summaryrefslogtreecommitdiff
path: root/lib/game.c
blob: b9294c9e50a0b515ca385a92dd0aa33628f458f2 (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
#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;
}

/*
 * TODO
 */
int game_is_checkmate(Board board, Color color) {
    return 0;
}

Board game_loop(Board board) {
    Board b = board;
    Color current_player = WHITE;
    Coord orig, dest;

    while (!game_is_checkmate(b, current_player)) {
        print_board(b, current_player);

        putchar('\n');
        if (current_player == WHITE)
            puts("White's turn.");
        else
            puts("Black's turn");

        orig = input_orig_coord();
        dest = input_dest_coord();

        b = board_make_move(b, move_init(orig, dest));
        current_player = _toggle_current_player(current_player);
    }

    return 0;
}
nihil fit ex nihilo