diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-02-16 15:38:08 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-02-16 15:38:08 +0100 |
commit | 7a2543051af1d30b62bcf78f0e10b46f80b5d10b (patch) | |
tree | 460a8672c91ca72a7c2fdea014de20df6c53cf18 /console/voerbak.c | |
parent | d2536926285b8cf8f2bcb7dfc300529d1914e4d8 (diff) |
board overflow error
Diffstat (limited to 'console/voerbak.c')
-rw-r--r-- | console/voerbak.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/console/voerbak.c b/console/voerbak.c index 4ee20e4..86f6076 100644 --- a/console/voerbak.c +++ b/console/voerbak.c @@ -79,15 +79,18 @@ bool checkWin(int board[], int width, int height, int pos) { return won; } -void dropFisje(int board[], int width, int height, int column, int disc) { +bool dropFisje(int board[], int width, int height, int column, int disc) { for (int row = 0; row < height; row++) { int pos = column + row * width; if (board[pos] == 0) { board[pos] = disc; bool won = checkWin(board, width, height, pos); - return; + return true; // success } } + printf("e:full\n"); + fflush(stdout); + return false; // unsuccessful drop on board full } int main() { @@ -102,9 +105,9 @@ int main() { while (scanf("%d", &move) == 1) { if (move == 0) break; if (move < 1 || move > width) continue; - dropFisje(board, width, height, move - 1, player_1 + 1); + bool dropSuccess = dropFisje(board, width, height, move - 1, player_1 + 1); printBoard(board, width, height); - player_1 = !player_1; + player_1 = player_1 ^ dropSuccess; // only flip turns on successful drop } return 0; |