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
|
#include <stdio.h>
#include <memory.h>
#include <stdbool.h>
#define DISC_A "\x1b[31mo\x1b[39m"
#define DISC_B "\x1b[34mo\x1b[39m"
#define EMPTY "\x1b[90m_\x1b[39m"
void printBoard(int board[], int width, int height) {
for (int y = height - 1; y > -1; y--) {
for (int x = 0; x < width; x++) {
int val = board[x + y * width];
char *print =
val == 0 ? EMPTY :
val == 1 ? DISC_A :
val == 2 ? DISC_B :
EMPTY;
printf("%s ", print);
}
printf("\n");
}
}
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);
int board[width * height];
memset(board, 0, sizeof board);
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;
}
|