Glomus.Server
Class GameBoard

java.lang.Object
  extended by java.lang.Thread
      extended by Glomus.Server.GameBoard
All Implemented Interfaces:
java.lang.Runnable

public class GameBoard
extends java.lang.Thread

The GameBoard class oversees and manages the running of a Glomus game.

GameBoard has an initial mode it waits in until the game is ready to be run (either by time limit or because it is full). Gameboard will then run through a set number of individual games, logging results, replacing misbehaving players, etc. Any given game within the set of games played will have a random turn order though the same player will always play as the same suspect throughout all games to ensure consistency in the log file. (IE- Mr Green will always be Mr Green, Miss Scarlet always Miss Scarlet, etc). The GameBoard polices all games played, and replaces without question any misbehaving player with a standard default player that is known to play a legal game. Players receive no second chances, being kicked out is final. If all players in a given set of games have been kicked out the GameBoard ceases with testing (there is no point to test Server Side players against each other). The GameBoard class differentiates between players added via the addPlayer method (which are assumed to be user players) and players it adds to run a full game. Players added via the addPlayer method are treated as user-end clients, all other players are treated as Server-side agents.

The GameBoard class is its own Thread and runs entirely separately from the Server class. Once Execution is finished (nicely or not) the GameBoard signals the Server that it has finished and exits.

The GameBoard, like all classes in the Glomus.Server package, depends upon the Protocol class to determine what is legal communication protocol and detect illegal protocol accordingly.

See Also:
Protocol, Player

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected static java.lang.String DEFAULT_CONFIGURATION
          The configuration that describes a default clue game
protected static int POINTS_FOR_CORRECT
          The number of points given to a player for each known piece of the answer that is correct
protected static int POINTS_FOR_WIN
          The number of 'bonus' points given to the player who won the game
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
GameBoard(java.lang.String name, Player newPlayer, boolean open, int maxPlayers, int iterations)
          Constructs a new game with the classic setup
GameBoard(java.lang.String name, Player newPlayer, boolean open, int maxPlayers, int iterations, java.lang.String board)
          Constructs a new, custom game board
 
Method Summary
 void addPlayer(Player toAdd)
          Adds a user-player to the game (should only be called during setup, calling after a game has launched will result in an IllegalArgumentException being thrown)
 boolean full()
          Tells whether or not the game is full and thus if it can accept more players legally (a game is full when it has as many players as requested by the player who initially created it, not necessarily when it has as many players as it does suspects)
 java.lang.String getGameName()
          Returns the name of this game
 long getTime()
          Returns the system time in milleseconds of this GameBoard's creation.
protected  boolean handleAccusation()
          Asks the current player to make an accusation (if they so desire)
protected  void handleRefute(java.lang.String claim)
          Asks, everyone to refute the claim made by the current player (excepting the current player itself)
protected  java.lang.String handleSuggestion()
          Asks for a suggestion/claim from the current player
protected static Player replace()
          Creates a Server-side replacement player ready to play a game (this method only obtains a new legal player, this player must still be initialized and placed in the rotation)
 void run()
          The 'main' method of the Game; calling run sets up the game cycle and starts testing the players
protected  void setup()
          Sets up a new game and makes it ready to play
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

POINTS_FOR_CORRECT

protected static final int POINTS_FOR_CORRECT
The number of points given to a player for each known piece of the answer that is correct

See Also:
Constant Field Values

POINTS_FOR_WIN

protected static final int POINTS_FOR_WIN
The number of 'bonus' points given to the player who won the game

See Also:
Constant Field Values

DEFAULT_CONFIGURATION

protected static final java.lang.String DEFAULT_CONFIGURATION
The configuration that describes a default clue game

See Also:
Constant Field Values
Constructor Detail

GameBoard

public GameBoard(java.lang.String name,
                 Player newPlayer,
                 boolean open,
                 int maxPlayers,
                 int iterations)
          throws java.lang.IllegalArgumentException
Constructs a new game with the classic setup

Parameters:
name - The name this session of games is registered under with the Server
newPlayer - The first player of the game (the one who requested to play in the first place.) More players may be added via the addPlayer method
open - Defines if this is an open of closed game. If true, other user players will be allowed to connect to this game and play, if false, only the specified user player, and a group of computer players will play
maxPlayers - The number of agents, or real players, that will play the game
iterations - The number of individual games to play with the same set of players
Throws:
java.lang.IllegalArgumentException - If the default values were not initialized, if any of the given values are null, if they have zero length, or if more players are specified than there are characters to play as

GameBoard

public GameBoard(java.lang.String name,
                 Player newPlayer,
                 boolean open,
                 int maxPlayers,
                 int iterations,
                 java.lang.String board)
          throws java.lang.IllegalArgumentException
Constructs a new, custom game board

Parameters:
name - The name this session of games is registered under with the Server
newPlayer - The first player of the game (the one who requested to play in the first place.) More players may be added via the addPlayer method
open - Defines if this is an open of closed game. If true, other user players will be allowed to connect to this game and play, if false, only the specified user player, and a group of computer players will play
maxPlayers - The number of agents, or real players, that will play the game
iterations - The number of individual games to play with the same set of players
board - The String provided from the client that specifies the game board, its suspects weapons, and rooms
Throws:
java.lang.IllegalArgumentException - If any of the given values are null, if they have zero length, if more players are specified than there are characters to play as, or if any of the specified GameBoard data in the board string would construct a board that is inconsistent or illegal
Method Detail

getTime

public long getTime()
Returns the system time in milleseconds of this GameBoard's creation.

Returns:
The creation time of this GameBoard

getGameName

public java.lang.String getGameName()
Returns the name of this game

Returns:
The name of the this game

addPlayer

public void addPlayer(Player toAdd)
               throws java.lang.IllegalArgumentException
Adds a user-player to the game (should only be called during setup, calling after a game has launched will result in an IllegalArgumentException being thrown)

Parameters:
toAdd - The player to add to this set of games
Throws:
java.lang.IllegalArgumentException - If the player to add is null, or if the game is full

full

public boolean full()
Tells whether or not the game is full and thus if it can accept more players legally (a game is full when it has as many players as requested by the player who initially created it, not necessarily when it has as many players as it does suspects)

Returns:
True if the game is full, false is more space is left

replace

protected static Player replace()
                         throws java.io.IOException,
                                java.lang.InterruptedException,
                                java.lang.IllegalArgumentException
Creates a Server-side replacement player ready to play a game (this method only obtains a new legal player, this player must still be initialized and placed in the rotation)

Returns:
The new user player to replace the misbehaving one
Throws:
java.io.IOException
java.lang.InterruptedException
java.lang.IllegalArgumentException

run

public void run()
The 'main' method of the Game; calling run sets up the game cycle and starts testing the players

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

handleSuggestion

protected java.lang.String handleSuggestion()
                                     throws java.io.IOException,
                                            java.lang.IllegalArgumentException,
                                            java.lang.InterruptedException
Asks for a suggestion/claim from the current player

Returns:
The raw suggestion made by the player (IE- minus the protocol keyword that identifies it as a claim)
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.InterruptedException

handleRefute

protected void handleRefute(java.lang.String claim)
                     throws java.io.IOException,
                            java.lang.IllegalArgumentException,
                            java.lang.InterruptedException
Asks, everyone to refute the claim made by the current player (excepting the current player itself)

Parameters:
claim - The claim made by the current player
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.InterruptedException

handleAccusation

protected boolean handleAccusation()
                            throws java.io.IOException,
                                   java.lang.IllegalArgumentException,
                                   java.lang.InterruptedException
Asks the current player to make an accusation (if they so desire)

Returns:
Whether or not the accusation was true, if it was, the game is over
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.InterruptedException

setup

protected void setup()
              throws java.lang.IllegalArgumentException
Sets up a new game and makes it ready to play

Throws:
java.lang.IllegalArgumentException