X-Git-Url: https://git.cworth.org/git?p=loudgame;a=blobdiff_plain;f=lg-loa.c;h=5a4d819de4543cfd24037aa648f8cda96b30e6e2;hp=174914307f71ca72faf74a496b08ce00e2a2d336;hb=HEAD;hpb=88c5b7fb802cd1eab050dc67289d86dcb37dec6c diff --git a/lg-loa.c b/lg-loa.c index 1749143..5a4d819 100644 --- a/lg-loa.c +++ b/lg-loa.c @@ -41,16 +41,13 @@ loa_game_new_game (loa_game_t *game) } static loa_bool_t -loa_game_move (loa_game_t *game, const char * peer, - int x1, int y1, int x2, int y2) +loa_game_move (loa_game_t *game, const char * peer, loa_move_t *move) { char *error; - if (! loa_board_move (&game->board, x1, y1, x2, y2, &error)) { - loudgame_sendf (&game->lg, peer, "Illegal move: %c%d%c%d: %s", - 'a' + x1, LOA_BOARD_SIZE - y1, - 'a' + x2, LOA_BOARD_SIZE - y2, - error); + if (! loa_board_move (&game->board, move, &error)) { + loudgame_sendf (&game->lg, peer, "Illegal move: %s: %s", + loa_move_to_string (move), error); return FALSE; } @@ -114,32 +111,22 @@ loa_game_handle_show (loa_game_t *game, static void loa_game_handle_move (loa_game_t *game, const char *peer, - const char *move) + const char *move_string) { - char xc1, xc2; - int x1, y1, x2, y2; - int matched; + loa_move_t move; - matched = sscanf (move, " %c %d %c %d ", &xc1, &y1, &xc2, &y2); - if (matched != 4) { + if (! loa_move_init_from_string (&move, move_string)) { loudgame_sendf (&game->lg, peer, - "Error: The 'move' command requires a move of the form 'b1d3'"); + "Error: The 'move' command requires a move of the form 'b1-d3'"); return; } - x1 = tolower (xc1) - 'a'; - x2 = tolower (xc2) - 'a'; - /* We use an upper-left origin internally. */ - y1 = LOA_BOARD_SIZE - y1; - y2 = LOA_BOARD_SIZE - y2; - if (! loa_game_move (game, peer, x1, y1, x2, y2)) + if (! loa_game_move (game, peer, &move)) return; - loudgame_broadcastf (&game->lg, "%c%d%c%d", - 'a' + x1, LOA_BOARD_SIZE - y1, - 'a' + x2, LOA_BOARD_SIZE - y2); + loudgame_broadcastf (&game->lg, "%s", loa_move_to_string (&move)); - if (loa_board_is_won (&game->board, x2, y2)) + if (loa_board_is_won (&game->board, move.x2, move.y2)) loudgame_broadcastf (&game->lg, "%s wins", peer); } @@ -176,7 +163,7 @@ loa_game_handle_help (loa_game_t *game, const char *peer) "\n" "And some game-specific commands:\n" "\tshow \t\tShow the current board\n" - "\tmove aNbN\tMove a piece, (eg. 'move b1d3')\n" + "\tmove aNbN\tMove a piece, (eg. 'move b1-d3')\n" "\tpass \t\tSkip a turn (only legal if no moves are possible)\n" "\tnew \t\tBegin a new game\n" "\thistory \t\tShow the move history of the game\n"