diff options
author | Robby Zambito <contact@robbyzambito.me> | 2021-07-25 23:57:54 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2021-07-25 23:57:54 -0400 |
commit | 284af628eee7e8661f117ca4cab698c24abf600f (patch) | |
tree | f8f3a8248f473baef091def8706fde0fba300425 /src/game_loop.c | |
parent | 0642443e690b879e94b627597f624d5fd56db33d (diff) |
Replaced player_color type with equivalent player_color enum
Diffstat (limited to 'src/game_loop.c')
-rw-r--r-- | src/game_loop.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/game_loop.c b/src/game_loop.c index 91350ec..964ba3f 100644 --- a/src/game_loop.c +++ b/src/game_loop.c @@ -9,7 +9,7 @@ #define STREQ(a, b) (strcmp(a, b) == 0) -static player_color other_player(player_color current_player) { +static enum player_color other_player(enum player_color current_player) { switch (current_player) { case WHITE: return BLACK; @@ -20,7 +20,7 @@ static player_color other_player(player_color current_player) { } } -static int player_number_from_color(player_color player) { +static int player_number_from_color(enum player_color player) { switch (player) { case WHITE: return 1; @@ -31,7 +31,7 @@ static int player_number_from_color(player_color player) { } } -static void prompt_player(player_color current_player) { +static void prompt_player(enum player_color current_player) { printf("Player %d [h for help] > ", player_number_from_color(current_player)); } @@ -40,13 +40,14 @@ static void print_help() { "For example `0 0` will select the top left corner.\n\n" "To print the board again, enter `p`\n\n" "To drop into a guile repl enter `g`.\n\n" - "In the guile repl you can define an AI to use for the current player.\n\n" + "In the guile repl you can define an AI to use for the current " + "player.\n\n" "After you define an AI for that player, it will be used for the rest " "of the game instead of prompting for input for that user."); } -static struct move get_move(player_color board[8][8], - player_color current_player) { +static struct move get_move(enum player_color board[8][8], + enum player_color current_player) { // Initialize move to an invalid move. struct move move = {-1, -1}; @@ -79,8 +80,8 @@ static struct move get_move(player_color board[8][8], return move; } -static void apply_move(player_color board[8][8], player_color current_player, - struct move move) { +static void apply_move(enum player_color board[8][8], + enum player_color current_player, struct move move) { if (!is_valid_move(board, current_player, move)) { // We should have checked for the validity of the move before we got here. @@ -151,8 +152,8 @@ static void apply_move(player_color board[8][8], player_color current_player, } } -player_color game_loop(player_color board[8][8]) { - player_color current_player = WHITE; +enum player_color game_loop(enum player_color board[8][8]) { + enum player_color current_player = WHITE; while (has_valid_moves(board, current_player)) { struct move move = get_move(board, current_player); |