Cocos2dx standalone Mahjong (4)

Source: Internet
Author: User

Cocos2dx standalone Mahjong (4)

Mahjong logic 5. Simulate playing

//// Main. CPP // majianglogictest /// created by tinyult on 14-8-16. // copyright (c) 2014 tinyult. all rights reserved. // # include <iostream> using namespace STD; # define max_repertory 144 typedef unsigned char byte; typedef unsigned short word; // array dimension # ifndef countarray # define countarray (array) (sizeof (array)/sizeof (array [0]) # endif // logical mask # definemask_color0xf0 // Color Mask # definemask_value0x0f // numerical mask # define max_ I Ndex42 // maximum index # define max_count14 // maximum number of const byte indexes [max_repertory] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, // Wanzi 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, // Wanzi 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, // Wanzi 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, // ten thousand sub 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, // same as 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, // same as 0x11, 0x12, 0x13, 0x X 15, 0x16, 0x17, 0x18, 0x19, // same as 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, // same as 0x24, 0x25, 0x26, 0x27,0 X, 0x29, // suo Zi 0x24, 0x25, 0x26, 0x27,0x28, 0x29, // suo Zi 0x24, 0x25, 0x26, 0x27,0x28, 0x29, // suo Zi 0x24, 0x25, 0x26, 0 x, 0x29, // suo Zi 0x32, 0x34, // 0x34, // 0x34, // 0x34, 0x34, // 0x43 ,// Wrigley 0x41,0x42,0X43, // Wrigley 0x41,0x42,0X43, // Wrigley 0x41,0x42,0X43, // Wrigley 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58, // card}; const char * m_cbcardwordarray [max_index] = {"10 thousand ", "20 thousand", "30 thousand", "40 thousand", "50 thousand", "60 thousand", "70 thousand", "80 thousand", "90 thousand", "one barrel ", "Two cylinder", "three cylinder", "Four Cylinder", "Five cylinder", "Seven cylinder", "eight cylinder", "Nine cylinder ", "One Suo", "Two Suo", "Three Suo", "Four Suo", "Five Suo", "Six Suo", "Seven Suo", "eight Suo ", "jiusuo", "East", "South", "West", "North", "medium", "fat", "White", "Spring", "Summer ", "Autumn", "Winter", "Mei", "Lan", "zhu", "Chrysanthemum"}; // chaotic poker static void randcarddata (BYT E cbcarddata [], byte cbmaxcount) {// confused preparation byte cbcarddatatemp [countarray (m_cbcarddataarray)]; // Why is max_repertory used directly? Because of this non-coupling memcpy (cbcarddatatemp, m_cbcarddataarray, sizeof (m_cbcarddataarray); // copy a copy to the temporary card array // chaotic poker (key core disrupting code) byte cbrandcount = 0, cbposition = 0; do {cbposition = rand () % (cbmaxcount-cbrandcount); cbcarddata [cbrandcount ++] = cbcarddatatemp [cbposition]; cbcarddatatemp [cbposition] = cbcarddatatemp [cbmaxcount-cbrandcount];} while (cbrandcount <cbmaxcount); return;} // void randappointcarddata (byte cbcarddata [], Byte cbmaxcount, byte originaldata []/* source card heap data */) {// chaotic poker byte cbrandcount = 0, cbposition = 0; do {cbposition = rand () % (cbmaxcount-cbrandcount); cbcarddata [cbrandcount ++] = originaldata [cbposition]; originaldata [cbposition] = originaldata [cbmaxcount-cbrandcount];} while (cbrandcount <cbmaxcount ); return;} // poker conversion (index-> card value) byte switchtocarddata (byte cbcardindex) {// assert (cbcardindex <42); If (cbcardindex <31) retu RN (cbcardindex/9) <4) | (cbcardindex % 9 + 1); If (cbcardindex> = 31 & cbcardindex <= 33) return (cbcardindex/7) <4) + cbcardindex % 10); If (cbcardindex> 33) Return (cbcardindex + 0x2f); // assert (false ); return 0;} // poker conversion (card type-> index) byte switchtocardindex (byte cbcarddata) {// assert (isvalidcard (cbcarddata); If (cbcarddata & mask_color) <= 0x30) Return (cbcarddata & mask_color)> 4) * 9 + (cbcarddata & mask_value)-1); If (cbcard Data & mask_color) = 0x40) Return (31 + (cbcarddata & mask_value)-1); If (cbcarddata & mask_color) = 0x50) return (34 + (cbcarddata & mask_value)-1); // assert (false); Return 0 ;} // poker switch byte switchtocarddata (byte cbcardindex [max_index]/* input table for counting the number of all cards */, byte cbcarddata [max_count]/* outgoing hand card data */) {// convert poker byte cbposition = 0; For (byte I = 0; I <max_index; I ++) {If (cbcardindex [I]! = 0) {for (byte J = 0; j <cbcardindex [I]; j ++) {// assert (cbposition <max_count ); cbcarddata [cbposition ++] = switchtocarddata (I) ;}}return cbposition; // returns the number of cards} // based on the Chinese card, get the card index int getindexbyword (const char * Ch) {for (INT I = 0; I <max_index; I ++) {If (! Strcmp (CH, m_cbcardwordarray [I]) {return I ;}return-1 ;}// Delete poker bool removecard (byte cbcardindex [max_index], byte cbremovecard) {// verify poker // assert (isvalidcard (cbremovecard); byte cbremoveindex = switchtocardindex (cbremovecard); // assert (cbcardindex [cbremoveindex]> 0 ); // Delete poker if (cbcardindex [cbremoveindex]> 0) {cbcardindex [cbremoveindex] --; return true;} // failure validation // assert (false); Return false ;} int main (INT argc, const char * argv []) {// insert code here... /* First messy issue * // create an empty card heap byte _ carddata1 [max_repertory]; // create and disrupt the card heap in this function, then pass the pointer to _ carddata; randcarddata (_ carddata1, max_repertory); // output card data cout <"chaotic initial card Heap" <Endl; For (INT I = 0; I <max_repertory; I ++) {cout Output:

Chaotic initial card heap

0x25 0x13 0x1 0x3 0x21 0x43 0x54 0x14 0x9 0x12 0x13 0x8 0x31 0x24 0x13 0x31 0x6 0x4 0x28 0x31 0x34 0x18 0x7 0x27 0x15 0x18 0x51 0x11 0x42 0x12 0x28 0x2 0x57 0x25 0x16 0x4 0x33 0x15 0x18 0x21 0x42 0x33 0x29 0x41 0x25 0x3 0x23 0x55 0x14 0x41 0x27 0x22 0x34 0x21 0x2 0x9 0x29 0x19 0x43 0x23 0x22 0x22 0x19 0x34 0x16 0x15 0x32 0x58 0x6 0x28 0x17 0x21 0x18 0x8 0x43 0x28 0x33 0x32 0x6 0x33 0x2 0x25 0x14 0x11 0x29 0x19 0x26 0x13 0x4 0x24 0x53 0x52 0x16 0x15 0x27 0x3 0x27 0x31 0x9 0x1 0x26 0x22 0x3 0x32 0x17 0x26 0x26 0x7 0x12 0x42 0x41 0x32 0x17 0x8 0x7 0x9 0x34 0x8 0x7 0x16 0x17 0x41 0x19 0x5 0x29 0x2 0x23 0x6 0x4 0x24 0x42 0x24 0x0x1 0x56 0x11 0x1 0x12 0x5 0x23 0x11 0x14 0x43 0x5 0x5


Messy designated card heap

0x16 0x56 0x21 0x7 0x28 0x14 0x41 0x12 0x16 0x24 0x43 0x21 0x31 0x26 0x3 0x53 0x52 0x7 0x12 0x34 0x51 0x14 0x9 0x29 0x23 0x33 0x12 0x31 0x14 0x6 0x16 0x18 0x54 0x21 0x25 0x58 0x19 0x5 0x7 0x28 0x32 0x34 0x1 0x27 0x27 0x33 0x6 0x14 0x9 0x17 0x25 0x33 0x28 0x11 0x17 0x24 0x43 0x2 0x22 0x6 0x23 0x3 0x11 0x42 0x2 0x18 0x3 0x4 0x42 0x4 0x18 0x55 0x25 0x42 0x22 0x32 0x4 0x15 0x8 0x29 0x24 0x13 0x6 0x26 0x19 0x9 0x41 0x25 0x7 0x8 0x1 0x13 0x11 0x15 0x41 0x43 0x57 0x16 0x33 0x18 0x32 0x27 0x1 0x8 0x12 0x31 0x4 0x5 0x27 0x22 0x26 0x23 0x31 0x2 0x5 0x17 0x26 0x13 0x19 0x43 0x17 0x21 0x42 0x5 0x3 0x19 0x23 0x15 0x28 0x15 0x8 0x24 0x9 0x29 0x13 0x32 0x34 0x2 0x34 0x41 0x11 0x29 0x22 0x1


Number of all types

10 thousand(0x1): 020 thousand(0x2): 030 thousand(0x3): 040 thousand(0x4): 050 thousand(0x5): 060 thousand(0x6): 070 thousand(0x7): 180 thousand(0x8): 090 thousand(0x9): 0One barrel(0x11): 02 Cylinder(0x12): 1Three Cylinder(0x13): 0Four Cylinder(0x14): 1Five Cylinder(0x15): 0Six Cylinder(0x16): 2Seven Cylinder(0x17): 0Octa(0x18): 0Nine Cylinders(0x19): 0Yasuo(0x21): 2Two(0x22): 0Sansuo(0x23): 0Sisuo(0x24): 1Wusuo(0x25): 0Liusuo(0x26): 1Qisuo(0x27): 08 Cable(0x28): 1Jiusuo(0x29): 0East(0x31): 1South(0x32): 0West(0x33): 0North(0x34): 0Medium(0x41): 1Sending(0x42): 0White(0x43): 1Spring(0x51): 0Summer(0x52): 0Autumn(0x53): 0Winter(0x54): 0Mei(0x55): 0Lan(0x56): 1Bamboo(0x57): 0Chrysanthemum(0x58): 0


Output hand data

Number of cards: 14

70 thousand(0x7)2 Cylinder(0x12)Four Cylinder(0x14)Six Cylinder(0x16)Six Cylinder(0x16)Yasuo(0x21)Yasuo(0x21)Sisuo(0x24)Liusuo(0x26)8 Cable(0x28)East(0x31)Medium(0x41)White(0x43)Lan(0x56)


Enter the card to be issued(For example30 thousand):70 thousand

The card is successfully issued.

Number of cards: 13

Hand card data is:

2 Cylinder(0x12)Four Cylinder(0x14)Six Cylinder(0x16)Six Cylinder(0x16)Yasuo(0x21)Yasuo(0x21)Sisuo(0x24)Liusuo(0x26)8 Cable(0x28)East(0x31)Medium(0x41)White(0x43)Lan(0x56)


Program ended with exit code: 0



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.