diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-02-23 20:52:24 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-02-23 20:52:24 +0100 |
commit | 9b712de308e150cc70cf7571c9debfff17978fd2 (patch) | |
tree | f4dd083f675ce6789f3e9c1e55e1387a0c7ca19d /voerbak/board.c | |
parent | 1a55f52bb79b609cd850a77e2f7a9fdc6b4fbf6b (diff) |
voerbak 2.1.3
Diffstat (limited to 'voerbak/board.c')
-rw-r--r-- | voerbak/board.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/voerbak/board.c b/voerbak/board.c new file mode 100644 index 0000000..8008db4 --- /dev/null +++ b/voerbak/board.c @@ -0,0 +1,41 @@ +#include <memory.h> + +#include "board.h" +#include "win.h" + +Board* createBoard(int width, int height) { + Board *gameBoard = malloc(sizeof(Board)); + gameBoard->board = malloc(sizeof(int) * (width * height - 1)); + gameBoard->width = width; + gameBoard->height = height; + gameBoard->length = width * height; + return gameBoard; +} + +void printBoard(Board *b) { + for (int i = 0; i < b->length; i++) + printf("%d", b->board[i]); + printf("\n"); + fflush(stdout); +} + +bool boardFull(Board *b) { + for (int i = 0; i < b->length; i++) + if (b->board[i] == 0) return false; + return true; +} + +bool dropFisje(Board *b, int column, int disc) { + for (int row = 0; row < b->height; row++) { + int pos = column + row * b->width; + if (b->board[pos] == 0) { + b->board[pos] = disc; + bool won = checkWin(b, pos); + return true; // success + } + } + printf("e:full\n"); + fflush(stdout); + return false; // unsuccessful drop on board full +} + |