X-Git-Url: https://git.cworth.org/git?p=loudgame;a=blobdiff_plain;f=lg-loa.c;h=ca888e8e7338e1c77c7012a89d0a5321521cf0af;hp=61e635124c5c591a6135f8e030668b92cef5431f;hb=9bf7ab7f271bc6ab5d916dc53893039d93418c9d;hpb=7e33d9d0482f397390bea2f2ce17562ac2bb736d diff --git a/lg-loa.c b/lg-loa.c index 61e6351..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,14 +407,16 @@ 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; } if (! board_move_legal (&game->board, x1, y1, x2, y2, &error)) { - loudgame_sendf (&game->lg, peer, "Illegal move: %s."); + loudgame_sendf (&game->lg, peer, "Illegal move: %c%d%c%d", + 'a' + x1, BOARD_SIZE - y1, + 'a' + x2, BOARD_SIZE - y2); return FALSE; } @@ -420,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; } @@ -446,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:"); @@ -516,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 @@ -524,7 +528,10 @@ loa_game_handle_help (loa_game_t *game, const char *peer) { loudgame_sendf (&game->lg, peer, "I'm a bot that allows you to play the game Lines of Action.\n" - "Here are some commands I understand:\n" + "Here are some generic commands I understand:\n" + LOUDGAME_HELP + "\n" + "And some game-specific commands:\n" "\tshow \t\tShow the current board\n" "\tmove aNbN\tMove a piece, (eg. 'move b1d3')\n" "\tpass \t\tSkip a turn (only legal if no moves are possible)\n"