-
Notifications
You must be signed in to change notification settings - Fork 0
/
IteratedPD.java
64 lines (52 loc) · 1.75 KB
/
IteratedPD.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Class containing iterated Prisoner's Dilemma (IPD).
* @author 081028AW
*/
public class IteratedPD extends Object
{
/**
* Iterated Prisoner's Dilemma.
*/
int maxSteps;
PrisonersDilemma pd;
Strategy p1, p2;
int p1Score;
int p2Score;
public IteratedPD(Strategy player1, Strategy player2)
{
this.p1 = player1;
this.p2 = player2;
pd = new PrisonersDilemma(p1, p2);
p1Score = 0;
p2Score = 0;
// System.out.printf(" Player 1 is %s, Player 2 is %s\n",
// p1.getName(), p2.getName() );
} /* IteratedPD */
public void runSteps(int maxSteps)
{
int i;
for (i=0; i<maxSteps; i++)
{
pd.playPD();
p1Score += pd.getPlayer1Payoff();
p2Score += pd.getPlayer2Payoff();
// System.out.printf(
// " t %3d P1 move %d payoff %d (%3d) P2 move %d payoff %d (%3d)\n",
// i, pd.getPlayer1Move(), pd.getPlayer1Payoff(), p1Score,
// pd.getPlayer2Move(), pd.getPlayer2Payoff(), p2Score);
/*
System.out.printf(" Iteration %d\n", i);
System.out.printf(" Player1 move %d, Player2 move %d\n",
pd.getPlayer1Move(), pd.getPlayer2Move());
System.out.printf(" Player1 payoff %d, Player2 payoff %d\n",
pd.getPlayer1Payoff(), pd.getPlayer2Payoff());
System.out.printf(" Player1 sum %d, Player2 sum %d\n",
p1Score, p2Score);
System.out.printf(" Player1 OLM %d, Player2 OLM %d\n",
p1.getOpponentLastMove(), p2.getOpponentLastMove() );
*/
} /* for i */
}
public int player1Score() {return p1Score;}
public int player2Score() {return p2Score;}
} /* class IteratedPD */