blob: 8008db4cfd53651bb510e10524f7260e93d073a1 (
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
|
#include <memory.h>
#include "board.h"
#include "win.h"
Board* createBoard(int width, int height) {
Board *gameBoard = malloc(sizeof(Board));
gameBoard->board = malloc(sizeof(int) * (width * height - 1));
gameBoard->width = width;
gameBoard->height = height;
gameBoard->length = width * height;
return gameBoard;
}
void printBoard(Board *b) {
for (int i = 0; i < b->length; i++)
printf("%d", b->board[i]);
printf("\n");
fflush(stdout);
}
bool boardFull(Board *b) {
for (int i = 0; i < b->length; i++)
if (b->board[i] == 0) return false;
return true;
}
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
}
|