-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeamHandshaker.java
64 lines (50 loc) · 2.15 KB
/
TeamHandshaker.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
public class TeamHandshaker extends Player {
// This will allow us use Handshaking functionality when we play TeamDoubleAgent.
// ADD FOLLOWING LINE TO SUPPORT HANDSHAKE
private Handshaker shaker;
public byte[] bestMoveBytesRealist, scoreWhiteBytesRealist, scoreBlackBytesRealist;
public TeamHandshaker(int maxNumMoves) {
TeamRational teamRationalRealist = TeamRational.createRealist(maxNumMoves);
bestMoveBytesRealist = teamRationalRealist.bestMoveBytes;
scoreWhiteBytesRealist = teamRationalRealist.scoreWhiteBytes;
scoreBlackBytesRealist = teamRationalRealist.scoreBlackBytes;
// ADD FOLLOWING LINE TO SUPPORT HANDSHAKE
shaker = Handshaker.createHandshakeAccepter();
}
public void prepareForSeries() {
// ADD FOLLOWING LINE TO SUPPORT HANDSHAKE
shaker.handshakePrepareForSeries();
}
public void prepareForMatch() {
// ADD FOLLOWING LINE TO SUPPORT HANDSHAKE
shaker.handshakePrepareForMatch(toBoardPosition());
}
public void receiveMatchOutcome(int matchOutcome) {
// ADD FOLLOWING LINE TO SUPPORT HANDSHAKE
shaker.handshakeReceiveMatchOutcome(matchOutcome, toBoardPosition());
}
// TO SUPPORT HANDSHAKE:
// Rename your original chooseMove -> internalChooseMove and use the following as chooseMove():
public MoveDescription chooseMove() {
BoardPosition currentBoardPosition = toBoardPosition();
// update shaker with opponent move
shaker.updateTheirMove(currentBoardPosition);
MoveDescription myMove;
if (shaker.shouldSendHandshakeMove()) {
myMove=Handshaker.getHandshakeMove(currentBoardPosition);
} else {
myMove = internalChooseMove();
}
shaker.receiveMyMove(myMove);
return myMove;
}
// Your original strategy goes here. Called whenever you are not sending a handshake.
private MoveDescription internalChooseMove() {
BoardPosition currentBoardPosition = toBoardPosition();
TeamRational.Node nodeRealist = new TeamRational.Node(
bestMoveBytesRealist[currentBoardPosition.toInt()],
scoreWhiteBytesRealist[currentBoardPosition.toInt()],
scoreBlackBytesRealist[currentBoardPosition.toInt()]);
return nodeRealist.bestMove;
}
}