aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-13 13:06:49 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-13 13:06:49 +0100
commit49fe5a35e962d363c0e43f5e4b345fc8810d2989 (patch)
treeac833abacce40f4d8ab83a5df7073d0d68208dee
parentdf5909c22a771851ba73a42975f42fab9c7541af (diff)
game from stdin working :tada:
-rw-r--r--console/voerbak.c21
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;