aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-13 14:17:37 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-13 14:17:37 +0100
commit64f53e70901069aab8344e24ebf0abe603f40ec3 (patch)
tree45110b48eb2701a694920616b59dd0f4e86e543c
parenta906e75dfbef6f58c9dd22c2a952cfef565a0b03 (diff)
voerbak.c done
-rw-r--r--console/voerbak.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/console/voerbak.c b/console/voerbak.c
index afb9bec..a7807b6 100644
--- a/console/voerbak.c
+++ b/console/voerbak.c
@@ -8,6 +8,12 @@
#define EMPTY "\x1b[90m_\x1b[39m"
void printBoard(int board[], int width, int height) {
+ for (int i = 0; i < width * height; i++)
+ printf("%d", board[i]);
+ printf("\n");
+}
+
+void printHumanBoard(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];
@@ -60,8 +66,11 @@ bool checkWin(int board[], int width, int height, int pos) {
bool won = false;
for (int i = 0; i < 4; i++) {
if (joinedValues[i] >= 3) {
- won = true;
- break;
+ won = won || true;
+
+ int start_pos = pos + directions[i+0] * values[i+0];
+ int end_pos = pos + directions[i+4] * values[i+4];
+ printf("w:%d-%d\n", start_pos, end_pos);
}
}
@@ -74,8 +83,6 @@ void dropFisje(int board[], int width, int height, int column, int disc) {
if (board[pos] == 0) {
board[pos] = disc;
bool won = checkWin(board, width, height, pos);
- printf(won ? "true" : "false");
- printf("\n");
return;
}
}
@@ -92,10 +99,11 @@ int main() {
int move = 0;
while (scanf("%d", &move) == 1) {
if (move == 0) break;
+ if (move < 1 || move > width) continue;
dropFisje(board, width, height, move - 1, player_1 + 1);
+ printBoard(board, width, height);
player_1 = !player_1;
}
- printBoard(board, width, height);
return 0;
}