bot.talk
Class Talk_ACPC

java.lang.Object
  extended by bot.talk.Talk
      extended by bot.talk.Talk_ACPC

public class Talk_ACPC
extends Talk

This class talks to the poker server. All message protocol dependent stuff should be in here.

Author:
Witthold/Korol

Field Summary
private  java.lang.String ClassOfPlayer
           
private  boolean gameOver
          Is the round over?
private  java.io.InputStream is
          Stream from the server.
private  java.lang.String lastGameStateString
          This is the current game state.
private  boolean matchOver
          Has an ENDGAME signal been received?
static java.lang.String messageTerminator
          Terminates the messages.
private  java.io.OutputStream os
          Stream to the server.
private  boolean protocolNoLimit
           
private  java.net.Socket socket
          Socket connecting to the server.
private  boolean tournament
          In a tournament the bot will be started via script and therefore announce itself as "AAAIPLAYER".
 
Fields inherited from class bot.talk.Talk
bot, port, serverAdress
 
Constructor Summary
Talk_ACPC(Bot bot, java.lang.String serverAdress, int port)
          Calls super constructor with the given parameters.
 
Method Summary
private  void close()
          Closes the connection.
private  void connect(java.net.InetAddress iaddr, int port)
          Tries to set up a socket and to get the input and output stream.
private  Card[] extractCards(java.lang.String cardString)
          Extracts the Cards from the given string and returns it.
private  java.lang.String extractLastAction(java.lang.String roundHistory)
          Extracts the string representing the last action out of the given string.
private  void gameLoop()
           
 boolean initConnection()
          Tries to connect to the given server (and enters a room).
private  void initHand(int position, int hand, Card[] holeCards, Card[] boardCards)
          Initialize the hand.
private  boolean isComplete(java.lang.String message)
          Tests if the message is complete (contains a terminal character)
private  void processMessage(java.lang.String message)
          Processes the given message.
private  java.lang.String receiveMessage()
          Receive a message from the server.
 void run()
          Triggers the the game loop.
private  boolean sendAction(char action)
          Send an action (action should be 'r', 'c', or 'f').
private  boolean sendAction(java.lang.String action)
          Send an action string (action should be r??
 boolean sendCall()
          Sends a call action.
 boolean sendFold()
          Sends a fold action.
private  boolean sendMessage(java.lang.String message)
          Sends the given message to the server.
 boolean sendRaise()
          Sends a raise action.
 boolean sendRaise(int finalInPot)
          Sends a raise action.
private  void setBoardCards(int round, java.lang.String cardString)
          Extracts the cards from the given string and makes the bot set the given cards to the given round.
private  void setEnemyHoleCards(java.lang.String message)
          Extracts all hole cards from the given string and calls the method of the bot to set them.
private  void setPlayers(java.lang.String[] playerDesc)
          Extracts the player information for each player (names and buy ins) and calls the according method of the bot.
private  void updateState(java.lang.String gameStorageString)
          Updates the state of the bot depending of the given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageTerminator

public static final java.lang.String messageTerminator
Terminates the messages. The current message terminator is CR LF (13 10).

See Also:
Constant Field Values

ClassOfPlayer

private final java.lang.String ClassOfPlayer
See Also:
Constant Field Values

tournament

private final boolean tournament
In a tournament the bot will be started via script and therefore announce itself as "AAAIPLAYER".
For testing it is easier to start the bot without script and it will announce itself as "GUIPLAYER".

See Also:
Constant Field Values

socket

private java.net.Socket socket
Socket connecting to the server.


is

private java.io.InputStream is
Stream from the server.


os

private java.io.OutputStream os
Stream to the server.


matchOver

private boolean matchOver
Has an ENDGAME signal been received?


gameOver

private boolean gameOver
Is the round over?


protocolNoLimit

private boolean protocolNoLimit

lastGameStateString

private java.lang.String lastGameStateString
This is the current game state.
It is not changed during a call to handleStateChange().
Necessary for sending a reply (by appending the action to the game state string).

Constructor Detail

Talk_ACPC

public Talk_ACPC(Bot bot,
                 java.lang.String serverAdress,
                 int port)
Calls super constructor with the given parameters.

Parameters:
bot -
serverAdress -
port -
Method Detail

initConnection

public boolean initConnection()
Tries to connect to the given server (and enters a room).
Gets and sets the gamedef in the process.

Specified by:
initConnection in class Talk

run

public void run()
Description copied from class: Talk
Triggers the the game loop.

Specified by:
run in class Talk

sendFold

public boolean sendFold()
Description copied from class: Talk
Sends a fold action.

Specified by:
sendFold in class Talk

sendCall

public boolean sendCall()
Description copied from class: Talk
Sends a call action.

Specified by:
sendCall in class Talk

sendRaise

public boolean sendRaise()
Description copied from class: Talk
Sends a raise action.

Specified by:
sendRaise in class Talk

sendRaise

public boolean sendRaise(int finalInPot)
Description copied from class: Talk
Sends a raise action. The final in pot is the total YOU want to have put in the pot after the raise (ie including previous amounts from raises, calls, and blinds.

Specified by:
sendRaise in class Talk

gameLoop

private void gameLoop()
               throws java.io.IOException
Throws:
java.io.IOException

connect

private void connect(java.net.InetAddress iaddr,
                     int port)
              throws java.io.IOException
Tries to set up a socket and to get the input and output stream.

Parameters:
iaddr -
port -
Throws:
java.io.IOException

sendMessage

private boolean sendMessage(java.lang.String message)
Sends the given message to the server. (After appending the message terminator)


close

private void close()
            throws java.io.IOException
Closes the connection. Called after game loop ends.

Throws:
java.io.IOException

isComplete

private boolean isComplete(java.lang.String message)
Tests if the message is complete (contains a terminal character)


sendAction

private boolean sendAction(char action)
Send an action (action should be 'r', 'c', or 'f').
Usually called during handleStateChange.
Action will be in response to the state in currentGameStateString.


sendAction

private boolean sendAction(java.lang.String action)
Send an action string (action should be r??, c, or f, where ?? is the final amount in the pot from a player in chips).
Usually called during handleStateChange.
Action will be in response to the state in currentGameStateString.


receiveMessage

private java.lang.String receiveMessage()
Receive a message from the server. (Removes the message terminator)


processMessage

private void processMessage(java.lang.String message)
Processes the given message.
Extracts all the information in it and calls the according methods to intialize the hand, store the board cards, ...

Parameters:
message - The message containing the data which are to set.

setBoardCards

private void setBoardCards(int round,
                           java.lang.String cardString)
Extracts the cards from the given string and makes the bot set the given cards to the given round.

Parameters:
round - Round in which the cards are revealed
cardString - Cards which are revealed

extractLastAction

private java.lang.String extractLastAction(java.lang.String roundHistory)
Extracts the string representing the last action out of the given string.

Parameters:
roundHistory - String representing the actions of the round
Returns:
A string representing the last action of the given string

updateState

private void updateState(java.lang.String gameStorageString)
Updates the state of the bot depending of the given string.

Parameters:
gameStorageString - String containing the changes to the state

initHand

private void initHand(int position,
                      int hand,
                      Card[] holeCards,
                      Card[] boardCards)
Initialize the hand.

Parameters:
position - Own position
hand - Hand count
holeCards - own hole cards
boardCards - board cards which are revealed at the start of the hand // TODO are there any poker types with that?

extractCards

private Card[] extractCards(java.lang.String cardString)
Extracts the Cards from the given string and returns it.

Parameters:
cardString - A string representing the card which are to be returned
Returns:
- A Card array containing all cards in the string
- or null, if the string is empty

setEnemyHoleCards

private void setEnemyHoleCards(java.lang.String message)
Extracts all hole cards from the given string and calls the method of the bot to set them.

Parameters:
message - A string containing the information about the revealed hole cards

setPlayers

private void setPlayers(java.lang.String[] playerDesc)
Extracts the player information for each player (names and buy ins) and calls the according method of the bot.

Parameters:
playerDesc -