Evolving Strategies for the Prisoner's Dilemma

ie.errity.pd
Class Prisoner

java.lang.Object
  |
  +--ie.errity.pd.Prisoner
All Implemented Interfaces:
java.lang.Cloneable

public class Prisoner
extends java.lang.Object
implements java.lang.Cloneable

This class represents a Prisoner with a strategy to play the Prisoner's Dilemma Game.


Constructor Summary
Prisoner(java.util.BitSet strat)
          Create a new Prisoner to play the prisoners dilemma (nameless)
Prisoner(java.lang.String s)
          Create a Predefined Prisoner
Prisoner(java.lang.String na, java.util.BitSet strat)
          Create a new Prisoner to play the prisoners dilemma
 
Method Summary
 java.lang.Object clone()
          Copy the current Prisoner
 java.awt.Color getColor()
          Return which color to render the prisoner (based on it's strategy)
In order to differentiate between different 'types' of player this method sets color according to how often the Prisoner will cooperate and how often they defect Orange/Red signifies defecting ('nasty') strategies Yellow/Green signifies cooperating ('nice') strategies Blue indicates balanced strategies
 java.lang.String getName()
          Returns the Prisoner's name
static Prisoner getRand()
          Returns a Prisoner with a random strategy
static Prisoner[] getRand(int num_players)
          Returns an array of Prisoners with random strategies
static Prisoner[][] getRand(int num_players, int num_players2)
          Returns a 2D array of Prisoners with random strategies
 int getScore()
          Returns the Prisoner's current score
 java.util.BitSet getStrat()
          Returns the Prisoner's strategy
 int getType()
          Return the strategy 'type' of the prisoner 0,1,2 signifies defecting ('nasty') strategies 5,6,7 signifies cooperating ('nice') strategies 3,4 indicates balanced strategies
 boolean play(int iteration, java.util.BitSet History)
          Gets the Prisoner's next game move
 void setScore(int s)
          Set the Prisoner's current score
 java.lang.String toString()
          Convert the Prisoner's strategy to a string of C's and D's
 int updateScore(int s)
          Adds value to the Prisoner's current score
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Prisoner

public Prisoner(java.lang.String na,
                java.util.BitSet strat)
Create a new Prisoner to play the prisoners dilemma

Parameters:
na - the Prisoner's name
strat - a BitSet representing the player's strategy

Prisoner

public Prisoner(java.util.BitSet strat)
Create a new Prisoner to play the prisoners dilemma (nameless)

Parameters:
strat - a BitSet representing the player's strategy

Prisoner

public Prisoner(java.lang.String s)
Create a Predefined Prisoner

Parameters:
s - the name of a predefined prisoner
Valid values include:
Method Detail

updateScore

public int updateScore(int s)
Adds value to the Prisoner's current score

Parameters:
s - the value to be added
Returns:
the new score

getScore

public int getScore()
Returns the Prisoner's current score

Returns:
the Prisoner's current score

setScore

public void setScore(int s)
Set the Prisoner's current score

Parameters:
s - the new score

getName

public java.lang.String getName()
Returns the Prisoner's name

Returns:
the Prisoner's name

getStrat

public java.util.BitSet getStrat()
Returns the Prisoner's strategy

Returns:
a BitSet representing the strategy

play

public boolean play(int iteration,
                    java.util.BitSet History)
Gets the Prisoner's next game move

Parameters:
iteration - current iteration number
History - game history represented as a BitSet
History should represent previous moves as C=1 and D=0
This players move should be followed by the opponents move, one such pair for each previous iteration of PD
Returns:
true or false {C or D}

clone

public java.lang.Object clone()
Copy the current Prisoner

Overrides:
clone in class java.lang.Object
Returns:
a copy of the current Prisoner

toString

public java.lang.String toString()
Convert the Prisoner's strategy to a string of C's and D's

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the Prisoner's strategy

getRand

public static Prisoner getRand()
Returns a Prisoner with a random strategy

Returns:
a Prisoner with a random strategy

getRand

public static Prisoner[] getRand(int num_players)
Returns an array of Prisoners with random strategies

Parameters:
num_players - the number of Prisoners to create
Returns:
an array of Prisoners with random strategies

getRand

public static Prisoner[][] getRand(int num_players,
                                   int num_players2)
Returns a 2D array of Prisoners with random strategies

Parameters:
num_players - the length of array to return
num_players2 - the depth of array to return
Returns:
a 2D array of Prisoners with random strategies

getColor

public java.awt.Color getColor()
Return which color to render the prisoner (based on it's strategy)
In order to differentiate between different 'types' of player this method sets color according to how often the Prisoner will cooperate and how often they defect

getType

public int getType()
Return the strategy 'type' of the prisoner

Andrew Errity [99086921]