uk.org.redfelineninja.risk.robot
Class GameState

java.lang.Object
  |
  +--uk.org.redfelineninja.risk.robot.GameState
All Implemented Interfaces:
RiskClientInterface

public class GameState
extends java.lang.Object
implements RiskClientInterface

This class stores all information about the game state for interagation by the robot. It monitors network messages in order to maintain its own state without any invention from a robot's programmer. From this network activity this class is also responsible for calling the robots makeMove method. A robots author should only use the interogation methods. Those that reflect game state, not that alter game state. Currently GameState allows programmers to access all the methods in the RiskClientInterface. This will be changed for the next version, they will be removed and put somewhere private. Untill then a robot author who calls these funtions is likely to find their robot doing some very strange things.


Field Summary
static int ATTACK
          Mode constant, a friendly country has been selected, we are expecting attack something.
static int FORTIFY
          Mode constant, waiting for a country to fortify.
static int FORTIFY_PLACEMENT
          Mode constant, placement limieted by the rules of fortification.
static int INIT_PLACEMENT
          Mode constant, placement of initial armies.
static int INIT_SELECTION
          Mode constant, initial selection of countries.
static int LIMITED_PLACEMENT
          Mode constant, placement restricted after a country has been defeated.
static int NULL
          Mode constant, game is in null state.
static int PLACEMENT
          Mode constant, unrestricted placement of armies from the pool.
static int SELECTION
          Mode constant, No country is selected.
 
Constructor Summary
GameState(java.io.File f, Robot r)
          Create a new GameState.
 
Method Summary
 void gameOver(Player victor)
          Called when the game is won.
 void gameOver(Player player, java.lang.String reason)
          Called when the game is stopped by the server.
 int getBoardSize()
          Get the size of the board.
 Move getContinentWeights()
          Get the percentage ownership of each continent.
 uk.org.redfelineninja.risk.robot.Country getCountry(int i)
          Get the requested country.
 uk.org.redfelineninja.risk.robot.Country getCountry(java.lang.String name)
          Get the requested country.
 Move getLegalMoves()
          Get the Moves available to the robot.
 int getMode()
          Get the current mode.
 Move getRelativeStrength()
          Get the relative strength of each country on the board.
 float getRelativeStrength(uk.org.redfelineninja.risk.robot.Country c)
          Get the relative strength of a single country.
 uk.org.redfelineninja.risk.robot.Country getSelection()
          Get the currently selected country.
 Move getStrength()
          Get the absolute strength of each country on the board.
 void lostPlayer(Player player)
          Called when a player leaves the game (or if his connection is timed out).
 void message(java.lang.String message)
          Message sent over the chat system to all clients.
 boolean myTurn()
          Test whether the robot associated with this GameState is the active player.
 void newGame(Player[] players)
          Called when the games owner decides to stop waiting for new players and start playing.
 void newPlayer(Player player)
          Called when a new player has joined the game the client is waiting to play
 void newSpectator(Player player)
          Called whenever a new spectator has joined the game.
 void select(java.lang.String country)
          Select the supplied country.
 void setArmies(java.lang.String country, int a)
          Set the number of armies in a country.
 void setCards(Card[] cards)
          Tell the client the cards that the player has.
 void setDice(int[] die)
          Supply the current state of the dice to those it interests.
 void setOwner(java.lang.String country, Player player)
          Set the owner of the country to the player.
 void setServer(RiskServerInterface s)
          Set the server that this game state is attached to.
 void setTurn(Player player)
          It is player's turn
 void showStatus(java.lang.String status)
          Display the supplied string in the clients status line.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final int NULL
Mode constant, game is in null state. The game should never be in a null state by the time the robot is told to make a move.

See Also:
Constant Field Values

INIT_SELECTION

public static final int INIT_SELECTION
Mode constant, initial selection of countries. In this mode the robot must select any unoccupied country in order to claim it as his own.

See Also:
Constant Field Values

INIT_PLACEMENT

public static final int INIT_PLACEMENT
Mode constant, placement of initial armies. In this mode the robot must select which country it wishes to place an army into. No attacks will be made following this placement.

See Also:
Constant Field Values

PLACEMENT

public static final int PLACEMENT
Mode constant, unrestricted placement of armies from the pool. In this mode the robot must select which country it wishes to place an army into. Following this robot may enter SELECTION mode.

See Also:
Constant Field Values

ATTACK

public static final int ATTACK
Mode constant, a friendly country has been selected, we are expecting attack something. Here a robot must pick the country that neighbours the current selection that it wants to attack or pick select to return to selection mode.

See Also:
Constant Field Values

LIMITED_PLACEMENT

public static final int LIMITED_PLACEMENT
Mode constant, placement restricted after a country has been defeated. In this mode armies may only be placed into the selected country and the country that was defeated. It is a good idea for the robot to record the defeated country, it is currently not stored within the GameState.

See Also:
Constant Field Values

FORTIFY_PLACEMENT

public static final int FORTIFY_PLACEMENT
Mode constant, placement limieted by the rules of fortification. Here the robot must pick countries that are adjacent to the selected country.

See Also:
Constant Field Values

FORTIFY

public static final int FORTIFY
Mode constant, waiting for a country to fortify. The robot must pick any country whose armies need to me moved somewhere else. The robot may also pick done when it has finished.

See Also:
Constant Field Values

SELECTION

public static final int SELECTION
Mode constant, No country is selected. The robot is required to pick a country to attack with. It may also pick done or fortify.

See Also:
Constant Field Values
Constructor Detail

GameState

public GameState(java.io.File f,
                 Robot r)
          throws java.io.FileNotFoundException
Create a new GameState. This takes a map definition file and a Robot. Make sure that the map definition is the same as the one used by the server.

Method Detail

getMode

public int getMode()
Get the current mode. This can be used to determine the current game state. Used in conjuction with the modal constants such as PLACEMENT.

Returns:
the current mode

myTurn

public boolean myTurn()
Test whether the robot associated with this GameState is the active player.

Returns:
true of the robot is that active player.

getBoardSize

public int getBoardSize()
Get the size of the board.

Returns:
the number of countries in the board

getCountry

public final uk.org.redfelineninja.risk.robot.Country getCountry(int i)
Get the requested country.

Parameters:
i - index of the country
Returns:
the country at the specified index

getCountry

public final uk.org.redfelineninja.risk.robot.Country getCountry(java.lang.String name)
Get the requested country.

Parameters:
name - the name of the country to be fetched
Returns:
the country of the specified

getSelection

public final uk.org.redfelineninja.risk.robot.Country getSelection()
Get the currently selected country.


getStrength

public final Move getStrength()
Get the absolute strength of each country on the board.

Absolute strength is the number of armies each contry contains.

Returns:
a Move where each element is the strength of the corresponding country

getRelativeStrength

public final Move getRelativeStrength()
Get the relative strength of each country on the board.

Relative strength is the absolute strength of a country and its friendly neighbours minus the absolute strength of all hostile neighbours.

Returns:
a Move where each element is the relative strength of the corresponding country

getRelativeStrength

public final float getRelativeStrength(uk.org.redfelineninja.risk.robot.Country c)
Get the relative strength of a single country.

Relative strength is the absolute strength of a country and its friendly neighbours minus the absolute strength of all hostile neighbours.

Returns:
the relative strength of the supplied country

getContinentWeights

public final Move getContinentWeights()
Get the percentage ownership of each continent.

This does not work and exists only as a test stub. Do not use this unless you are developing the Risk Arena.

Returns:
a Move where each country that the player owns has a fraction associated with it. This fraction is the fraction of the conitnent that this player owns.

getLegalMoves

public Move getLegalMoves()
Get the Moves available to the robot.

This method is used internally to ensure that the robot only makes legal moves. It can be used by advanced robots to prevent wasting time analysing illegal moves.

Returns:
a Move where each element is either 0 or 1. 0 represents an illegal move.

setServer

public void setServer(RiskServerInterface s)
Set the server that this game state is attached to.

Robot authurs should not normally call this method.


newPlayer

public void newPlayer(Player player)
Called when a new player has joined the game the client is waiting to play

Robot authurs should not normally call this method.

Specified by:
newPlayer in interface RiskClientInterface

newSpectator

public void newSpectator(Player player)
Called whenever a new spectator has joined the game. This can be ignored unless the client has a talker that supports private talking. Robots could communicate their internal state like this if desired.

Robot authurs should not normally call this method.

Specified by:
newSpectator in interface RiskClientInterface

lostPlayer

public void lostPlayer(Player player)
Called when a player leaves the game (or if his connection is timed out). Leaving mid-game is anti-social but it will happen.

Robot authurs should not normally call this method.

Specified by:
lostPlayer in interface RiskClientInterface

newGame

public void newGame(Player[] players)
Called when the games owner decides to stop waiting for new players and start playing.

Robot authurs should not normally call this method.

Specified by:
newGame in interface RiskClientInterface

gameOver

public void gameOver(Player victor)
Called when the game is won.

Robot authurs should not normally call this method.

Specified by:
gameOver in interface RiskClientInterface

gameOver

public void gameOver(Player player,
                     java.lang.String reason)
Called when the game is stopped by the server.

Robot authurs should not normally call this method.

Specified by:
gameOver in interface RiskClientInterface

message

public void message(java.lang.String message)
Message sent over the chat system to all clients.

Robot authurs should not normally call this method.

Specified by:
message in interface RiskClientInterface

setTurn

public void setTurn(Player player)
It is player's turn

Robot authurs should not normally call this method.

Specified by:
setTurn in interface RiskClientInterface

showStatus

public void showStatus(java.lang.String status)
Display the supplied string in the clients status line.

Robot authurs should not normally call this method.

Specified by:
showStatus in interface RiskClientInterface

setArmies

public void setArmies(java.lang.String country,
                      int a)
Set the number of armies in a country.

Robot authurs should not normally call this method.

Specified by:
setArmies in interface RiskClientInterface

setOwner

public void setOwner(java.lang.String country,
                     Player player)
Set the owner of the country to the player.

Robot authurs should not normally call this method.

Specified by:
setOwner in interface RiskClientInterface

select

public void select(java.lang.String country)
Select the supplied country.

Robot authurs should not normally call this method.

Specified by:
select in interface RiskClientInterface

setDice

public void setDice(int[] die)
Supply the current state of the dice to those it interests.

Robot authurs should not normally call this method.

Specified by:
setDice in interface RiskClientInterface

setCards

public void setCards(Card[] cards)
Tell the client the cards that the player has. Clients can connect to the server with two connections if there are two players at that client.

Robot authurs should not normally call this method.

Specified by:
setCards in interface RiskClientInterface