ca.ualberta.cs.poker.free.client
Class PokerClient

java.lang.Object
  extended by ca.ualberta.cs.poker.free.client.PokerClient
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
AdvancedPokerClient, PokerAcademyClient, RandomPokerClient

public class PokerClient
extends java.lang.Object
implements java.lang.Runnable

Root for all example Java implementations of the client interface. Basic functionality: sends a version statement, receives state messages and remembers them, can send replies (actions), and exits on an ENDGAME message from the server. The function to overload is handleStateChange(). sendRaise(), sendCall(), and sendFold() can be used to send actions to the server. currentGameStateString has the most recent state information.


Field Summary
 java.lang.String currentGameStateString
          This is the current game state.
 
Constructor Summary
PokerClient()
          Creates a new instance of PokerClient.
 
Method Summary
 void close()
          Close the connection.
 void connect(java.net.InetAddress iaddr, int port)
          Connects to the server at the given IP address and port number.
 java.lang.String getClientID()
          Returns the IP address and port number of the client.
 void handleStateChange()
          Override to handle a state change.
 boolean isComplete(java.lang.String result)
          Test if the message is complete (contains a terminal character)
 java.lang.String receiveMessage()
          Receive a message from the server.
 void run()
          Start the client.
 void sendAction(char action)
          Send an action (action should be r, c, or f).
 void sendCall()
          send a call action.
 void sendFold()
          send a fold action.
 void sendMessage(java.lang.String message)
          Send a message to the server.
 void sendRaise()
          send a raise action.
 void setVerbose(boolean verbose)
          Sets the verbose flag (if true, prints messages sent and received to stdout).
 void showVerbose(java.lang.String message)
          Print a message to stdout if verbose==true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentGameStateString

public java.lang.String currentGameStateString
This is the current game state. It is not changed during a call to handleStateChange()

Constructor Detail

PokerClient

public PokerClient()
Creates a new instance of PokerClient. Need to connect(), then run() to start process.

Method Detail

setVerbose

public void setVerbose(boolean verbose)
Sets the verbose flag (if true, prints messages sent and received to stdout).


getClientID

public java.lang.String getClientID()
Returns the IP address and port number of the client.


showVerbose

public void showVerbose(java.lang.String message)
Print a message to stdout if verbose==true.


handleStateChange

public void handleStateChange()
                       throws java.io.IOException,
                              java.net.SocketException
Override to handle a state change. Observe that a state change does NOT imply it is your turn.

Throws:
java.io.IOException
java.net.SocketException

connect

public void connect(java.net.InetAddress iaddr,
                    int port)
             throws java.io.IOException,
                    java.net.SocketException
Connects to the server at the given IP address and port number.

Throws:
java.io.IOException
java.net.SocketException

sendAction

public void sendAction(char action)
                throws java.io.IOException,
                       java.net.SocketException
Send an action (action should be r, c, or f). Usually called during handleStateChange. Action will be in response to the state in currentGameStateString.

Throws:
java.io.IOException
java.net.SocketException

sendRaise

public void sendRaise()
               throws java.io.IOException,
                      java.net.SocketException
send a raise action.

Throws:
java.io.IOException
java.net.SocketException

sendCall

public void sendCall()
              throws java.io.IOException,
                     java.net.SocketException
send a call action.

Throws:
java.io.IOException
java.net.SocketException

sendFold

public void sendFold()
              throws java.io.IOException,
                     java.net.SocketException
send a fold action.

Throws:
java.io.IOException
java.net.SocketException

run

public void run()
Start the client. Should call connect() before running.

Specified by:
run in interface java.lang.Runnable

close

public void close()
           throws java.io.IOException
Close the connection. Called in response to an ENDGAME message from the server.

Throws:
java.io.IOException

receiveMessage

public java.lang.String receiveMessage()
                                throws java.net.SocketException,
                                       java.io.IOException
Receive a message from the server. Removes a message terminator (period).

Throws:
java.net.SocketException
java.io.IOException

isComplete

public boolean isComplete(java.lang.String result)
Test if the message is complete (contains a terminal character)


sendMessage

public void sendMessage(java.lang.String message)
                 throws java.net.SocketException,
                        java.io.IOException
Send a message to the server. Appends a message terminator (period).

Throws:
java.net.SocketException
java.io.IOException