diff options
author | Raúl Benencia <rul@kalgan.cc> | 2015-03-31 16:20:39 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2015-03-31 16:20:39 -0300 |
commit | d8143db289b441562a69dcfa783d7d80c2f544c6 (patch) | |
tree | 928c22c4598a670019dbb1d31af687d59ba3ed27 /lib/game.c | |
parent | a9b35e6086ff71e351b3861aa897777e278a4059 (diff) |
input_move instead of coordinates. Introduce game_is_move_valid()
Diffstat (limited to 'lib/game.c')
-rw-r--r-- | lib/game.c | 36 |
1 files changed, 23 insertions, 13 deletions
@@ -6,24 +6,27 @@ #include "move.h" #include "print.h" -static Color _toggle_current_player(Color c) { - if (c == WHITE) - return BLACK; - else - return WHITE; -} - /* + * Return 1 if the received player is checkmated. Returns 0 otherwise. * TODO */ -int game_is_checkmate(Board board, Color color) { +int game_is_checkmate(Board b, Color p) { return 0; } +/* + * Check if a move is valid in the received board for the received player. + * TODO. + */ +int game_is_move_valid(Board b, Color p, Move m) { + return 1; +} + Board game_loop(Board board) { Board b = board; Color current_player = WHITE; - Coord orig, dest; + Move m; + int move_valid; while (!game_is_checkmate(b, current_player)) { print_board(b, current_player); @@ -34,11 +37,18 @@ Board game_loop(Board board) { else puts("Black's turn"); - orig = input_orig_coord(); - dest = input_dest_coord(); + move_valid = 0; + while (!move_valid) { + m = input_move(); + + if (game_is_move_valid(b, current_player, m)) + move_valid = 1; + else + printf("Invalid move. Please, try again. "); + } - b = board_make_move(b, move_init(orig, dest)); - current_player = _toggle_current_player(current_player); + b = board_make_move(b, m); + current_player = current_player == WHITE ? BLACK : WHITE; } return 0; |