-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
executable file
·142 lines (117 loc) · 3.79 KB
/
Player.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import java.util.*;
public abstract class Player {
public int myColour;
public int numMovesPlayed;
public boolean myKingIsAlive;
public int myKingColumn, myKingRow;
public boolean myRookIsAlive;
public int myRookColumn, myRookRow;
public boolean theirKingIsAlive;
public int theirKingColumn, theirKingRow;
public boolean theirRookIsAlive;
public int theirRookColumn, theirRookRow;
private String name = getClass().getSimpleName();
protected final static int WHITE = 0;
protected final static int BLACK = 1;
public Player() {
}
public void prepareForSeries() {
throw new RuntimeException("You need to override the method prepareForSeries.");
}
public void prepareForMatch() {
throw new RuntimeException("You need to override the method prepareForMatch.");
}
public MoveDescription chooseMove() {
throw new RuntimeException("You need to override the method ChooseMove.");
}
public int outcomeToPayoff(int matchOutcome) {
if (matchOutcome == 1) { // indicates a win
return 3;
} else if (matchOutcome == 2) { // indicates a loss
return 0;
} else if (matchOutcome == 3) { // indicates a tie
return 2;
} else if (matchOutcome == 4) { // indicates a draw
return 1;
}
return -1;
}
public void receiveMatchOutcome(int matchOutcome) {
// throw new RuntimeException("You need to override the method
// receiveMatchOutcome.");
}
public final void update(Board board, Colour myColour, int numMovesPlayed) {
this.myColour = myColour.toInt();
this.numMovesPlayed = numMovesPlayed;
Cell cell = null;
cell = board.getPieceLocation(new Piece(PieceType.KING, myColour));
if (cell == null) {
myKingIsAlive = false;
myKingColumn = -1;
myKingRow = -1;
} else {
myKingIsAlive = true;
myKingColumn = cell.getColumn();
myKingRow = cell.getRow();
}
cell = board.getPieceLocation(new Piece(PieceType.ROOK, myColour));
if (cell == null) {
myRookIsAlive = false;
myRookColumn = -1;
myRookRow = -1;
} else {
myRookIsAlive = true;
myRookColumn = cell.getColumn();
myRookRow = cell.getRow();
}
cell = board.getPieceLocation(new Piece(PieceType.KING, myColour.reverse()));
if (cell == null) {
theirKingIsAlive = false;
theirKingColumn = -1;
theirKingRow = -1;
} else {
theirKingIsAlive = true;
theirKingColumn = cell.getColumn();
theirKingRow = cell.getRow();
}
cell = board.getPieceLocation(new Piece(PieceType.ROOK, myColour.reverse()));
if (cell == null) {
theirRookIsAlive = false;
theirRookColumn = -1;
theirRookRow = -1;
} else {
theirRookIsAlive = true;
theirRookColumn = cell.getColumn();
theirRookRow = cell.getRow();
}
}
public final Colour getColour() {
return myColour == WHITE ? Colour.WHITE : Colour.BLACK;
}
protected final BoardPosition toBoardPosition() {
BoardPosition boardPosition = null;
if (myColour == WHITE) {
boardPosition = new BoardPosition(myKingIsAlive, myKingColumn, myKingRow, myRookIsAlive, myRookColumn,
myRookRow, theirKingIsAlive, theirKingColumn, theirKingRow, theirRookIsAlive, theirRookColumn,
theirRookRow, numMovesPlayed, myColour);
} else {
boardPosition = new BoardPosition(theirKingIsAlive, theirKingColumn, theirKingRow, theirRookIsAlive,
theirRookColumn, theirRookRow, myKingIsAlive, myKingColumn, myKingRow, myRookIsAlive, myRookColumn,
myRookRow, numMovesPlayed, myColour);
}
return boardPosition;
}
protected final ArrayList<MoveDescription> getAllPossibleMoves() {
return this.toBoardPosition().getAllPossibleMoves();
}
@Deprecated //Use BoardPosition.getAllInitialBoardPositions()
protected LinkedList<BoardPosition> getAllInitialBoardPositions() {
return BoardPosition.getAllInitialBoardPositions();
}
public final String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}