net.sourceforge.cilib.games.game
Class Game<E extends GameState>

java.lang.Object
  extended by net.sourceforge.cilib.games.game.Game<E>
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
GridGame, PredatorPreyGame, Tetris

public abstract class Game<E extends GameState>
extends Object
implements Cloneable

Author:
leo A general framework for a Game, turn based or real time. A game is played by Agents until it is terminated. A game has four possible outcomes from the perspective of a player: Win, lose, draw or receive a score. A fitness is assigned to each game playing Agent by the GameScoringStrategy.
See Also:
Serialized Form

Field Summary
protected  List<AgentMeasure> agentMeasurement
           
protected  int currentPlayer
           
protected  List<Agent> players
           
 
Constructor Summary
Game()
          Default constructor
Game(Game<E> other)
          Copy constructor
Game(Game<E> other, E newState)
          Copy constructor, copy the given Game object but use the given GameState obect.
 
Method Summary
 void addMeasurement(AgentMeasure measure)
          Add a new AgentMeasure to the list of measurements
 void assignPlayerScore(int playerID, Fitness score)
          Assign a score to a player
 void clearMeasurementData()
          Clear all the measured data while keeping all the AgentMeasure
 void clearMeasurements()
          Remove all AgentMeasure objects in the list
abstract  void display()
          Print the game to the console, is useful during testing.
abstract  boolean gameOver()
          check if the game should terminate
 List<AgentMeasure> getAgentMeasurements()
           
abstract  Game<E> getClone()
          Create a cloned copy of the current object and return it.
abstract  Game<E> getClone(E newState)
          Get a clone with the given GameState This method should typically be used by the StateTraversalStrategy and Agent with regards to decision making when playing the game.
 int getCurrentIteration()
           
 int getCurrentPlayer()
           
 E getCurrentState()
          returns the current state of the game, this isnt always the same as the decision state
 E getDecisionState()
          Returns the state of the game that the agent needs to make a decision.
 DomainRegistry getDomainForPlayer(int playerID)
          This method is used to get the specific domain for an agents solution vector
abstract  AbstractGameResult getGameResult()
          Get the result of the game (Win/Lose/Draw)
 int getNextPlayerID(int playerID)
          This method returns the playerID who would play directly after the playerID that is given to the method.
 Agent getPlayer(int playerID)
           
 int getPlayerCount()
          get the number of players
 int[] getPlayerIDList(int startPlayerID)
          return a list of all the playerID's, in the order that they would play starting with startPlayerID
 Fitness getPlayerScore(int playerID)
          return the fitness of the agent
 GameScoringStrategy getScoringStrategy()
           
 void initializeAgent(int playerID, Type agentData)
          This method initializes an agent with entity data.
abstract  void initializeGame()
          perform any game specific initialization
 void playGame()
           
 void playGame(boolean display)
          initialize and play the game until the end conditions are met while recording any playing information.
 void setAgent(Agent player)
          Add a new agent
 void setAgent(Agent player, int playerID)
          Add an agent with a specified playerID, if it already exists, replace it
 void setCurrentGameState(E state)
          Set the current state of the game
 void setCurrentPlayer(int currentPlayer)
           
 void setEntityScore(int playerID, EntityScore score)
          Store the result and fitness for a specific player in the entityscore object
 void setScoringStrategy(GameScoringStrategy scoringStrategy)
          Set the GameScoringStrategy for this game.
 void setSeedingStrategy(GameSeedingStrategy seedStrategy)
          Set the seeding strategy of the game, this will determine how many and when unique games are played.
 void setStartPlayer(int startPlayer)
          Re-arrange the players in the player vector to put a new agent first
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

players

protected List<Agent> players

currentPlayer

protected int currentPlayer

agentMeasurement

protected List<AgentMeasure> agentMeasurement
Constructor Detail

Game

public Game()
Default constructor


Game

public Game(Game<E> other)
Copy constructor

Parameters:
other - the other game object

Game

public Game(Game<E> other,
            E newState)
Copy constructor, copy the given Game object but use the given GameState obect.

Parameters:
other - the other game object
newState - the new state to use as this Game's GameState
Method Detail

getDecisionState

public E getDecisionState()
Returns the state of the game that the agent needs to make a decision. This implies that the state the agent receives isn't necceseraly the entire game state as it is at that point in time. This method can be overwritten to introduce noise or imperfect player information.

Returns:
default returns the current game state, override to return other state

getCurrentState

public E getCurrentState()
returns the current state of the game, this isnt always the same as the decision state

Returns:
the current state of the game

setCurrentGameState

public void setCurrentGameState(E state)
Set the current state of the game

Parameters:
state - the new game state

setAgent

public void setAgent(Agent player)
Add a new agent

Parameters:
player - the Agent to add

setAgent

public void setAgent(Agent player,
                     int playerID)
Add an agent with a specified playerID, if it already exists, replace it

Parameters:
player - the new Agent
playerID - the playerID for the agent

getDomainForPlayer

public DomainRegistry getDomainForPlayer(int playerID)
This method is used to get the specific domain for an agents solution vector

Parameters:
playerID - the id of the player
Returns:
the domainregistry of that players solution

assignPlayerScore

public void assignPlayerScore(int playerID,
                              Fitness score)
Assign a score to a player

Parameters:
playerID - the id of the player
score - the fitness

getPlayerScore

public Fitness getPlayerScore(int playerID)
return the fitness of the agent

Parameters:
playerID - the id of the player
Returns:
the relevant fitness

getPlayerCount

public int getPlayerCount()
get the number of players

Returns:
number of players

initializeAgent

public void initializeAgent(int playerID,
                            Type agentData)
This method initializes an agent with entity data.

Parameters:
playerID - the id of the player
agentData - the entity data that the agent uses to make decisions

setStartPlayer

public void setStartPlayer(int startPlayer)
Re-arrange the players in the player vector to put a new agent first

Parameters:
startPlayer - the id of the lpayer to go first

getPlayer

public Agent getPlayer(int playerID)

getNextPlayerID

public int getNextPlayerID(int playerID)
This method returns the playerID who would play directly after the playerID that is given to the method. This is not necceseraly in numeric order, since players take turns going first

Parameters:
playerID - the playerID that preceeds the playerID to be returned
Returns:
the player who's turn it is next

getPlayerIDList

public int[] getPlayerIDList(int startPlayerID)
return a list of all the playerID's, in the order that they would play starting with startPlayerID

Parameters:
startPlayerID - the ID of the starting player
Returns:
the list of playerID's in the order that they would play

clearMeasurements

public void clearMeasurements()
Remove all AgentMeasure objects in the list


clearMeasurementData

public void clearMeasurementData()
Clear all the measured data while keeping all the AgentMeasure


getAgentMeasurements

public List<AgentMeasure> getAgentMeasurements()

addMeasurement

public void addMeasurement(AgentMeasure measure)
Add a new AgentMeasure to the list of measurements

Parameters:
measure - the new measurement

playGame

public void playGame(boolean display)
initialize and play the game until the end conditions are met while recording any playing information. The Agents fitness values are assigned in this method


playGame

public void playGame()

setEntityScore

public void setEntityScore(int playerID,
                           EntityScore score)
Store the result and fitness for a specific player in the entityscore object

Parameters:
playerID - the id of the agent
score - the entityscore object that is manipulated

initializeGame

public abstract void initializeGame()
perform any game specific initialization


gameOver

public abstract boolean gameOver()
check if the game should terminate

Returns:
the endgame flag

getGameResult

public abstract AbstractGameResult getGameResult()
Get the result of the game (Win/Lose/Draw)

Returns:
the relevant AbstractGameResult object

getClone

public abstract Game<E> getClone()
Create a cloned copy of the current object and return it. In general the created copy will be a deep copy of the provided instance. As a result this operation an be quite expensive if used incorrectly.

Specified by:
getClone in interface Cloneable
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()

getClone

public abstract Game<E> getClone(E newState)
Get a clone with the given GameState This method should typically be used by the StateTraversalStrategy and Agent with regards to decision making when playing the game. Since this process includes making alot of copies of the game a seperate, faster, method is neccesary that does not waste time by making unneccesary copies of the game state and player logic.

Parameters:
newState - the new sate to use
Returns:
the copy

display

public abstract void display()
Print the game to the console, is useful during testing.


setScoringStrategy

public void setScoringStrategy(GameScoringStrategy scoringStrategy)
Set the GameScoringStrategy for this game. The scoring strategy might require certain AgentMeasures and therefore clears any existing measures before adding its own.

Parameters:
scoringStrategy - the scoring strategy

getCurrentIteration

public int getCurrentIteration()

getCurrentPlayer

public int getCurrentPlayer()

setCurrentPlayer

public void setCurrentPlayer(int currentPlayer)

getScoringStrategy

public GameScoringStrategy getScoringStrategy()

setSeedingStrategy

public void setSeedingStrategy(GameSeedingStrategy seedStrategy)
Set the seeding strategy of the game, this will determine how many and when unique games are played. The GameSeedingStrategy is in the GameState

Parameters:
seedStrategy -


Copyright © 2009 CIRG. All Rights Reserved.