Cocos2dx standalone Mahjong (4)

Source: Internet
Author: User

Cocos2dx standalone Mahjong (4)

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
Using namespace std; # define max_reperspon144 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 # mask // numeric mask # define MAX_INDEX42 // maximum index # define MAX_COUNT14 // maximum number of const BYTE m_cbCardDataArray [max_repermask] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, // ten thousand sub 0x01, 0x X, // x, x 09, // 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, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, // same as 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, // same as 0x24, 0x25, 0x26, 0 x, 0x29, // suo Zi 0x21, 0x X 24, 0x25, 0x26, 0 x, 0x28, 0x29, // suo Zi 0 x, 0 x, 0x29, // suo Zi 0x24, 0x25, 0x26, 0 x, 0x29, // suo Zi 0x32, 0x34, // 0x34, // 0x34, // 0x34, 0x34, // 0x43, // Wrigley 0x43, // Wrigley 0x43, // Wrigley 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 cylinder", "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", "Nine Suo", "East", "South", "West", "North", "medium", "fat", "White ", "Spring", "Summer", "Autumn", "Winter", "Mei", "Lan", "zhu", "Chrysanthemum "}; // chaos poker static void RandCardData (BYTE cbCardData [], BYTE cbMaxCount) {// confusion prepare BYTE cbCardDataTemp [CountArray (m_cbCardDataArray)]; // Why does one directly use MAX_REPERTORY? 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
Card value) BYTE SwitchToCardData (BYTE cbCardIndex) {// assert (cbCardIndex <42); if (cbCardIndex <31) return (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 (cbCardData & 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
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" <
> Ch; int _ outCardIndex = getIndexByWord (ch); if (_ outCardIndex =-1) {cout <"input error" <

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: 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.