From 9b712de308e150cc70cf7571c9debfff17978fd2 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 23 Feb 2021 20:52:24 +0100 Subject: voerbak 2.1.3 --- voerbak/voerbak.c | 56 ++++++++++++++++++------------------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) (limited to 'voerbak/voerbak.c') diff --git a/voerbak/voerbak.c b/voerbak/voerbak.c index 1ac74b6..d1982fa 100644 --- a/voerbak/voerbak.c +++ b/voerbak/voerbak.c @@ -1,51 +1,31 @@ -#include -#include -#include #include +#include #include "voerbak.h" #include "win.h" +#include "board.h" +#include "messages.h" +#include "argparse.h" -void printBoard(Board *b) { - for (int i = 0; i < b->length; i++) - printf("%d", b->board[i]); - printf("\n"); - fflush(stdout); -} +#define EMPTY "" -bool boardFull(Board *b) { - for (int i = 0; i < b->length; i++) - if (b->board[i] == 0) return false; - return true; -} +int main(int argc, char* argv[]) { + struct arguments arguments = argparse(argc, argv); -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 -} - -int main() { - int width, height; - scanf("%d %d", &width, &height); - - Board *gameBoard = malloc(sizeof(Board)); - gameBoard->board = malloc(sizeof(int) * (width * height - 1)); - gameBoard->width = width; - gameBoard->height = height; - gameBoard->length = width * height; + Board *gameBoard = createBoard(arguments.width, arguments.height); bool player_1 = true; int move = 0; - while (scanf("%d", &move) == 1) { + char* message = malloc(1); // this is weird and i don't understand it but it prevents a segmentation fault or something + strcpy(message, EMPTY); + while (scanf("%d", &move) == 1 || scanf("%s", message) == 1) { + if (strlen(message) != 0) { + parseMessage(message, arguments.verbosity); + + strcpy(message, EMPTY); // clear message + continue; + } + if (move == 0) break; if (move < 1 || move > gameBoard->width) continue; -- cgit v1.2.3