ipdlx
Class Game

java.lang.Object
  extended by ipdlx.Game
All Implemented Interfaces:
PDValues
Direct Known Subclasses:
MultiPlayerGame, StandardGame

public abstract class Game
extends java.lang.Object
implements PDValues

Base class for all games

Author:
Jan Humble

Field Summary
protected  boolean broadcastResult
           
protected  boolean broadcastRoundResults
           
protected  java.util.Vector gameListeners
           
protected  GameMatrix gameMatrix
          payoff matrix of the game
protected  GameResult gameResult
          info about the result of this game
protected  long moveTimeLimit
           
protected  java.util.Vector players
          all players
protected  float probabilityOfMistake
          The percentage of mistakes the strategy makes.
protected  float stDev
          how many rounds (iterations)
 
Fields inherited from interface ipdlx.PDValues
COOPERATE, DEFAULT_MISTAKE_LEVEL, DEFAULT_PUNISHMENT, DEFAULT_REWARD, DEFAULT_SUCKER, DEFAULT_TEMPTATION, DEFECT, EXIT, moves, PLAYER_A, PLAYER_B
 
Constructor Summary
Game(Game game)
          Constructs a new game with the same game parameters as the given one.
Game(int nrOfRounds, GameMatrix gameMatrix)
          constructor
Game(int nrOfRounds, GameMatrix gameMatrix, float noise)
          constructor
 
Method Summary
 void addGameListener(GameListener gameListener)
           
 void addPlayer(Player player)
          Adds a player to this game instance.
 void addPlayers(java.util.Vector players)
          Adds an array of players to this game instance.
protected  void broadcastGameStart(Game game)
           
protected  void broadcastResults(GameResult result)
           
protected  void broadcastRoundResults(GameRoundResult result)
           
 double filterMove(double move)
          Returns a possibly modified move from another.
 boolean getBroadcastResult()
           
 boolean getBroadcastRoundResults()
           
 java.util.Vector getGameListeners()
           
 GameMatrix getGameMatrix()
          Returns the game matrix.
 float getNrRoundsStDev()
          Returns the standard deviation set for the number of rounds to play.
 int getNumberOfRounds()
          Returns the currently set number of rounds.
 int getNumberOfRounds(boolean useStDev)
          Returns the current number of rounds.
 int getNumberOfRoundsStDev()
          Returns a deviation of the current number of rounds and current standard deviation setting.
 float getProbabilityOfMistake()
          Returns the probability of mistake setting for all moves in the current game state.
protected  double getStrategyMove(Strategy strategy)
          Returns the move from a given strategy.
protected  double getStrategyMove(Strategy strategy, boolean checkTimeLimit)
          Returns the move from a given strategy.
 GameResult play()
          plays the game and return the results of it
 void removeGameListener(GameListener gameListener)
           
 void setBroadcastResult(boolean broadcast)
           
 void setBroadcastRoundResults(boolean broadcast)
           
 void setGameMatrix(GameMatrix gameMatrix)
          Sets the game matrix.
 void setMoveTimeLimit(long timeLimitMillis)
          Sets the time limit for a player move at each iteration.
 void setNrRoundsStDev(float stDev)
          Sets the standard deviation for the number of rounds to play.
 void setNumberOfRounds(int nrOfRounds)
          Sets the number of rounds to play
 void setPlayers(java.util.Vector players)
          Sets the players to play this game.
 void setProbabilityOfMistake(float probabilityOfMistake)
           
 java.lang.String toString()
          Returns a small description of the current game parameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

moveTimeLimit

protected long moveTimeLimit

stDev

protected float stDev
how many rounds (iterations)


players

protected java.util.Vector players
all players


gameResult

protected GameResult gameResult
info about the result of this game


gameMatrix

protected GameMatrix gameMatrix
payoff matrix of the game


probabilityOfMistake

protected float probabilityOfMistake
The percentage of mistakes the strategy makes. Mistake is a situation like this for example: strategy wants to play COOPERATE but for some unknown reasons it plays DEFECT.


gameListeners

protected java.util.Vector gameListeners

broadcastResult

protected boolean broadcastResult

broadcastRoundResults

protected boolean broadcastRoundResults
Constructor Detail

Game

public Game(Game game)
Constructs a new game with the same game parameters as the given one. Also, all game listeners are transferred.

Parameters:
game - a template game to copy parameters from

Game

public Game(int nrOfRounds,
            GameMatrix gameMatrix)
constructor

Parameters:
nrOfRounds - number of iterations
gameMatrix - matrix of the prisoner's dilemma game

Game

public Game(int nrOfRounds,
            GameMatrix gameMatrix,
            float noise)
constructor

Parameters:
nrOfRounds - number of iterations
gameMatrix - matrix of the prisoner's dilemma game
noise - probability of mistake
Method Detail

toString

public java.lang.String toString()
Returns a small description of the current game parameters

Overrides:
toString in class java.lang.Object

setNumberOfRounds

public final void setNumberOfRounds(int nrOfRounds)
Sets the number of rounds to play

Parameters:
nrOfRounds - number of iterations to play

getNumberOfRoundsStDev

public final int getNumberOfRoundsStDev()
Returns a deviation of the current number of rounds and current standard deviation setting.


getNumberOfRounds

public final int getNumberOfRounds(boolean useStDev)
Returns the current number of rounds.

Parameters:
useStDev - if true returns a deviation from the currently set number of rounds to play.

getNumberOfRounds

public final int getNumberOfRounds()
Returns the currently set number of rounds.


getGameMatrix

public final GameMatrix getGameMatrix()
Returns the game matrix.


addPlayer

public void addPlayer(Player player)
Adds a player to this game instance.

Parameters:
player - the player to add.

addPlayers

public void addPlayers(java.util.Vector players)
Adds an array of players to this game instance.

Parameters:
players - the players to add.

setNrRoundsStDev

public final void setNrRoundsStDev(float stDev)
Sets the standard deviation for the number of rounds to play.

Parameters:
stDev - the standard deviation

getNrRoundsStDev

public final float getNrRoundsStDev()
Returns the standard deviation set for the number of rounds to play.


setPlayers

public void setPlayers(java.util.Vector players)
Sets the players to play this game.

Parameters:
players - the players

setGameMatrix

public void setGameMatrix(GameMatrix gameMatrix)
Sets the game matrix.

Parameters:
gameMatrix - the game matrix.

setMoveTimeLimit

public void setMoveTimeLimit(long timeLimitMillis)
Sets the time limit for a player move at each iteration.

Parameters:
timeLimitMillis - the time limit in milliseconds.

getStrategyMove

protected double getStrategyMove(Strategy strategy)
Returns the move from a given strategy. This is by default used to check time limit considerations and log moves.

Parameters:
strategy - the strategy to acquire the move from.

getStrategyMove

protected double getStrategyMove(Strategy strategy,
                                 boolean checkTimeLimit)
Returns the move from a given strategy. This is by default used to check time limit considerations and log moves.

Parameters:
strategy - the strategy to acquire the move from.
checkTimeLimit - if true checks whether to check the play time limit constraints imposed.

filterMove

public double filterMove(double move)
Returns a possibly modified move from another. Mainly used for introducing noise in the move signal.

Parameters:
move - the original move to filter.

getProbabilityOfMistake

public final float getProbabilityOfMistake()
Returns the probability of mistake setting for all moves in the current game state.


setProbabilityOfMistake

public final void setProbabilityOfMistake(float probabilityOfMistake)

removeGameListener

public final void removeGameListener(GameListener gameListener)

getGameListeners

public final java.util.Vector getGameListeners()

setBroadcastResult

public void setBroadcastResult(boolean broadcast)

setBroadcastRoundResults

public void setBroadcastRoundResults(boolean broadcast)

getBroadcastResult

public boolean getBroadcastResult()

getBroadcastRoundResults

public boolean getBroadcastRoundResults()

addGameListener

public final void addGameListener(GameListener gameListener)

broadcastResults

protected final void broadcastResults(GameResult result)

broadcastRoundResults

protected final void broadcastRoundResults(GameRoundResult result)

broadcastGameStart

protected final void broadcastGameStart(Game game)

play

public GameResult play()
plays the game and return the results of it

Returns:
result of the game