-
Notifications
You must be signed in to change notification settings - Fork 0
/
TeamDoubleAgent.java
81 lines (66 loc) · 2.78 KB
/
TeamDoubleAgent.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
public class TeamDoubleAgent extends Player {
// This will allow us use Handshaking functionality when we play an Alliance handshaker.
private Handshaker shaker;
public byte[] bestMoveBytesRealist, scoreWhiteBytesRealist, scoreBlackBytesRealist;
public byte[] bestMoveBytesDoubleAgent, scoreWhiteBytesDoubleAgent, scoreBlackBytesDoubleAgent;
public TeamDoubleAgent(int maxNumMoves) {
TeamRational teamRationalRealist = TeamRational.createRealist(maxNumMoves);
TeamRational teamDoubleAgent = new TeamRational(maxNumMoves, 2, 0, 3, 1, 2, 0, 3, 1);
/*TeamDoubleAgent has the following beliefs as P1:
* P1\P2 | W | L |
* -------------------
* W | 2,2 | 0,0 |
* -------------------
* L | 3,3 | 1,1 |
* -------------------
* Or in other words, he is rooting for his opponent.*/
//Data needed to play as a Realist:
bestMoveBytesRealist = teamRationalRealist.bestMoveBytes;
scoreWhiteBytesRealist = teamRationalRealist.scoreWhiteBytes;
scoreBlackBytesRealist = teamRationalRealist.scoreBlackBytes;
//Data needed to play for the opponent's payoff:
bestMoveBytesDoubleAgent = teamDoubleAgent.bestMoveBytes;
scoreWhiteBytesDoubleAgent = teamDoubleAgent.scoreWhiteBytes;
scoreBlackBytesDoubleAgent = teamDoubleAgent.scoreBlackBytes;
shaker = Handshaker.createHandshakeOfferer();
}
public void prepareForSeries() {
shaker.handshakePrepareForSeries();
}
public void prepareForMatch() {
shaker.handshakePrepareForMatch(toBoardPosition());
}
public void receiveMatchOutcome(int matchOutcome) {
shaker.handshakeReceiveMatchOutcome(matchOutcome, toBoardPosition());
}
public MoveDescription chooseMove() {
BoardPosition currentBoardPosition = toBoardPosition();
shaker.updateTheirMove(currentBoardPosition);
MoveDescription myMove;
if (shaker.shouldSendHandshakeMove()) {
myMove=Handshaker.getHandshakeMove(currentBoardPosition);
} else {
myMove = internalChooseMove();
}
shaker.receiveMyMove(myMove);
return myMove;
}
private MoveDescription internalChooseMove() {
BoardPosition currentBoardPosition = toBoardPosition();
MoveDescription move;
if (shaker.handshakeHasFailed()) {
TeamRational.Node nodeRealist = new TeamRational.Node(
bestMoveBytesRealist[currentBoardPosition.toInt()],
scoreWhiteBytesRealist[currentBoardPosition.toInt()],
scoreBlackBytesRealist[currentBoardPosition.toInt()]);
move=nodeRealist.bestMove;
} else {
TeamRational.Node nodeDoubleAgent = new TeamRational.Node(
bestMoveBytesDoubleAgent[currentBoardPosition.toInt()],
scoreWhiteBytesDoubleAgent[currentBoardPosition.toInt()],
scoreBlackBytesDoubleAgent[currentBoardPosition.toInt()]);
move=nodeDoubleAgent.bestMove;
}
return move;
}
}