aboutsummaryrefslogtreecommitdiff
path: root/voerbak/voerbak.c
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-23 20:52:24 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-23 20:52:24 +0100
commit9b712de308e150cc70cf7571c9debfff17978fd2 (patch)
treef4dd083f675ce6789f3e9c1e55e1387a0c7ca19d /voerbak/voerbak.c
parent1a55f52bb79b609cd850a77e2f7a9fdc6b4fbf6b (diff)
voerbak 2.1.3
Diffstat (limited to 'voerbak/voerbak.c')
-rw-r--r--voerbak/voerbak.c56
1 files changed, 18 insertions, 38 deletions
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 <stdio.h>
-#include <stdlib.h>
-#include <memory.h>
#include <stdbool.h>
+#include <memory.h>
#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;