summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/game.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/game.c b/lib/game.c
new file mode 100644
index 0000000..6fcc0c5
--- /dev/null
+++ b/lib/game.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+
+#include "board.h"
+#include "game.h"
+#include "input.h"
+#include "move.h"
+#include "print.h"
+
+static Color _toggle_current_player(Color c) {
+ if (c == WHITE)
+ return BLACK;
+ else
+ return WHITE;
+}
+
+Board game_loop(Board board) {
+ Board b = board;
+ Color current_player = WHITE;
+ Coord orig, dest;
+
+ while (1) {
+ print_board(b, current_player);
+
+ putchar('\n');
+ if (current_player == WHITE)
+ printf("White's turn. \n");
+ else
+ printf("Black's turn. \n");
+
+ orig = input_orig_coord();
+ dest = input_dest_coord();
+
+ b = board_make_move(b, move_init(orig, dest));
+ current_player = _toggle_current_player(current_player);
+ }
+}
nihil fit ex nihilo