-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSimpleAccessor.java
30 lines (28 loc) · 1020 Bytes
/
SimpleAccessor.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
public class SimpleAccessor extends CheckersGridAccessor {
private static int normalWeight = 1, crownedWeight = 5;
@Override
public int accessCheckersGrid(CheckersGrid checkersGrid, PlayerColor playerColor, MinMaxEnum whoseTurn) {
if (whoseTurn != null) {
return switch (whoseTurn) {
case MIN -> Integer.MIN_VALUE;
case MAX -> Integer.MAX_VALUE;
};
}
int countCurrent = 0;
for (var figure : checkersGrid.getAllFilledItems()) {
if (figure != null) {
var multiplier = 1;
if (figure.playerColor != playerColor) {
multiplier = -1;
}
if (figure.figureType == FigureType.NORMAL) {
countCurrent += normalWeight * multiplier;
}
else {
countCurrent += crownedWeight * multiplier;
}
}
}
return countCurrent;
}
}