All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----com.monpetitcoin.java.PrisonerGame.Prisoner
The class implements the Pawn interface, so that the Prisoners can fit on a GameBoard. The GameBoard knows how it wants the Prisoner to draw itself. The Prisoner chooses dynamically a subclass of ShapeDrawer to fit the request of the board.
= 1 for honest behavior= 0 for cheating
private static final double DEFAULT_INCENTIVE
private static final double DEFAULT_THRESHOLD
private static final int NO_STATE
private static int idCounter
private int state
= 1 for honest behavior= 0 for cheating
private int oldState
private int id
private double gain
private double incentive
private double threshold
private com.monpetitcoin.java.PrisonerGame.GameBoard board
private com.monpetitcoin.java.PrisonerGame.PrisonerGame game
private com.monpetitcoin.java.PrisonerGame.Prisoner neighbors[]
private int maxNeighbors
private prisoner.shapes.ShapeDrawer renderer
public Prisoner(com.monpetitcoin.java.PrisonerGame.PrisonerGame game,
com.monpetitcoin.java.PrisonerGame.GameBoard board)
public Prisoner(com.monpetitcoin.java.PrisonerGame.PrisonerGame game,
com.monpetitcoin.java.PrisonerGame.GameBoard board,
double incentive)
public Prisoner(com.monpetitcoin.java.PrisonerGame.PrisonerGame game,
com.monpetitcoin.java.PrisonerGame.GameBoard board,
double incentive,
double threshold)
public Prisoner(com.monpetitcoin.java.PrisonerGame.PrisonerGame game,
com.monpetitcoin.java.PrisonerGame.GameBoard board,
double incentive,
double threshold,
int state)
public Prisoner(com.monpetitcoin.java.PrisonerGame.PrisonerGame game,
com.monpetitcoin.java.PrisonerGame.GameBoard board,
double incentive,
double threshold,
int state,
double gain)
=1 honest, =0 dishonest)
public int getState()
public int getOldState()
public double getGain()
public double getIncentive()
public double getThreshold()
public void draw(java.awt.Graphics g,
int x,
int y,
int width,
int height)
public int getID()
public void setNeighbors(com.monpetitcoin.java.PrisonerGame.Pawn theNeighbors[])
public void calculateGain()
neighbors array and calculates its gain
depending on its and its neighbor's behaviors.
At this point, it is important to preserve the state of the Prisoner, by storing it in the
oldState member variable. Indeed, the game first asks all Prisoners to calculate
their gain. Then each Prisoner in turn must decide whether to change its behavior or not.
This decision is based on the neighbors' gains and behaviors. But since Prisoners are called
one after the other, when Prisoner n must draw its conclusion, Prisoners 1 to n-1 have already
drawn theirs and changed their state. Thus the comparison must be made with the previous
game turn's state.
public void drawConclusion()
calculateGain()).
The actual algorithm for decision calculates the average gain among all the honest neighbors and all the dishonest neighbors. A decision to change is then taken on two conditions:
This means that even if the opposing party has gained more than itself, the Prisoner will not change its behavior if its party has gained even more than the opposing party. In a sense, the Prisoner is reassured in its behavior by seeing its party come on top.
All Packages Class Hierarchy This Package Previous Next Index