Cocos2dx standalone Mahjong (2) and cocos2dx Mahjong

Source: Internet
Author: User

Cocos2dx standalone Mahjong (2) and cocos2dx Mahjong

Cocos2dx standalone Mahjong (2)

Disrupt Mahjong order 2

We have explained how to disrupt the initial Mahjong heap and how to disrupt any given Mahjong heap.

// Chaotic Poker 2

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;

}

The complete console code is as follows:

//// 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]) # endifconst BYTE m_cbCardDataArray [MAX_REPERTORY] = {0x01,0x02,0x03,0x04,0x05, 0x X, 0x09, // x, // 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, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, // same as 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, // same as 0x24, 0x25, 0x 26, 0x27,0x28,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 0x43, // Wrigley 0x43, // Wrigley 0x43, // Wrigley 0x41,0x42,0x43, // Wrigley 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58, // card }; // 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] = bytes [cbMaxCount-cbRandCount];} while (cbRandCount <cbMaxCount); return ;}// chaotic Poker 2 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 ;} int main (int argc, const char * argv []) {// insert code here... /* first confusion * // create an empty card heap BYTE _ cardData1 [MAX_REPERTORY]; // create and disrupt the card heap in this function, and then pass the pointer to _ cardData; randCardData (_ cardData1, max_reper); // output card data for (int I = 0; I <max_reper; I ++) {cout Output:

25 13 1 3 21 43 54 14 9 12 13 8 31 24 13 31 6 4 28 31 34 18 7 27 15 11 42 12 28 2 57 25 16 4 33 15 18 21 42 33 29 41 25 3 23 14 41 27 22 34 21 2 9 29 19 43 23 22 22 19 34 16 15 32 58 6 28 17 21 18 8 43 28 33 32 6 33 2 25 14 11 29 19 26 13 4 24 53 16 16 15 27 3 31 9 1 26 22 3 32 17 26 7 12 42 41 32 17 8 7 9 34 8 7 16 17 41 19 5 29 2 23 6 4 24 42 24 1 56 11 1 12 5 23 11 14 43 5

16 56 21 7 28 14 41 12 16 24 21 31 26 3 53 52 7 12 34 51 14 9 29 23 33 12 31 14 6 16 18 54 21 25 58 19 5 7 28 32 34 1 27 27 33 6 14 9 17 33 28 11 17 24 43 2 22 6 23 3 11 42 2 18 3 4 42 4 18 55 25 42 22 32 4 15 8 29 24 13 6 26 19 9 41 25 7 8 1 13 11 15 41 43 57 16 33 18 32 27 1 8 12 31 4 5 27 22 26 23 31 2 5 17 26 13 19 43 17 21 42 5 3 19 23 15 15 8 24 9 29 13 32 34 2 34 41 11 29 22 1

Program ended with exit code: 0


Mahjong logic 3. initialize the card

The logical premise of Mahjong is data support. It is necessary to store all the data well.
Card records of mahjong generally adopt a general method, that is, a one-dimensional array, the length is the number of cards, the value of the element is the number of cards
For example

# Define MAX_INDEX 42 // maximum Index
BYTE cbCardIndex [MAX_INDEX]

There are 42 types of cards: 10 thousand-90 thousand, 1-9, 1-9, 7, and 8)
9 + 9 + 9 + 7 + 8 = 42.

If you get a 10 thousand image, as long as cbCardIndex [0] ++, and 30 thousand cbCardIndex [2] ++, do you find cbCardIndex [0x31] ++ in Dongfeng?
You will find that the card value is represented in hexadecimal notation (review first). We cannot use cbCardIndex [card value] to represent the number of cards of this type.
For example, if I want to get the number of 1 cylinders in my hands and cannot use cbCardIndex [0x11], we should use cbCardIndex [9]. We should have a function that allows the card value and index to convert each other.
That is, the cbCardIndex [func (9)] = cbCardIndex [0x11] is implemented, so that we can use the card type value to obtain the number of cards of this type.
It's not too early to go to bed.

//// Main. cpp // MajiangLogicTest /// Created by TinyUlt on 14-8-17. // 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}; // chaotic poker static void RandCardData (BYTE cbCardData [], BYTE cbMaxCount) {// confused preparation BYTE cbCardDataTemp [CountArray (m_cbCardDataArray)]; // Why do I 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] = bytes [cbMaxCount-cbRandCount];} while (cbRandCount <cbMaxCount); return ;}// chaotic Poker 2 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) 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 ;} 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 cards in the output board heap

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


Program ended with exit code: 0



Can I play Tianshui mahjong or dibao Mahjong online? Where can I download it?

After finding it, I finally found out. Tianshui Mahjong (the second newspaper Mahjong) can log on to the official website of ShengTang game for registration at www.sntan.com to find the game of Tianshui mahjong. There are still many players. Do you want to send Tang bean @@@

What is this standalone mahjong game called?

Yes, Master Mahjong 2
Hope to adopt

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.