blob: a46b92fc46137882d79235e495b69a525504c861 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include <stdbool.h>
#include <memory.h>
#include "voerbak.h"
#include "win.h"
#include "board.h"
#include "messages.h"
#include "argparse.h"
#include "solvers.h"
#define EMPTY ""
int verbosity = 0;
int main(int argc, char* argv[]) {
struct arguments arguments = argparse(argc, argv);
verbosity = arguments.verbosity;
Board *gameBoard = createBoard(arguments.width, arguments.height);
bool cpu_2 = strlen(arguments.solver) > 0;
bool player_1 = true;
int move = 0;
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);
strcpy(message, EMPTY); // clear message
continue;
}
move:
if (move == 0) break;
if (move < 1 || move > gameBoard->width) continue;
int drop = dropFisje(gameBoard, move - 1, player_1 + 1);
if (drop == -1) {
printBoard(gameBoard);
continue;
}
player_1 = !player_1; // only flip turns on successful drop
bool won = checkWin(gameBoard, drop);
if (verbosity >= 0 ) {
cpu_2 == false && printf("m:%s\n", player_1 ? "true" : "false");
fflush(stdout);
}
if (boardFull(gameBoard)) {
printf("d:full\n");
fflush(stdout);
}
printBoard(gameBoard);
if (cpu_2 && !player_1) {
move = cpuMove(gameBoard, arguments.solver);
goto move;
}
}
return 0;
}
|