ca.ualberta.cs.poker.free.server
Class PokerServer

java.lang.Object
  extended by ca.ualberta.cs.poker.free.dynamics.PokerDynamics
      extended by ca.ualberta.cs.poker.free.server.PokerServer
All Implemented Interfaces:
java.lang.Runnable

public class PokerServer
extends PokerDynamics
implements java.lang.Runnable


Field Summary
 java.net.ServerSocket socket
          The socket clients connect to.
 
Fields inherited from class ca.ualberta.cs.poker.free.dynamics.PokerDynamics
amountWon, bettingSequence, board, firstActionOnRound, handNumber, handOver, hole, inPot, roundBets, roundIndex, seatToAct, winnerIndex
 
Constructor Summary
PokerServer(java.security.SecureRandom random, java.net.InetAddress firstPlayerAddress, java.net.InetAddress secondPlayerAddress, int timePerHand)
          Initialize a PokerServer.
PokerServer(java.lang.String firstPlayerAddress, java.lang.String secondPlayerAddress, int timePerHand, java.io.FileReader cardFileReader, java.io.BufferedWriter logFileWriter, java.lang.String resultFile)
          Initialize a PokerServer with logging and card reading capabilities.
 
Method Summary
 void adjustBankrolls()
          Adjust the bankrolls according to current hands winnings.
 void broadcastMatchState()
          Sends the match state as it appears to all players.
 void closeLogFile()
           
 void forfeit(int playerIndex, int numHandsRemaining)
          If a player forfeits, he loses all of his blinds for the remainder of the game.
 char getActionFromResponse(java.lang.String response)
          Gets the last character of a response, which should be 'c', 'r', or 'f'
 java.lang.String getBankrollString()
          Get the bankroll information for the log
 void incrementSeatBankroll(double amount, int seat)
          Increment the bankroll of the player in seat seat an amount amount.
 void initialiseLogFile(java.lang.String filename)
          Create file to write the log into Initialise/close is so that one file descriptor can be used instead of re-creating it each round
 boolean isAppropriate(java.lang.String response)
          Tests if a response is actually a response to the CURRENT action.
static void main(java.lang.String[] args)
          Run the server listening for connections from the localhost to test the code.
 int playerToSeat(int player)
          Which seat is the player in?
 void playHand()
          Play one hand.
 void run()
          Run the server.
 int seatToPlayer(int seat)
          Which player is in the seat?
 void setVerbose(boolean verbose)
          If setVerbose(true), messages sent/received are printed to standard output.
 void verboseMessage(java.lang.String str)
          If verbose==true, prints a message to standard output.
 void writeLog()
          Write the necessary logging information to a file
 
Methods inherited from class ca.ualberta.cs.poker.free.dynamics.PokerDynamics
addToPot, dealCards, endHand, getCardState, getMatchState, getOtherSeat, getWinner, handleAction, handleCall, handleFold, handleRaise, incrementRound, initializeBets, isFirstSeatVisible, isSecondSeatVisible, setHandNumber, startHand, startHand
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

socket

public java.net.ServerSocket socket
The socket clients connect to.

Constructor Detail

PokerServer

public PokerServer(java.security.SecureRandom random,
                   java.net.InetAddress firstPlayerAddress,
                   java.net.InetAddress secondPlayerAddress,
                   int timePerHand)
Initialize a PokerServer. The InetAddress are the client's address we expect to contact us. timePerHand is the amount of time allocated per hand, in milliseconds.


PokerServer

public PokerServer(java.lang.String firstPlayerAddress,
                   java.lang.String secondPlayerAddress,
                   int timePerHand,
                   java.io.FileReader cardFileReader,
                   java.io.BufferedWriter logFileWriter,
                   java.lang.String resultFile)
            throws java.net.UnknownHostException
Initialize a PokerServer with logging and card reading capabilities. The InetAddress are the client's address we expect to contact us. timePerHand is the amount of time allocated per hand, in milliseconds.

Throws:
java.net.UnknownHostException
Method Detail

verboseMessage

public void verboseMessage(java.lang.String str)
If verbose==true, prints a message to standard output.


setVerbose

public void setVerbose(boolean verbose)
If setVerbose(true), messages sent/received are printed to standard output.


run

public void run()
Run the server. Note that a small delay is advisable before attempting to connect to the server.

Specified by:
run in interface java.lang.Runnable

forfeit

public void forfeit(int playerIndex,
                    int numHandsRemaining)
If a player forfeits, he loses all of his blinds for the remainder of the game.


broadcastMatchState

public void broadcastMatchState()
                         throws TimeoutException
Sends the match state as it appears to all players.

Throws:
TimeoutException

playHand

public void playHand()
              throws TimeoutException
Play one hand. One thousand hands make a match.

Throws:
TimeoutException

isAppropriate

public boolean isAppropriate(java.lang.String response)
Tests if a response is actually a response to the CURRENT action.


getActionFromResponse

public char getActionFromResponse(java.lang.String response)
Gets the last character of a response, which should be 'c', 'r', or 'f'


seatToPlayer

public int seatToPlayer(int seat)
Which player is in the seat?


playerToSeat

public int playerToSeat(int player)
Which seat is the player in?


incrementSeatBankroll

public void incrementSeatBankroll(double amount,
                                  int seat)
Increment the bankroll of the player in seat seat an amount amount.


adjustBankrolls

public void adjustBankrolls()
Adjust the bankrolls according to current hands winnings.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Run the server listening for connections from the localhost to test the code.

Throws:
java.lang.Exception

initialiseLogFile

public void initialiseLogFile(java.lang.String filename)
Create file to write the log into Initialise/close is so that one file descriptor can be used instead of re-creating it each round


closeLogFile

public void closeLogFile()

getBankrollString

public java.lang.String getBankrollString()
Get the bankroll information for the log


writeLog

public void writeLog()
Write the necessary logging information to a file