Glomus.Server
Class Player

java.lang.Object
  extended by Glomus.Server.Player
Direct Known Subclasses:
AIplayer, RemotePlayer, ServerPlayer

public class Player
extends java.lang.Object

The Player class is the server-side representation of a remote player. Two types of Players exist in a game (both use the same class), user players, who have a remote AI that is being tested through a series of games, and replacement players, who use a server-side AI and act as other players to test the user AI against.

Notes about usage: Before a Player is ready to play a game, the Initialization method must be called to setup all the player and GameBoard data. Once a Player has played all games it will play, the delete method should be called to allow the Player a chance to close all I/O, etc. Actual game play is via the refute, suggest, and accuse methods. All broadcasting must use the forward method.

The Player class depends heavily upon the common protocol defined for client-server interactions. Reference the Protocol class for more information.

See Also:
Protocol, GameBoard

Constructor Summary
Player(java.net.Socket link)
          Creates the server-side representation of a remote player.
 
Method Summary
 java.lang.String accuse()
          Asks the Player to communicate with its remote counterpart and make an accusation if they wish
 void deletePlayer()
          Closes all I/O streams and sockets for this player.
 void forceMove(java.lang.String newLocation)
          Unconditionally moves a player from one room to another (This is used by the Server to move a player to a room they were suggested in)
 void forward(java.lang.String message)
          Forwards the broadcast message to its remote counterpart
 java.lang.String getAnswer()
          Asks the player to send all the pieces of the answer that it knows for certain
 java.util.HashSet<java.lang.String> getCards()
          Returns this player's set of cards
 java.lang.String getInit()
          Returns the last initialization message this Player received
 java.lang.String getLocation()
          Returns the player's current location
 java.lang.String getName()
          Asks the Player to return its name
 void initialize(java.lang.String initMessage, java.lang.String name, java.lang.String startingRoom, java.util.HashSet<java.lang.String> cards, java.util.ArrayList<java.lang.String> players, java.util.HashSet<java.lang.String> suspects, java.util.HashSet<java.lang.String> weapons, java.util.HashSet<java.lang.String> rooms, java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.String>> connections)
          Initializes a player for a given game and GameBoard.
 java.lang.String refute(java.lang.String claim)
          Asks the Player to communicate with its remote counterpart and refute the last suggestion (if it can)
 java.lang.String suggest()
          Asks the Player to communicate with its remote counterpart and make a suggestion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Player

public Player(java.net.Socket link)
       throws java.io.IOException,
              java.lang.IllegalArgumentException
Creates the server-side representation of a remote player. Note, the constructor only initializes the data that is necessary for communication, in order to play a new game, the initialize method must be called

Parameters:
link - The Socket on which the real remote player is communicating
Throws:
java.io.IOException - If the I/O streams from the socket cannot be initialized
java.lang.IllegalArgumentException - If a null value is specified for the link
Method Detail

initialize

public void initialize(java.lang.String initMessage,
                       java.lang.String name,
                       java.lang.String startingRoom,
                       java.util.HashSet<java.lang.String> cards,
                       java.util.ArrayList<java.lang.String> players,
                       java.util.HashSet<java.lang.String> suspects,
                       java.util.HashSet<java.lang.String> weapons,
                       java.util.HashSet<java.lang.String> rooms,
                       java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.String>> connections)
                throws java.lang.IllegalArgumentException
Initializes a player for a given game and GameBoard. Initialize must be called before the start of each new game

Parameters:
initMessage - The initialization message, containing all the data specified in the following arguments (kept so that it can be passed on to the remote player, if there is one, and to a ServerPlayer if need be)
name - The name of this character
startingRoom - The room this character will start in
cards - This player's cards for this game
players - All suspects who are also active players in this game
suspects - The list of all suspects
weapons - The list of all weapons
rooms - The list of all rooms
connections - A connection detailing for each room which other rooms it connects to
Throws:
java.lang.IllegalArgumentException - If a null argument is given or if any of the lists do not contain enough information

suggest

public java.lang.String suggest()
                         throws IllegalTurnException,
                                TimeoutException,
                                NetworkFailureException,
                                java.lang.IllegalArgumentException
Asks the Player to communicate with its remote counterpart and make a suggestion

Returns:
The claim made by the player, in the form, "claim [suspect] [weapon] [room] [player]"
Throws:
IllegalTurnException - if player does not move to a proper room
java.lang.IllegalArgumentException - When player's message includes illegal values
TimeoutException
NetworkFailureException

refute

public java.lang.String refute(java.lang.String claim)
                        throws IllegalTurnException,
                               TimeoutException,
                               NetworkFailureException
Asks the Player to communicate with its remote counterpart and refute the last suggestion (if it can)

Parameters:
claim - The claim to refute, in the form "[suspect] [weapon] [room] [player]"
Returns:
the ability or inability of the remote player to refute the last suggestion; in the format "show" if not possible, and "show [value]" if possible
Throws:
IllegalTurnException - when the remote player either didn't refute when it could have, or refuted with a card it does not have
TimeoutException
NetworkFailureException

accuse

public java.lang.String accuse()
                        throws IllegalTurnException,
                               TimeoutException,
                               NetworkFailureException,
                               java.lang.IllegalArgumentException
Asks the Player to communicate with its remote counterpart and make an accusation if they wish

Returns:
the message to broadcast to all the other players about this player's accusation; in the format "accuse" if not desired and "accuse [suspect] [weapon] [room]" if desired
Throws:
java.lang.IllegalArgumentException - when player's message includes illegal values
IllegalTurnException
TimeoutException
NetworkFailureException

getAnswer

public java.lang.String getAnswer()
                           throws IllegalTurnException,
                                  TimeoutException,
                                  NetworkFailureException
Asks the player to send all the pieces of the answer that it knows for certain

Returns:
A string containing which pieces of the answer are known for certain and blanks for those that are not
Throws:
IllegalTurnException
TimeoutException
NetworkFailureException

forward

public void forward(java.lang.String message)
Forwards the broadcast message to its remote counterpart

Parameters:
message - The message to forward to the remote player

deletePlayer

public void deletePlayer()
Closes all I/O streams and sockets for this player. This should be called for each player in a game, before the game signals that it is finished


forceMove

public void forceMove(java.lang.String newLocation)
               throws java.lang.IllegalArgumentException
Unconditionally moves a player from one room to another (This is used by the Server to move a player to a room they were suggested in)

Throws:
java.lang.IllegalArgumentException - If the location to move to is null

getName

public java.lang.String getName()
Asks the Player to return its name

Returns:
The name of this Player

getLocation

public java.lang.String getLocation()
Returns the player's current location

Returns:
The location of this Player

getCards

public java.util.HashSet<java.lang.String> getCards()
Returns this player's set of cards

Returns:
The set of cards this Player has

getInit

public java.lang.String getInit()
Returns the last initialization message this Player received

Returns:
The last init message given to this player