Skip to content

Commit 5e3c9ba

Browse files
committed
fix counting regression
1 parent b718f46 commit 5e3c9ba

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

src/main/java/com/bernd/LobbyController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ private static int[][] createEmptyBoard(MatchRequest request) {
9090
for (int y = 0; y < dim; y++) {
9191
board[y] = new int[dim];
9292
}
93+
// board = new int[][]{
94+
// new int[]{0, 0, 0, 0, W, B, 0, 0, 0},
95+
// new int[]{0, 0, 0, 0, W, B, 0, 0, 0},
96+
// new int[]{0, 0, W, W, W, B, 0, 0, 0},
97+
// new int[]{0, 0, W, B, B, B, 0, B, B},
98+
// new int[]{W, 0, W, B, B, 0, B, W, W},
99+
// new int[]{B, W, W, B, 0, B, W, W, 0},
100+
// new int[]{B, B, B, B, W, B, W, 0, 0},
101+
// new int[]{0, 0, 0, B, B, W, W, 0, 0},
102+
// new int[]{0, 0, 0, B, W, W, W, 0, 0},
103+
// };
93104
return board;
94105
}
95106
}

src/main/java/com/bernd/util/Util.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static String boardToString(int[][] board) {
3333
}
3434

3535
public static boolean isEmpty(int color) {
36-
return color == 0 || (color & REMOVED_B) != 0 || (color & REMOVED_W) != 0;
36+
return (color & COLORS) == 0;
3737
}
3838

3939
public static int unremove(int color) {
@@ -57,10 +57,16 @@ public static int toggleRemoved(int color) {
5757
}
5858

5959
public static int getBaseColor(int color) {
60-
if ((color & (B | TERRITORY_B | REMOVED_B)) != 0) {
60+
if ((color & (B | REMOVED_B)) != 0) {
6161
return B;
6262
}
63-
if ((color & (W | TERRITORY_W | REMOVED_W)) != 0) {
63+
if ((color & (W | REMOVED_W)) != 0) {
64+
return W;
65+
}
66+
if ((color & TERRITORY_B) != 0) {
67+
return B;
68+
}
69+
if ((color & TERRITORY_W) != 0) {
6470
return W;
6571
}
6672
return 0;
@@ -81,6 +87,6 @@ public static int divUp(int i, int div) {
8187
}
8288

8389
public static boolean isStone(int color) {
84-
return (color & COLORS) != 0 && (color & MARKERS) == 0;
90+
return (color & COLORS) != 0;
8591
}
8692
}

src/test/java/com/bernd/game/CountTest.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void testNoBufferOverflow() {
190190

191191
@Test
192192
void testCornerEyeCount() {
193-
int b = REMOVED_B;
193+
int b = REMOVED_B;
194194
int w = TERRITORY_W;
195195
int k = TERRITORY_W | REMOVED_B;
196196
int t = TERRITORY_B;
@@ -270,6 +270,47 @@ void testCountAgain() {
270270
}, counted);
271271
}
272272

273+
@Test
274+
void testTerritoryBorderRemoved() {
275+
int b = TERRITORY_B;
276+
int k = REMOVED_B;
277+
int[][] position = new int[][]{
278+
new int[]{W, B, b, b, b},
279+
new int[]{W, B, b, b, b},
280+
new int[]{W, B, b, b, b},
281+
new int[]{B, B, b, k, k},
282+
new int[]{B, b, B, W, W},
283+
};
284+
int[][] counted = Count.count(position);
285+
assertArrayEquals(new int[][]{
286+
new int[]{W, B, 0, 0, 0},
287+
new int[]{W, B, 0, 0, 0},
288+
new int[]{W, B, 0, 0, 0},
289+
new int[]{B, B, 0, k, k},
290+
new int[]{B, b, B, W, W},
291+
}, counted);
292+
}
293+
294+
@Test
295+
void testResurrect() {
296+
int b = TERRITORY_B;
297+
int w = TERRITORY_B | REMOVED_W;
298+
int k = REMOVED_B;
299+
int[][] position = new int[][]{
300+
new int[]{B, b, B, w},
301+
new int[]{b, k, w, w},
302+
new int[]{w, k, w, b},
303+
new int[]{B, w, w, b}
304+
};
305+
int[][] counted = Count.count(position);
306+
assertArrayEquals(new int[][]{
307+
new int[]{B, b, B, w},
308+
new int[]{b, B, w, w},
309+
new int[]{w, B, w, b},
310+
new int[]{B, w, w, b}
311+
}, counted);
312+
}
313+
273314
static int[][] createEmptyBoard(int dim) {
274315
int[][] board = new int[dim][];
275316
for (int y = 0; y < dim; y++) {

0 commit comments

Comments
 (0)