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,
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:
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
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;
}
board_remove_piece (board, x2, y2);
board_add_piece (board, x2, y2, cell);
- loa_game_next_player (game);
+ board_next_player (board);
return TRUE;
}
"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:");
{
loudgame_broadcastf (&game->lg, "%s passes", peer);
- loa_game_next_player (game);
+ board_next_player (&game->board);
}
static void
{
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"