From: Carl Worth Date: Sat, 23 Feb 2008 20:01:15 +0000 (-0800) Subject: lg-loa: Move current player into board_t structure. X-Git-Url: https://git.cworth.org/git?p=loudgame;a=commitdiff_plain;h=9bf7ab7f271bc6ab5d916dc53893039d93418c9d lg-loa: Move current player into board_t structure. --- diff --git a/lg-loa.c b/lg-loa.c index a1949d3..ca888e8 100644 --- a/lg-loa.c +++ b/lg-loa.c @@ -64,14 +64,24 @@ typedef struct { int col_pieces[BOARD_SIZE]; int diag_grave_pieces[DIAG_ARRAY_SIZE]; int diag_acute_pieces[DIAG_ARRAY_SIZE]; + + player_t player; } board_t; typedef struct _loa_game { loudgame_t lg; board_t board; - player_t current; } loa_game_t; +static void +board_next_player (board_t *board) +{ + if (board->player == PLAYER_BLACK) + board->player = PLAYER_WHITE; + else + board->player = PLAYER_BLACK; +} + static int board_group_size_recursive (board_t *board, int x, int y, cell_t cell, @@ -292,6 +302,8 @@ board_init (board_t *board) board_add_piece (board, 0, i, CELL_WHITE); board_add_piece (board, BOARD_SIZE - 1, i, CELL_WHITE); } + + board->player = PLAYER_BLACK; } /* A few different ideas for displaying boards: @@ -380,16 +392,6 @@ static void loa_game_new_game (loa_game_t *game) { board_init (&game->board); - game->current = PLAYER_BLACK; -} - -static void -loa_game_next_player (loa_game_t *game) -{ - if (game->current == PLAYER_BLACK) - game->current = PLAYER_WHITE; - else - game->current = PLAYER_BLACK; } static loa_bool_t @@ -405,7 +407,7 @@ loa_game_move (loa_game_t *game, const char * peer, return FALSE; } - if (board->cells[x1][y1] != game->current) { + if (board->cells[x1][y1] != board->player) { loudgame_sendf (&game->lg, peer, "Cell at (%d,%d) does not belong to current player.", x1, y1); return FALSE; @@ -422,7 +424,7 @@ loa_game_move (loa_game_t *game, const char * peer, board_remove_piece (board, x2, y2); board_add_piece (board, x2, y2, cell); - loa_game_next_player (game); + board_next_player (board); return TRUE; } @@ -448,7 +450,7 @@ loa_game_handle_show (loa_game_t *game, "xmlns", "http://www.w3.org/1999/xhtml"); - if (game->current == PLAYER_BLACK) + if (game->board.player == PLAYER_BLACK) lm_message_node_add_child (body, "span", "Black to move:"); else lm_message_node_add_child (body, "span", "White to move:"); @@ -518,7 +520,7 @@ loa_game_handle_pass (loa_game_t *game, const char *peer) { loudgame_broadcastf (&game->lg, "%s passes", peer); - loa_game_next_player (game); + board_next_player (&game->board); } static void