Hu Pai judgment Function

Source: Internet
Author: User
Hu Pai judgment Function

Hu Pai judgment Function
[Code] // ---------------- unt_mainwin.cpp ---------------------------------------------------------

/* Configure /*-----------------------------------------------------------------------------------------
* This function is used to determine whether there are any fake cards. The number of cards must be [2, 5, 8, 11, 14].
* When the number of cards is 14, you can determine whether there are any special cards. [thirteen, Seven, none]
* If the above card type does not exist, use recursive algorithms to determine whether a general card type exists.
*
* Author: Yutian (Yu)
* E_main: yution@126.com
*
* Author's statement: This code is written during learning. You can post it, compile it, and modify it at will.
* But not for commercial purposes or gambling, the author reserves all power
*
* Thanks: Net user shyworm (fear of insects) e_mail: shyworm@sina.com
* Csdn chinaunix
*/

// Configure //-----------------------------------------------------------------------------------------------
Int twanjia: iswin ()
{
Int I, dblpos, dblcount;

If (this-> distinct COUNT = 13) // handle the special card type first, which is 7-to-13 or none.
{
If (this-> using inhand [0] = This-> using inhand [1]) & (this-> using inhand [2] = This-> using inhand [3])
& (This-> using inhand [4] = This-> using inhand [5]) & (this-> using inhand [6] = This-> using inhand [7])
& (This-> using inhand [8] = This-> using inhand [9]) & (this-> using inhand [10] = This-> using inhand [11])
& (This-> using inhand [12] = This-> using inhand [13])
Return sevendbl; // set the 7-to-7 pairs.

Dblcount = 0;

For (I = 0; I <13; I ++) // you can specify the number and position of the child in the hand card.
{
If (this-> using inhand [I] = This-> using inhand [I + 1])
{
Dblcount ++;
}

If (dblcount> 1) break; // if the hand card contains two or more pairs (or more than one engraved pair), only the basic brand name can be Hu
}

If (dblcount = 1) // is there a 13-hand pair, maybe 13?
{
/*************************************** ********
The thirteen-card model must be a fourteen-card combination of the ninth card and the character card, which is defined by the card number.
In the hand card array, as long as there is no 1 ~ 7,10 ~ 16,19 ~ 25,
It can be determined that the array is thirteen
*/
Int isthirteen = 1;
For (I = 0; I <14; I ++)
{
If (this-> using inhand [I]> 0 & this-> using inhand [I] <8)
{
Isthirteen = 0;
Break;
}
Else if (this-> using inhand [I]> 9 & this-> using inhand [I] <17)
{
Isthirteen = 0;
Break;
}
Else if (this-> using inhand [I]> 18 & this-> using inhand [I] <26)
{
Isthirteen = 0;
Break;
}
}
If (isthirteen) return thirteensmall;
} // End of thirteen

If (dblcount = 0) // no child, probably none
{
/*-------------------------------------------
Thirteen card models: 147,258,369 of the three colors of ten thousand cylinders plus a total of 16 cards
Of any fourteen cards, 147,258,369 of the colors can be any, but not two
Four identical ordinal numbers, such as 10 thousand, 40 thousand, and one, cannot form a card.

The algorithm is as follows:
First, determine the number of ordinal number cards (not character cards;
If the ordinal number is greater than 9, an error is returned;
If there is a sequence of cards (two cards can be used to eat another card), an error is returned;
For all ordinal cards, the order numbers are obtained by mod9 from the first card and all subsequent card values respectively.
If there are equal, an error is returned.
If all of the above statements are passed, it is no later than 13th.

*/

Int nowordpos = 14;

For (I = 13; I> = 0; I --)
{
If (this-> using inhand [I] <= 26)
{
Nowordpos = I;
Break;
}
}

If (nowordpos <= 8) // if there are more than 9 non-character cards, you cannot depend on them.
{
Int isthirteensingle = 1;

For (I = 0; I
{
If (this-> using inhand [I + 1] <= (this-> using inhand [I] + 2 )) & (this-> using inhand [I] % 9 = This-> using inhand [I + 1] % 9 ))
{
Isthirteensingle = 0;
Break;
}
}

If (isthirteensingle)
{
For (I = 0; I
{
For (Int J = 0; j <= nowordpos; j ++)
{
If (this-> using inhand [I] = This-> using inhand [J] % 9)
{
Isthirteensingle = 0;
Break;
}
}
}
}

If (isthirteensingle) return thirteensingle;
}

} // End of does not depend on
}


Int temppai [33];

For (I = 0; I <34; I ++) temppai = 0;

For (I = 0; I <14; I ++)
{
Temppai [This-> using inhand [I] ++;
}
If (hupai (temppai) return genaralwin;
Return 0;
}
// Configure //-----------------------------------------------------------------------------------------------------------------
Int twanjia: hupai (int * ARR)
{
/*
The following code references
Shyworm (fear of insects) e_mail: shyworm@sina.com
I would like to thank the algorithm and source code posted on the csdn forum.
 
The original algorithm was used to process the horizontal bars, but in the data structure I designed, they do not need to be judged,
So I skipped a piece of code.
*/
Static int Jiang = 0; // set the logo, that is, "two" in the "three two"

If (! Remainpai (ARR) return 1; // recursive exit condition: If there are no cards left, and the card is returned.

For (INT I = 1 ;! Arr [I] & I <34; I ++); // find the place with a card. I indicates the current card, and ARR [I] indicates the number.

// 3 combinations (engraved)
If (ARR [I]> = 3) // if the current card number is not less than 3
{
Arr [I]-= 3; // subtract 3 cards
If (hupai (ARR) return 1; // if the remaining cards are successfully combined
Arr [I] + = 3; // cancel the three combinations.
}

// Two combinations (CARDS)
If (! Jiang & arr [I]> = 2) // if the current card is not set and no more than 2 cards are displayed
{
Jiang = 1; // set the logo
Arr [I]-= 2; // subtract 2 cards
If (hupai (ARR) return 1; // if the remaining cards are successfully combined
Arr [I] + = 2; // cancel two combinations
Jiang = 0; // clear the logo
}

If (I> 26) return 0; // "publish in the Southeast and northwest China" does not have a good combination


// Shun card combination. Note that it is a combination from the past to the next!
If (I % 9! = 7 & I % 9! = 8 & arr [I + 1] & arr [I + 2]) // exclude cards with values 8 and 9 and if there are two consecutive cards
{
Arr [I] --;
Arr [I + 1] --;
Arr [I + 2] --; // The number of cards minus 1
If (hupai (ARR) return 1; // if the remaining cards are successfully combined
Arr [I] ++;
Arr [I + 1] ++;
Arr [I + 2] ++; // restores the number of cards
}


// Not all combinations!
Return 0;
}
//----------------------------------------------------------------------------
// Check the remaining number of cards
Int twanjia: remainpai (int * ARR)
{
Int sum = 0;
 
For (INT I = 0; I <34; I ++)
Sum + = arr [I];

Return sum;
 
}
//----------------------------------------------------------------------------

[/Code]

Header file

[Code]

// ------------------- The player class and the header file of the form (modifying )----------------------------------------

# Ifndef unt_mainwinh
# Define unt_mainwinh
//---------------------------------------------------------------------------
# Include
# Include
# Include
# Include

# Include

# Define sevendbl 7 // seven pairs
# Define thirteensmall 13 // thirteen
# Define thirteensingle 14 // thirteen
# Define genaralwin 15 // General card

// ================================================ ======
// 0 1 2 3 4 5 6 7 8
// ================================================ ======
// Ten thousand and two 30,004 50,006 70,008 90 thousand
// ================================================ ======
// 9 10 11 12 13 14 15 16 17
// ================================================ ======
// One, two, three, four, five, six, seven, eight, and nine
// ================================================ ======
// 18 19 20 21 22 23 24 25 26
// ================================================ ======
// One cylinder, two cylinder, three cylinders, four cylinders, six cylinders, seven cylinders, eight cylinders, and nine cylinders
// ================================================ ======
// 27 28 29 30 31 32 33 34 35
// ================================================ ======
// Dongfeng Nanfeng west wind north wind fortune whiteboard flowers 1 flower 2
// ================================================ ======

//---------------------------------------------------------------------------
Struct schipai // The structure of the card to eat. The card to eat is shunzi, so the first and last two cards are recorded.
{
Int minpai; // Mahjong card value, the smallest card in the card
Int maxpai; // The maximum number of mahjong cards.
};
//---------------------------------------------------------------------------
Struct sgangpai // structure of the bar chart
{
Int Pai; // Mahjong card value, value range: [0 .. 33]
Int mingan; // a value of 0 or indicates a dark bar, and 0 indicates a bright bar.
};
//---------------------------------------------------------------------------
Class twanjia
{
// _ Published:

PRIVATE:
Ansistring playerid;
Int fenshu; // the player's score, which must be consistent with the database

Int menfeng; // gamer's portal

Sgangpai gangpai [3]; // card of the player's lever

Schipai chipai [3]; // cards that players eat

Int pengpai [3]; // touch card in the player's hand

Int huapai; // The number of cards to use.

Int into inhand [13]; // the player's hand, remove the cards in the hand after the lever is touched
// Cards not visible to other players, up to fourteen cards
// When the processing is complete, the value of paiinhand [13] is-1.

Int digit count; // number of hands, value: 1, 4, 7, 10, 13

Int newpai; // a new card or card played by another user. After processing, it is assigned a value of-1.
// If newpai is not a negative value, you must remove a card or a card.

Protected:

Int hupai (int * ARR );
Int remainpai (int * ARR );

Public:
Twanjia (ansistring playid, int fenzhi );
Int setmenfeng (INT menfeng );
Int setfenshu (INT fenshu );
Int setgangpai (INT Pai, int mingan );
Int setchipai (INT min, int max );
Int setpengpai (INT pengpai );
Int setincluinhand (int * incluarr );
Int set0000count (INT count );

Int getmenfeng ();
Int getfenshu ();
Sgangpai * getgangpai ();
Int * getpengpai ();
Schipai * getchipai ();
Int * getaskinhand ();
Int getaskcount ();

Int buhua ();
Int chipaiwithtwopai (INT min, int max );
Int pengw.withonedbl (INT Pai );
Int iswin ();
Int sendthepaitoserver ();
Int requireonepai ();
};
//---------------------------------------------------------------------------
Class tmjzhuo
{
// _ Published:

PRIVATE:
Int quanfen, header, tail;
Int random Qiang [143];
Twanjia players [3];
Public:

};

//----------------------------------------------------------------------------
Class tfrm_mainwin: Public tform
{
_ Published: // ide-managed Components
Tedit * edt_policinhand1;
Tlabel * label1;
Tedit * edt_gang1_1;
Tlabel * label2;
Tlabel * label3;
Tlabel * label4;
Tedit * edt_chipai11;
Tedit * edt_chipai12;
Tedit * edt_chipai21;
Tedit * edt_chipai22;
Tedit * edt_chipai31;
Tedit * edt_chipai32;
Tedit * edt_chipai41;
Tedit * edt_chipai42;
Tedit * edt_gangpai2;
Tedit * edt_gang1_3;
Tedit * edt_gang1_4;
Tedit * edt_gang1_11;
Tedit * edt_gang000022;
Tedit * edt_gang000033;
Tedit * edt_gang000044;
Tedit * edt_peng1_1;
Tedit * edt_pengpai2;
Tedit * edt_pengworkflow 3;
Tedit * edt_peng00004;
Tedit * edt_policinhand2;
Tedit * edt_policinhand3;
Tedit * edt_policinhand4;
Tedit * edt_policinhand5;
Tedit * edt_policinhand6;
Tedit * edt_policinhand7;
Tedit * edt_policinhand8;
Tedit * edt_policinhand9;
Tedit * edt_paiinhand10;
Tedit * edt_policinhand11;
Tedit * edt_policinhand12;
Tedit * edt_policinhand13;
Tedit * edt_policinhand14;
Tbitbtn * btn_iswin;
Void _ fastcall formclose (tobject * sender, tcloseaction & action );
Void _ fastcall btn_iswinclick (tobject * sender );
Void _ fastcall formcreate (tobject * sender );
PRIVATE: // user declarations
Twanjia * player;

Public: // user declarations
Void senddatatowanjia ();
Void dispwanjiadata ();
_ Fastcall tfrm_mainwin (tcomponent * owner );

};
//---------------------------------------------------------------------------
Extern package tfrm_mainwin * frm_mainwin;
//---------------------------------------------------------------------------
# Endif

[/Code]

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.