-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeamMonkey.java
executable file
·46 lines (36 loc) · 1.13 KB
/
TeamMonkey.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
import java.util.*;
public class TeamMonkey extends Player {
private Random rand;
public TeamMonkey(int maxNumMoves) {
rand = new Random(System.currentTimeMillis());
}
public void prepareForSeries() {
}
public void prepareForMatch() {
}
public void receiveMatchOutcome(int matchOutcome) {
}
public MoveDescription chooseMove() {
ArrayList<MoveDescription> allPossibleMoves = getAllPossibleMoves();
// Try to capture their king.
if (theirKingIsAlive) {
for (MoveDescription moveDescription : allPossibleMoves) {
if (moveDescription.getDestinationColumn() == theirKingColumn
&& moveDescription.getDestinationRow() == theirKingRow) {
return moveDescription;
}
}
}
// Try to capture their rook.
if (theirRookIsAlive) {
for (MoveDescription moveDescription : allPossibleMoves) {
if (moveDescription.getDestinationColumn() == theirRookColumn
&& moveDescription.getDestinationRow() == theirRookRow) {
return moveDescription;
}
}
}
// Did not manage to capture any piece. Will choose random move.
return allPossibleMoves.get(rand.nextInt(allPossibleMoves.size()));
}
}