Creating a Prisoner Strategy - AdamVD/Prisoners_Dilemma_Simulator GitHub Wiki
The goal of this simulator is to make the creation of new strategies as easy as possible. To achieve this, new prisoner objects inherit from a superclass named Prisoner. The code for this superclass can be found in src/Strategies/Prisoner.java. To create your own prisoner algorithm, make a new public class with a name of your choice within the src/Strategies package, and extend the Prisoner superclass.
package Strategies;
public class ClassName extends Prisoner {
...
}
return EXPLOIT; or return COMPLY; to avoid confusion.
From the AlwaysComply strategy:
public class AlwaysComply extends Prisoner {
@Override
public boolean choose() {
return COMPLY;
}
}
From the MultipleConstructor example:
public class MultipleConstructor extends Prisoner {
private boolean choice;
// default
public MultipleConstructor() {
// send values to the other constructor (may be randomized).
this(true);
}
// parametrized
public MultipleConstructor(boolean choice) {
this.choice = choice;
}
@Override
public Prisoner evolve() {
return new MultipleConstructor(false);
}
}
Optionally, if you would like your algorithm to introduce actual evolution, you might choose to initialize your new object using randomly generated parameters that will change the behavior of your prisoner.
This method notifies the prisoner of what the other prisoner's choice was in the previous round. This method is called upon the completion of each round.From the TitForTat strategy:
public class TitForTat extends Prisoner {
private boolean prevOppMove = COMPLY;
@override
public void notifyOpponentChoice(boolean choice) {
prevOppMove = choice;
}
}
public class TitForTat extends Prisoner {
private boolean prevOppMove = COMPLY;
@Override
public void notifyGameOver() {
prevOppMove = COMPLY;
}
}