Poker game architecture and its implementation (3)

xiaoxiao2021-03-05  26

Poker game architecture and its implementation (3)

Technical point to column and analysis

Poker painting

Define nouns as follows:

l

Suit

One of the properties of poker, the value is one block, grass flower, red peach, black peach

l

Face value face

One of the properties of poker, the value is a, 2, 3, etc. until K

l

Ordinary card

ACE to K's card, called

Ordinary card

l

Joker

(Big small ghost, big crazy)

In addition to the cards of Ace to K, Joker (large villate, big crazy)

Here the author reference

Http://www.catch22.net "HOW TO Use Cards.dll" (Author James Brown), the author only saw Part1 and Part2, recently have part3 to come to the article, the author launched a class library, and give There is a related document. Seeing that there is a certain similarity with the author practices, I can't help but have a little pleasing, I'm going to have a little in the hero, huh, huh :-)

In Cards.dll, the poker's display is determined by an integer value value. Set this value is X, then

u If x ∈ [0,52] is displayed as a brand of Ace to K, called

Ordinary card, its order is such a grass flower, a square, A red peaches, A black peach, 2 grass flowers, 2 squares, 2 red peaches, 2 pheasant ... This article defines such sorting

Face value priority sort

(Face first sort); if you sort a grass flower, 2 grass flowers, 3 grass flowers ... K grass flower, A square, 2 square, 3 square ... K square, A red peach, 2 red peach, 3 red peach ... K red Peach, a black peach, 2 black peach, 3 pheasant ... K, peach, said this sort is

Color color priority sorting (

Suit first sort

).

u If x ∈ [53, 68] is displayed as some rear back pattern, according to the author's experience, on different versions of the operating system, the rear back pattern displayed is different. The XP is obviously better than W2K.

u If the X is taken, the uncertainty pattern is displayed. Here, it should be noted that the author encounters the case where the uncertain value is caused, and will be cautious.

Therefore, the poker object is always set

ØINTEGER IFACE // Face value

ØINTEGER ISUIT / color

Also, the key value x of the plot of poker is X = IFACE ISUIT * 4, name this value in the poker object.

iFacefirstValue

In addition, some rule of card games may also use color priority sequences, so they are set

ISUITFIRSTVALUE

And this value is ISUITFIRSTVALUE = ifce * 13 iSuit. For ordinary poker cards, the IFACE and ISUIT values ​​determine the playback of poker, while ifactionfirstvalue and iSuitFirstValue can also be used as

Sort.

Object package

Pokerlist

Follow the CPOKER object described in the aging, the details are as follows:

Set

The PokerList class is defined as a set of poker, and should be inserted with at least a function interface such as deletion search. This class contains a pointer queue (PTRLIST), most of which are on this queue basis.

Ø

Bool CPOKERLIST :: Sendout

(CPOKERLIST *

)function

Ø

Bool CPOKERLIST :: IssentValidate

()function:

The former function requires a parameter, the target queue that needs to be moved.

The latter is a function of determining whether the card is legal, gives a result with the BOOL value.

Before moving poker, you must select the associated poker (call cpokerwnd :: setPicked (TRUE)). The former calls the latter. First, the latter determines whether the date is legal, if legal, then move, otherwise returning to the original PokerList and sets setPicked (false). Remote and Local

Inheritance class of Pokerlist

CPLAYER has two inheritance classes

ClocalPlayer and

CremotePlayer

. The difference is:

CLOCALPLAYER is a local player, and the local player operates, thereby departing the relevant function to send a message to the distal end, describing the operation, synchronization data;

CremotePlayer does not have this feature.

In the appearance, you can make some difference settings, such as

CremotePlayer hidden cards, etc.

Licensing

In the past posts in the 9CBS, the licensing is always a difficult point. The author's solution is as follows:

Use a one-dimensional array

TotalPoker [N] indicates that the number in the billboard, the number of elements of the array (set to n) is the total number of colors used in the poker (with the same color color), such as "arch pig" game, no size Joker, Only the color cards of Ace ~ K, then n = 52; if it is "red five three hits", there is size Joker, plus the plates of Ace ~ K, a total of 54, so n = 54.

At the beginning, the value of each element in the array takes the number of the color brand, such as: "Arch pig" requires a pair, then TotalPoker [n] = 1 (n∈ [0, n-1], n is between it Any integer); "Red 5 or three hits a" need two pairs, then TotalPoker [n] = 2.

Each time you send a card, randomly tap i∈ [0, n-1] (i is an integer), if TotalPoker [i] is not zero, the assignment is successful, minus TotalPoker [i] 1, otherwise repeating the random The process is sent to each player. The above process repeats N times, then all the cards are sent.

/

//

Initial setting

For (int i = 0; i <52; i )

{

iTotalPokers [i] = 1; //

Delete the card already having the queue and reinitialize the tag array

}

/

For (i = 52; i> 0; i -) //

License function

{

While (iTotalPokers [iPokerValueFacefirst = rand ()% 52] <1);

// new a poker and append it to the list

// ppokerwnd = new cpokerwnd (iPokerValueFacefirst, False);

PPOKERWND = New CPOKERWNDPIGGIE (IPOKERVALUEFACEFIRST, FALSE);

PPOKERWND-> CREATE (NULL, NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS, CRECT (0, 0, 0, 0), PParentWnd, ZYY_POKER i);

PPOKERBOX-> Addtail (PPOKERWND);

ItotalPokers [iPokerValueFacefirst] -;

}

Control of the order

In a CPLAYER object

Token member

(Token) and

Whether it is legally determined to make a combination of the mechanism to achieve - not allowed to make the card. After getting a token and passed, pass the token to the next player.

The legality judgment of the card

It is mainly to achieve different legitimate rules in different games by overloading the cpokerbufferlist :: ispokersentvalide () function in the inheritance class. It is necessary to pay attention to the following rules: Ø order control

Ø The same is the same as the first player player, for example: the same number is the same as the same color or the same pair of squats, etc.

Ø Does the first player of each round, for example: "Arch pig" must be a grass flower 2

Tractor and other brand types ("Red 5 or three hits")

Whether it is color, only the face value is taken. The general judgment rules of various colors such as the sub-, squin are as follows:

Ø will

Target sequence (Poker combination to be judged) is placed in a string array

Ø for different

Combination, take different

Standard comparison sequence, also in the array of strings

Ø The face value of a group of cards is reduced to the minimum face value and add one, get one

Compare sequence

Ø Use the string related functions in the C language to compare the comparison sequence of the associated comparison sequence and the target sequence, thereby determining whether it is a combination.

Ø Special circumstances

Example: The target sequence is 778899, which is determined whether it is a triple pair, the sequence of comparisons is 112233 (= 778899-777777 111111), and the three-linked standard comparison sequence is 112233. It can be judged by the strCMP () function, the target sequence is three-linked.

However, there is also a special case. For example, in "Red 5th Type 1", the red peaches 6 as the largest card, so it is not possible to participate in the combination of the children. At this time, it is necessary to implement the color and face value, exclude this.

The judgment of "fall" ("Red 53")

So-called "

Satched ", it is a unique online rule in the game such as" Red 53 ", and its role is tantamount to play cards for many times, but it must be guaranteed (combined or single) is all players. The biggest, the purpose is to mobilize the other party's card, reduce the possibility of the other party's ability to play, and strive to take the initiative.

So how to judge whether the card in the overhead queue is the biggest, extremely important, the author's implementation method is as follows:

Ø Define the derived class member of CGAME INT MaxPokeraRray [A] [B] (usually, A = 3, b = 4, this is because each time the card, the value in the array and the card value, check Whether the card is the largest, after each time the card is completed, update the value inside this array.

Ø Using the above judgment method ("tractor", the card sequence is analyzed into a plurality of basic pairs or squirrels and single rows, respectively, compared to the value in MaxPokerarray [3] [4], if All are the largest, then the card is listed as the largest combination, namely

tractor.

Size comparison

Ø Comparison of single sheets

Single card is actually the core of poker size - the comparison of combinations is ultimately attributed to a single sign. For each brand, a member variable is

Compare the value, the value is taken as follows:

¨ If there is a main flower rule, for the ordinary card, if it is the main color, its IFACE value is 15 (ensuring greater than the non-main colorful ACE)

¨ If the rule or 2 is better than K, then add 15

¨ If there is a rule

Changde (for example, "red five three hits a" 2 is often sent), plus 15

¨ Out of the same card, the first out is a big Ø

Single card

Compare the value

Ø Comparison of multi-card combination

Assume that it has passed

The legality determination confirmation is the same. The comparison can be implemented using the function strcmp () in the C language.

Rule determination

Message package and analysis

Ø Package a class of free operation strings, providing interface: Take strings by length, add strings by length

Ø Based on the above class, the package and analysis of the pipeline message is supported by the marker and loop.

Reference website

http://www.catch22.net

Thank Mr. James Brown

转载请注明原文地址:https://www.9cbs.com/read-37368.html

New Post(0)