com.bolinfest.prisonerbot
Class SimpleIterativeGame

java.lang.Object
  extended by com.bolinfest.prisonerbot.SimpleIterativeGame
All Implemented Interfaces:
UnmodifiableGame

public class SimpleIterativeGame
extends Object
implements UnmodifiableGame

SimpleIterativeGame is an abstract data type containing the details of an iterated Prisoner's Dilemma game.

Author:
mbolin

Constructor Summary
SimpleIterativeGame(String player1Name, String player2Name, PayoffMatrix matrix)
           
 
Method Summary
protected  void calculateRounds()
          override this method to decide how the number of rounds will be determined
 boolean choicesEntered()
           
 Iterator getIterations()
           
 Iteration getLastIteration()
           
 String getLeader()
           
 int getNumberOfIterations()
           
 int getNumRounds()
           
 int[] getNumRoundsProposed()
           
 PayoffMatrix getPayoffMatrix()
           
 String getPlayer1Name()
           
 String getPlayer2Name()
           
 int[] getScore()
           
 boolean isTieGame()
           
 boolean recordChoice(String playerName, Choice c)
          Record the choice made by the player
 void recordChoices()
          resets the choices and updates the score so game can proceed to next round
 boolean roundsEntered()
          Indicates both players have suggested a valid number of rounds to play
 void setNumRoundsProposed(String playerName, int n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleIterativeGame

public SimpleIterativeGame(String player1Name,
                           String player2Name,
                           PayoffMatrix matrix)
Parameters:
player1Name -
player2Name -
matrix -
Method Detail

getPayoffMatrix

public PayoffMatrix getPayoffMatrix()
Specified by:
getPayoffMatrix in interface UnmodifiableGame
Returns:
Returns the payoffMatrix.

setNumRoundsProposed

public void setNumRoundsProposed(String playerName,
                                 int n)

recordChoice

public boolean recordChoice(String playerName,
                            Choice c)
Record the choice made by the player

Returns:
true if the choice was updated successfully, false if this player already selected his choice for this round

choicesEntered

public boolean choicesEntered()
Returns:
true if both players have entered their choices

recordChoices

public void recordChoices()
resets the choices and updates the score so game can proceed to next round


calculateRounds

protected void calculateRounds()
override this method to decide how the number of rounds will be determined


getNumRounds

public int getNumRounds()

roundsEntered

public boolean roundsEntered()
Indicates both players have suggested a valid number of rounds to play


getNumberOfIterations

public int getNumberOfIterations()
Specified by:
getNumberOfIterations in interface UnmodifiableGame
Returns:
the number of iterations played in this game

getScore

public int[] getScore()
Specified by:
getScore in interface UnmodifiableGame
Returns:
an array of size 2 where the first element is player1's score and the second element is player2's score

getLeader

public String getLeader()
Specified by:
getLeader in interface UnmodifiableGame
Returns:
the name of the player with the higher score

isTieGame

public boolean isTieGame()

getIterations

public Iterator getIterations()
Specified by:
getIterations in interface UnmodifiableGame
Returns:
an Iterator (whose remove() method is unsupported) over the iterations of the game

getPlayer1Name

public String getPlayer1Name()
Specified by:
getPlayer1Name in interface UnmodifiableGame
Returns:
Returns the player1Name.

getPlayer2Name

public String getPlayer2Name()
Specified by:
getPlayer2Name in interface UnmodifiableGame
Returns:
Returns the player2Name.

getLastIteration

public Iteration getLastIteration()

getNumRoundsProposed

public int[] getNumRoundsProposed()
Specified by:
getNumRoundsProposed in interface UnmodifiableGame