-
Notifications
You must be signed in to change notification settings - Fork 4
/
PossibleMoves.cpp
76 lines (55 loc) · 2.81 KB
/
PossibleMoves.cpp
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
// check whether player can the piece here
#include <jni.h>
bool checkSetChess(int p, int[][] chessList) {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (chessList[i][j] < 0 && setChessCheck(i, j, p, chessList,
false)) {
return true;
}
}
}
return false;
}
public boolean isEnclosingUpwards(int player, int col, int row) {
boolean enclosing = false;
// impossible enclose upwards if row is less than 2
if (row > 1) {
// impossible enclose upwards if adjacent upwards chip is not
// opponent
if (this.gameMatrix[col][row - 1] == opponent(player)) {
int value = this.getFirstPositionDifferentThan(
opponent(player), col, row - 1, Direction.X.NONE,
Direction.Y.UP);
// only encloses if the first different than opponent is an own
// chip
enclosing = value == player;
}
}
return enclosing;
}
//////////////////////////////////////////////////////
private int getFirstPositionDifferentThan(int player, int initialColumn,
int initialRow, int directionX, int directionY) {
// stores the value of the first position with a value different than
// the player value
int differentPosition = player;
boolean resolved = false;
int x = initialColumn;
int y = initialRow;
while (!resolved) {
x += directionX;
y += directionY;
// if we are inside the bounds of the board game
if (x >= 0 && x < GameLogic.COLS && y >= 0 && y < GameLogic.COLS) {
if (this.gameMatrix[x][y] != player) {
resolved = true;
differentPosition = this.gameMatrix[x][y];
}
} else {
// out of bounds means resolved with no different position
resolved = true;
}
}
return differentPosition;
}