Preface (due to my lack of intellectual property legal knowledge, I do not know whether the development experience and principles of writing types are infringing ):
If you are involved in infringing the rights and interests of netfox, please delete the post from csdn. Do not disclose it to the public. Thank you.
I am introducing the Texas hold'or robot feature, but it is just the development experience.
1. File Introduction
The following files are mainly used to add robot functions.
Androiduseritemsink. h
Androiduseritemsink. cpp
--------------- Class candroiduseritemsink
(File Name: robot user entry trap)
Purpose: robot-related events will fall into this trap, where a response mechanism is provided to trigger corresponding actions and send and transmit messages.
Gamelogic. h
Gamelogic. cpp
--------------- Class cgamelogic
(Game logic file)
Role: defines the number of poker games, game gameplay rules, card type comparison, card value size, and other functions of the game.
Tableframesink. h
Tableframesink. cpp
---------------- Class ctableframesink
(Table Frame trap)
Role: events related to game desktops cannot escape this trap. A response mechanism is provided in this trap to trigger corresponding actions and send and transmit messages.
Performance_dzshowhand.h
(Message definition file)
Purpose: Define the communication format reservation and constant definition between the client and the server.
The fourth article below illustrates how to transmit data like candroiduseritemsink and ctableframesink.
Ii. Robot implementation principle
The candroiduseritemsink class obtains game scenario messages.
Including game start, user filling, user giving up, licensing news, and game end.
After this type of message is captured,
One is to call the timer processing function to implement the corresponding action.
After capturing a message, the timer processing function is called to implement the expected action through the corresponding action function.
Our robot implementation is implemented in the latter way. Action processing functions need to obtain many predictable data conditions.
The action processing function must be supported by the logic class cgamelogic. The logic class is instantiated as m_gamelogic in the candroiduseritemsink class, that is, the logical interface.
Specific implementation:
The proposed robot implementation scheme is mainly used to determine the action of the Robot Based on the card type. In addition to judging the card model, the real man also needs to play several rounds of accumulated experience to observe the character and situation of the opponent player, make some details, and decide to place a bet.
However, robots cannot accumulate human experience.
Robot action trigger events mainly include:
1) Start the game
At the beginning of the first round, the robot determines whether the player is the current player. If yes, the robot decides to place a bet or give up based on the card type and card value. The basic data and card value referenced by the bet value. Class ctableframesink will be sent.
2) User Filling
After the previous user places a bet, the robot determines whether the player is the current player. If yes, the robot also depends on the card type and card value, and determines whether a card exists on the desktop. If the card is not issued, that is, the bet is consistent at the beginning of the game.
If there is a public card, how many cards are identified as 3, 4, and 5?
Select the best card type based on the combination of the hand card and the public card, and place a bet based on the card value and desktop amount.
3) Licensing messages
After the public card is issued, the machine determines whether the player is the current player. If yes, the number of public cards is determined and the best card type is combined. The bet is determined based on the desktop amount and the number of rounds of licensing.
Iii. Instructions on adding robot implementation code. The following is a snippet of my code implementation code architecture. If you are interested, please take a look. Sorry, you cannot publish the detailed code.
1. androiduseritemsink. h
The data variables to be learned and functions to implement specific functions are added to machine humans.
// Machine human
Class candroiduseritemsink
// Game variable
Protected:
Byte m_cbhandcard [max_count];
// User's hand card
Byte m_cbcardtype;
// Card type
Byte cbfirstvalue;
// Hand card Value
Byte cbsecondvalue;
// Hand card Value
// Robot action
Protected:
Bool preflopaction ();
// Bottom card right/Front flop
Bool floproundaction ();
// Flop
Bool turnroundaction ();
// Badge circle
For details about the Function Definition, see androiduseritemsink. cpp.
2. androiduseritemsink. cpp
It mainly adds the timer (as shown below) that needs to be added, and the message sending details that define the action Timer In the oneventtimer () function. And the implementation of robot action functions in androiduseritemsink. h.
# Define idi_user_add1_gold
// Double-note Timer
# Define idi_user_add2_gold // Double note Timer
# Define idi_user_follow_gold // follow-up timer
# Define idi_user_pass
// Card-crossing Timer
# Define idi_user_show_hand
// Stud Timer
// Time Message
Bool _ cdecl candroiduseritemsink: oneventtimer (uint ntimerid)
3. gamelogic. h
Add the poker type to be used:
// Poker type
# Define hct_single 11
// Card type
# Define hct_pair 12
// Hand card pair type
# Define hct_will_straight 13
// Hand card shun type
# Define ct_less_straight 14
// Returns a proper subtype.
Add function:
// Obtain the hand card type
Byte gethandcardtype ();
// Obtain the hand card + ticker board type
Byte getfloproundcardtype ();
// 6. Return to the acquisition hand card + the largest byte fivefromsix () in the badge type ();
4. gamelogic. cpp
Mainly added the definition of the function in the gamelogic. h file.
5. tableframesink. cpp
No new code is added.
Iv. Communication between class candroiduseritemsink and class ctableframesink
The two classes are closely linked and communicate with each other. The class candroiduseritemsink can be viewed as a game client with no display function.
Only the file name is written below, and the corresponding class name can be understood as the file name.
The following describes how to start data transmission in the game era:
Tableframesink. cpp
// Start the game
Tableframe. cpp
// Send data
Attemperenginesink. cpp
// Send data
Androidusermanager. cpp
// Send data
Androiduseritem. cpp
// Network message
// Game message
Androiduseritemsink. cpp
// Game message
// Start the game
The following is a detailed code snippet:
Tableframesink. cpp
// Start the game
Bool _ cdecl ctableframesink: oneventgamestart ()
M_pitableframe-> sendtabledata (I, sub_s_game_start, & gamestart, sizeof (gamestart ));
Tableframe. cpp
// Send data
Bool _ cdecl ctableframe: sendtabledata (word wchairid, word wsubcmdid, void * pdata, word wdatasize)
M_pigameserviceframe-> senddata (m_piuseritem [wchairid], mdm_gf_game, wsubcmdid, pdata, wdatasize );
Attemperenginesink. cpp
// Send data
Bool _ cdecl cattemperenginesink: senddata (iserveruseritem * piserveruseritem, word wmaincmdid, word wsubcmdid, void * pdata, word wdatasize)
M_androidusermanager.senddatatoclient (dwid, wmainize ID, wsubcmdid, pdata, wdatasize );
Androidusermanager. cpp
// Send data
Bool _ cdecl candroidusermanager: senddatatoclient (DWORD dwandroidid, word wmaincmdid, word wsubcmdid, void * pdata, word wdatasize)
If (pandroiduseritem-> onsocketread (wmaincmdid, wsubcmdid, pdata, wdatasize) = false)
Androiduseritem. cpp
// Network message
Bool candroiduseritem: onsocketread (word wmaincmdid, word wsubcmdid, void * pdata, word wdatasize)
// Game message
If (wmain1_id = mdm_gf_game) | (wmain1_id = mdm_gf_frame ))
{
Return onsocketgamemessage (wmaincmdid, wsubcmdid, pdata, wdatasize );
}
// Game message
Bool candroiduseritem: onsocketgamemessage (word wmaincmdid, word wsubcmdid, void * pdata, word wdatasize)
Return m_piandroiduseritemsink-> oneventgamemessage (wsubcmdid, pdata, wdatasize );
Androiduseritemsink. cpp
// Game message
Bool _ cdecl candroiduseritemsink: oneventgamemessage (word wsubcmdid, void * pdata, word wdatasize)
Switch (wsubcmdid)
{
Case sub_s_game_start:
// Start the game
{
Return onsubgamestart (pdata, wdatasize );