Commit a0cbf811 authored by PurkkaKoodari's avatar PurkkaKoodari

Fix stack overflow for adjacent mines

parent 5321181c
...@@ -168,6 +168,7 @@ public class Board { ...@@ -168,6 +168,7 @@ public class Board {
return; return;
int state = tiles[index]; int state = tiles[index];
if (state != (state &= ~Tile.SUPER_MINE)) { if (state != (state &= ~Tile.SUPER_MINE)) {
tiles[index] = (state & ~(Tile.OPPONENT | Tile.SUPER_MINE)) | Tile.PLAYER;
takeTile(tiles, x - 1, y - 1, index - 11); takeTile(tiles, x - 1, y - 1, index - 11);
takeTile(tiles, x + 1, y - 1, index - 9); takeTile(tiles, x + 1, y - 1, index - 9);
takeTile(tiles, x - 1, y + 1, index + 9); takeTile(tiles, x - 1, y + 1, index + 9);
...@@ -177,12 +178,14 @@ public class Board { ...@@ -177,12 +178,14 @@ public class Board {
takeTile(tiles, x + 1, y, index + 1); takeTile(tiles, x + 1, y, index + 1);
takeTile(tiles, x, y + 1, index + 10); takeTile(tiles, x, y + 1, index + 10);
} else if (state != (state &= ~Tile.MINE)) { } else if (state != (state &= ~Tile.MINE)) {
tiles[index] = (state & ~(Tile.OPPONENT | Tile.MINE)) | Tile.PLAYER;
takeTile(tiles, x, y - 1, index - 10); takeTile(tiles, x, y - 1, index - 10);
takeTile(tiles, x - 1, y, index - 1); takeTile(tiles, x - 1, y, index - 1);
takeTile(tiles, x + 1, y, index + 1); takeTile(tiles, x + 1, y, index + 1);
takeTile(tiles, x, y + 1, index + 10); takeTile(tiles, x, y + 1, index + 10);
} else {
tiles[index] = (state & ~Tile.OPPONENT) | Tile.PLAYER;
} }
tiles[index] = (state & ~Tile.OPPONENT) | Tile.PLAYER;
} }
private void addConnected(int[] tiles, int x, int y, int index, boolean[] positions) { private void addConnected(int[] tiles, int x, int y, int index, boolean[] positions) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment