-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComplexGridAccessor.java
49 lines (45 loc) · 1.68 KB
/
ComplexGridAccessor.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
public class ComplexGridAccessor extends CheckersGridAccessor {
private static int normalWeight = 1, crownedWeight = 5;
private double getAreaNumber(GridItem gridItem) {
if (gridItem.letter == GridItemLetter.A || gridItem.letter == GridItemLetter.H) {
if (gridItem.number == 1 || gridItem.number == 8) {
return 1.3;
}
}
if (gridItem.letter == GridItemLetter.B || gridItem.letter == GridItemLetter.G) {
if (gridItem.number == 2 || gridItem.number == 7) {
return 1.1;
}
}
return 1;
}
@Override
public int accessCheckersGrid(CheckersGrid checkersGrid, PlayerColor playerColor, MinMaxEnum whoseTurn) {
if (whoseTurn != null) {
return switch (whoseTurn) {
case MIN -> Integer.MAX_VALUE;
case MAX -> Integer.MIN_VALUE;
};
}
int countCurrent = 0;
for (var row : checkersGrid.getFullGrid()) {
for (var item : row) {
var figure = checkersGrid.getFigure(item);
if (figure != null) {
var multiplier = 1;
if (figure.playerColor != playerColor) {
multiplier = -1;
}
multiplier *= getAreaNumber(item);
if (figure.figureType == FigureType.NORMAL) {
countCurrent += normalWeight * multiplier;
}
else {
countCurrent += crownedWeight * multiplier;
}
}
}
}
return countCurrent;
}
}