Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## glassfrog.model
Class Dealer

    java.lang.Object
      glassfrog.model.Dealer

All Implemented Interfaces:
  java.io.Serializable, java.lang.Runnable

    public class Dealer

extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable

The Dealer class will handle all of the methods of dealing cards, evaluating hands, pots, and betting actions. There should be one Dealer per Room, and each dealer is assigned a list of Players and a Gamedef to which they will use to play. Dealers may also be assigned a Room in which they can report game outcomes and similar information. The Room may also be used to handle the player requests and actions, although I am not sure that will be the case

Author:
  jdavidso
See Also:
  Serialized Form

Field Summary
`private static int` | `ACTION_DELAY`
`private Hand` | `currentHand`
`private int` | `currentPlayer`
`private Deck` | `deck`
`private static java.lang.String` | `DEFAULT_ACTION`
`private boolean` | `disconnected`
`private java.io.FileWriter` | `divatLog`
`private java.io.BufferedWriter` | `divatLogWriter`
`private boolean` | `error`
`private java.io.FileWriter` | `errorLog`
`private java.io.BufferedWriter` | `errorLogWriter`
`private Gamedef` | `gamedef`
`private boolean` | `gameOver`
`private Gamestate` | `gamestate`
`private int` | `handsPlayed`
`private boolean` | `hasReported`
`private java.lang.String` | `lastAction`
`private java.io.FileWriter` | `matchLog`
`private java.io.BufferedWriter` | `matchLogWriter`
`private java.lang.String` | `name`
`private int` | `numHands`
`private static int` | `PLAYER_TIMEOUT`
`private java.util.LinkedList<Player>` | `players`
`private boolean` | `shuffle`
`private java.io.FileWriter` | `summaryLog`
`private java.io.BufferedWriter` | `summaryLogWriter`

Constructor Summary
`Dealer(java.lang.String name, int numHands, Gamedef gamedef, int seed, java.util.LinkedList<Player> players)`

Method Summary
`void` | `deal()` Deal will deal a game until the Gamedef.gameOver is true.
`private void` | `evaluateHand()` The evaluateHand function runs the routine for determining which players won and how much each of them won.
`private java.lang.String` | `getGameState(Player p)` Get the gamestate for the specified player in the AAAI competition format This is a string representation of the betting, and the private and public cards
`private Player` | `getNextPlayer()` This function returns the next active player.
`private java.lang.String` | `getShowdownGameState(Player p)` Get the Full Showdown Gamestate to send to the players at HandOver
`java.lang.String` | `getStats()` Return stats about the game.
`private void` | `handleDisconnect()` On a disconnect, for now we are going to do a few things.
`private void` | `initLogging()` Initialize the logs for the game.
`boolean` | `isDisconnected()` Check to see if one of the players has disconnected
`boolean` | `isError()` Check to see if the game error'd out
`boolean` | `isGameOver()` Check to see whether or not the games is over
`private boolean` | `isHandOver()` Check to see if everyone is all in or has folded (basically nobody can act anymore)
`private boolean` | `isRoundOver()` Check to see if the round is over according to the rules of the game For this to be satisfied, all the players must now be unable to act.
`private static void` | `loadSettings()`
`private void` | `logDivat()` Log a divat readable gamestate into a divat log.
`void` | `logError(java.lang.Exception ex)` Utility for logging an error message to the errorLogger
`void` | `logState(java.lang.String matchstate)` Log a gamesate to the matchlogger
`private void` | `logStats()` Log the game stats
`private void` | `logSummary()`
`void` | `logWarning(java.lang.String warningMessage)` Utility for logging a warning message to the errorLogger
`private int` | `nextPlayer()` Increments the currentPlayer index to the next player and returns that index.
`private void` | `nextRound()` Update the game to the next round.
`private java.lang.String` | `parseAction(java.lang.String response)` Parse out the last token of the response string and return it as the action the player took
`private void` | `playHand()` Plays a single hand of poker.
`private void` | `playRound()` This function follows the following algorithm: while(!
`private void` | `postBlinds()` This posts the "antes" or blinds for the game.
`private void` | `readObject(java.io.ObjectInputStream in)` An overriden function used when loading the object.
`boolean` | `reconnectPlayers(java.util.LinkedList<Player> players)` Set the players of the game.
`boolean` | `restorePlayer(java.lang.String name, int seat, int stack, int position, int score)` Restores a player matching the name.
`void` | `restoreToHand(int handNumber)` Used to restore the game to a specific hand.
`void` | `run()` Run the dealer in a thread
`private void` | `sendPlayerInfos()` Send the gui players the player info for correct display.
`void` | `setCurrentHand(Hand testHand)` Only used for test purposed, this is a method to create a specific hand
`void` | `setDisconnected(boolean disconnected)` Set the disconnected flag
`private void` | `shutdownLogging()` Close the log files
`private void` | `updateGamestate()` Update the current gamestate.
`private void` | `updatePlayers()` Send the players thier new gamestates
`private void` | `writeObject(java.io.ObjectOutputStream out)` An overriden function used to change the default serialization behavior on a write

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### gamedef

    private Gamedef gamedef

### gamestate

    private Gamestate gamestate

### currentHand

    private Hand currentHand

### players

    private java.util.LinkedList<Player> players

### deck

    private Deck deck

### currentPlayer

    private int currentPlayer

### handsPlayed

    private int handsPlayed

### numHands

    private int numHands

### lastAction

    private java.lang.String lastAction

### name

    private java.lang.String name

### gameOver

    private boolean gameOver

### hasReported

    private boolean hasReported

### error

    private boolean error

### shuffle

    private boolean shuffle

### errorLog

    private transient java.io.FileWriter errorLog

### matchLog

    private transient java.io.FileWriter matchLog

### divatLog

    private transient java.io.FileWriter divatLog

### summaryLog

    private transient java.io.FileWriter summaryLog

### errorLogWriter

    private transient java.io.BufferedWriter errorLogWriter

### matchLogWriter

    private transient java.io.BufferedWriter matchLogWriter

### divatLogWriter

    private transient java.io.BufferedWriter divatLogWriter

### summaryLogWriter

    private transient java.io.BufferedWriter summaryLogWriter

### disconnected

    private boolean disconnected

### DEFAULT_ACTION

    private static java.lang.String DEFAULT_ACTION

### PLAYER_TIMEOUT

    private static int PLAYER_TIMEOUT

### ACTION_DELAY

    private static int ACTION_DELAY

Constructor Detail

### Dealer

    public Dealer(java.lang.String name,
                  int numHands,
                  Gamedef gamedef,
                  int seed,
                  java.util.LinkedList<Player> players)

Parameters:
  `name` - A String to represent the name of the game for the log file
  `numHands` - the number of hands of which the dealer will play
  `gamedef` - The @Gamedef that will be used to play
  `seed` - An integer representing the seed in which to seed the deck RNG
  `players` - A list of Players that will be seated in the game.

Method Detail

### reconnectPlayers

    public boolean reconnectPlayers(java.util.LinkedList<Player> players)

  Set the players of the game. Used by the room to set the players up.

  Parameters:
    `players` - LinkedList containing player objects for the game
  Returns:
    True for successful reconnect

### initLogging

    private void initLogging()

  Initialize the logs for the game. The logname will be of the form roomname_timestamp.(log || .err) where roomname is the name passed from the server to the room and the timestamp

### logError

    public void logError(java.lang.Exception ex)

  Utility for logging an error message to the errorLogger

  Parameters:
    `ex` - An exception to log

### logWarning

    public void logWarning(java.lang.String warningMessage)

  Utility for logging a warning message to the errorLogger

  Parameters:
    `warningMessage` - A message to log to the error log

### logState

    public void logState(java.lang.String matchstate)

  Log a gamesate to the matchlogger

  Parameters:
    `matchstate` - the gamestate message to log to the match log

### logStats

    private void logStats()

  Log the game stats

### logDivat

    private void logDivat()

  Log a divat readable gamestate into a divat log. Note: Only implemented for heads up 2 player.

  Parameters:
    `value` - The value of the game for the first player

### logSummary

    private void logSummary()

### deal

    public void deal()

  Deal will deal a game until the Gamedef.gameOver is true. This allows for any number of options to be specified to the Gamedef to allow for different game ending situations (bankroll, handscount, forever). The deal function follows the following algorithm: While not gameover: generate a new hand for the players generate a new gamestate play hand The gamestate here refers to the game properties such as potsize, folded players, etc.

### shutdownLogging

    private void shutdownLogging()

  Close the log files

### sendPlayerInfos

    private void sendPlayerInfos()

  Send the gui players the player info for correct display.

### setCurrentHand

    public void setCurrentHand(Hand testHand)

  Only used for test purposed, this is a method to create a specific hand

  Parameters:
    `testHand` -

### playHand

    private void playHand()

  Plays a single hand of poker.

### playRound

    private void playRound()

  This function follows the following algorithm: while(!roundOver): get next player to act send gamestate to player wait for action from player or timeout update gamestate This essentially plays one round of poker, gets the actions from all the players and keeps an up to date gamestate information.

### handleDisconnect

    private void handleDisconnect()

  On a disconnect, for now we are going to do a few things. First we are going to end the hand in a fold for the disconnected player Second, we are going to stop the match and set a flag for the Room to pickup. This will allow the room to serialize the dealer object to file, and when we reload, we will grab the dealer object, load it in and continue from the very next hand.

### nextRound

    private void nextRound()

  Update the game to the next round. Reset players current bets and action flags

### postBlinds

    private void postBlinds()

  This posts the "antes" or blinds for the game. Assumes that after the blinds are posted, the action falls to the next player at the table.

### nextPlayer

    private int nextPlayer()

  Increments the currentPlayer index to the next player and returns that index.

  Returns:
    An integer index to the next player in the list of players % size

### getNextPlayer

    private Player getNextPlayer()

  This function returns the next active player. That is, the next player that hasn't folded or isn't all in or the player we started at (That player must have went all in and everybody else folded) Probably shouldn't be able to occur.

  Returns:
    The next active player

### isRoundOver

    private boolean isRoundOver()

  Check to see if the round is over according to the rules of the game For this to be satisfied, all the players must now be unable to act. We are going to refactor these checks out and see if a player "can act"

  Returns:
    Whether or not the round is over.

### updateGamestate

    private void updateGamestate()

  Update the current gamestate. This will update the game based on the action that was taken by the player and set important things like is the hand or round over etc, etc.

### isHandOver

    private boolean isHandOver()

  Check to see if everyone is all in or has folded (basically nobody can act anymore)

  Returns:
    True if the hand is over and we should evaluate

### evaluateHand

    private void evaluateHand()

  The evaluateHand function runs the routine for determining which players won and how much each of them won. First it will determine the rank of the players, rank 0 being the winner(s) followed by rank 1, rank 2, etc. This is done for each sidepot, and we pay the money out of the potsize.

### getGameState

    private java.lang.String getGameState(Player p)

  Get the gamestate for the specified player in the AAAI competition format This is a string representation of the betting, and the private and public cards

  Parameters:
    `p` - The player for whom to show the gamestate
  Returns:
    A string representing the current state of the game

### getShowdownGameState

    private java.lang.String getShowdownGameState(Player p)

  Get the Full Showdown Gamestate to send to the players at HandOver

  Parameters:
    `position` - The position of the player to send this too.
  Returns:
    A string representation of the Full Showdown Gamestate

### updatePlayers

    private void updatePlayers()

  Send the players thier new gamestates

### parseAction

    private java.lang.String parseAction(java.lang.String response)

  Parse out the last token of the response string and return it as the action the player took

  Parameters:
    `playerResponse` -
  Returns:
    the action from the response string

### run

    public void run()

  Run the dealer in a thread

  Specified by:
    `run` in interface `java.lang.Runnable`

### getStats

    public java.lang.String getStats()

  Return stats about the game.

  Returns:
    A string representing the room stats

### isGameOver

    public boolean isGameOver()

  Check to see whether or not the games is over

  Returns:
    True for gameOver, False otherwise

### isDisconnected

    public boolean isDisconnected()

  Check to see if one of the players has disconnected

  Returns:
    True is there has been a disconect, False otherwise

### isError

    public boolean isError()

  Check to see if the game error'd out

  Returns:
    True if there was an error

### setDisconnected

    public void setDisconnected(boolean disconnected)

  Set the disconnected flag

  Parameters:
    `disconnected` - a boolean to set the disconnected flag

### writeObject

    private void writeObject(java.io.ObjectOutputStream out)
                      throws java.io.IOException

  An overriden function used to change the default serialization behavior on a write

  Parameters:
    `out` - the output stream to write the object to
  Throws:
    `java.io.IOException`

### readObject

    private void readObject(java.io.ObjectInputStream in)
                     throws java.io.IOException,
                            java.lang.ClassNotFoundException

  An overriden function used when loading the object. The default behavior is used and the disconnect flag is reset

  Parameters:
    `in` - The input stream to load the object from
  Throws:
    `java.io.IOException`
    `java.lang.ClassNotFoundException`

### restorePlayer

    public boolean restorePlayer(java.lang.String name,
                                 int seat,
                                 int stack,
                                 int position,
                                 int score)

  Restores a player matching the name. This resets thier stack score and position

  Parameters:
    `name` - The players name to restore
    `seat` - The seat to restore the player to
    `stack` - The stacksize the player needs restoring to
    `position` - The positions to restore the player to
    `score` - The score of the player to be restored
  Returns:
    True on a sucessful restore, false otherwise

### restoreToHand

    public void restoreToHand(int handNumber)

  Used to restore the game to a specific hand. The game deals out the hands from the deck until the hand number is reached

  Parameters:
    `handNumber` - The hand to restore to

### loadSettings

    private static void loadSettings()
                              throws javax.xml.parsers.ParserConfigurationException,
                                     org.xml.sax.SAXParseException,
                                     org.xml.sax.SAXException,
                                     java.io.IOException,
                                     java.lang.InterruptedException

  Throws:
    `javax.xml.parsers.ParserConfigurationException`
    `org.xml.sax.SAXParseException`
    `org.xml.sax.SAXException`
    `java.io.IOException`
    `java.lang.InterruptedException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD