-
Notifications
You must be signed in to change notification settings - Fork 0
/
BestBot.java
63 lines (46 loc) · 1.59 KB
/
BestBot.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
public class BestBot implements RoShamBot {
private ArrayList<Action> opponentsActions = new ArrayList<Action>();
private Action opponentLastMove;
private int numRocks = 0;
private int numPaper = 0;
private int numScissors = 0;
private int totalMoves = 0;
private int tenMoves = 0;
public Action getNextMove(Action lastOpponentMove) {
opponentsActions.add(lastOpponentMove);
totalMoves++;
tenMoves++;
if (lastOpponentMove == Action.ROCK)
numRocks++;
if (lastOpponentMove == Action.PAPER)
numPaper++;
if (lastOpponentMove == Action.SCISSORS)
numScissors++;
// if total moves is less than 10, do nash equilibria
if (totalMoves < 10) {
double coinFlip = Math.random();
if (coinFlip <= 1.0/3.0)
return Action.ROCK;
else if (coinFlip <= 2.0/3.0)
return Action.PAPER;
else
return Action.SCISSORS;
}
// else, calculate
else {
int probRock = numRocks/totalMoves;
int probPaper = numPaper/totalMoves;
int probScissors = numScissors/totalMoves;
double coinFlip = Math.random();
/* COMMENTS: Calculating the probabilities of their moves above. Would we want to return the opposite
* move with those probabilities? And how do we return these moves based on the coin flip?
*/
if (coinFlip <= probRock)
return Action.ROCK;
else if (coinFlip <= 2.0/3.0)
return Action.PAPER;
else
return Action.SCISSORS;
}
}
}