diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-02-13 13:06:49 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-02-13 13:06:49 +0100 |
commit | 49fe5a35e962d363c0e43f5e4b345fc8810d2989 (patch) | |
tree | ac833abacce40f4d8ab83a5df7073d0d68208dee /console | |
parent | df5909c22a771851ba73a42975f42fab9c7541af (diff) |
game from stdin working :tada:
Diffstat (limited to 'console')
-rw-r--r-- | console/voerbak.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/console/voerbak.c b/console/voerbak.c index 4eeabc5..43eb6c6 100644 --- a/console/voerbak.c +++ b/console/voerbak.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <memory.h> +#include <stdbool.h> #define DISC_A "\x1b[31mo\x1b[39m" #define DISC_B "\x1b[34mo\x1b[39m" @@ -20,6 +21,18 @@ void printBoard(int board[], int width, int height) { } } +void 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); */ + /* printf("%d", won); */ + return; + } + } +} + int main() { int width, height; scanf("%d %d", &width, &height); @@ -27,8 +40,12 @@ int main() { int board[width * height]; memset(board, 0, sizeof board); - board[2] = 1; - board[3] = 2; + bool player_1 = true; + int move = 0; + while (scanf("%d", &move) == 1) { + dropFisje(board, width, height, move - 1, player_1 + 1); + player_1 = !player_1; + } printBoard(board, width, height); return 0; |