-
Notifications
You must be signed in to change notification settings - Fork 0
/
StrategyTester.java
82 lines (75 loc) · 2.76 KB
/
StrategyTester.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Write a description of class StrategyTester here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class StrategyTester
{
private static Player[] players = {
new JeremyMack(),
new FranCap(),
new SimonHedges(),
new JackMcNeil(),
new NatLevyWest(),
new HenryCost(),
new MilesBergner(),
new Dummy(0),
};
private final int howManyGames;
private int totalScore = 0;
private int totalRounds = 0;
private int totalWinningScore = 0;
public static void main(String[] args) {
int numGames = 1000;
try {
numGames = new Integer(args[0]);
} catch(RuntimeException re) {
System.err.println("numGames defaulting to "+numGames);
}
StrategyTester test = new StrategyTester(numGames);
test.run();
}
public StrategyTester(int numGames) {
howManyGames = numGames;
}
public void run() {
System.err.println();
for(int i = 0; i < howManyGames; i++) {
Game game = new Game(players);
System.err.print(">");
while(true) {
System.err.print(".");
game.playRound();
Player winner = game.getWinner();
if(winner != null) {
winner.incrementWinCount();
break;
}
}
System.err.println("<");
totalScore += game.getTotalScore();
totalRounds += game.getNumRounds();
totalWinningScore += game.getLeadScore();
resetPlayers();
}
System.err.println("Total Games Played: " + howManyGames);
System.err.println("Average Game Length: " + (float)totalRounds/(float)howManyGames);
System.err.println("Average Total Score: " + (float)totalScore/(float)howManyGames);
System.err.println("Average Player Score: " + ((float)totalScore/(float)players.length)/(float)howManyGames);
System.err.println("Average Winner Score: " + (float)totalWinningScore/(float)howManyGames);
System.err.println();
System.err.println();
for(Player p : players) {
System.err.println(p + ": " + p.getWinCount() + " ("+(float)p.getWinCount()*100F/(float)howManyGames+"%)");
System.err.println(" YES: "+ p.getYes()+ "/" + totalRounds + " (" + (float)p.getYes()*100F/(float)totalRounds + "%)");
System.err.println(" NO: " + p.getNo() + "/" + totalRounds + " (" + (float)p.getNo()*100F/(float)totalRounds + "%)");
System.err.println();
}
}
private void resetPlayers() {
for(Player p : players) {
p.reset();
}
}
}