]> git.cworth.org Git - loudgame/blobdiff - lg-loa.c
Add support for a 'history' command
[loudgame] / lg-loa.c
index b18b27d0ff417fb2738792ad4abebcfe028604f7..174914307f71ca72faf74a496b08ce00e2a2d336 100644 (file)
--- a/lg-loa.c
+++ b/lg-loa.c
@@ -37,7 +37,7 @@ typedef struct _loa_game {
 static void
 loa_game_new_game (loa_game_t *game)
 {
-    loa_board_init (&game->board);
+    loa_board_reset (&game->board);
 }
 
 static loa_bool_t
@@ -47,9 +47,10 @@ loa_game_move (loa_game_t *game, const char * peer,
     char *error;
 
     if (! loa_board_move (&game->board, x1, y1, x2, y2, &error)) {
-       loudgame_sendf (&game->lg, peer, "Illegal move: %c%d%c%d",
+       loudgame_sendf (&game->lg, peer, "Illegal move: %c%d%c%d: %s",
                        'a' + x1, LOA_BOARD_SIZE - y1,
-                       'a' + x2, LOA_BOARD_SIZE - y2);
+                       'a' + x2, LOA_BOARD_SIZE - y2,
+                       error);
        return FALSE;
     }
 
@@ -142,6 +143,17 @@ loa_game_handle_move (loa_game_t *game,
        loudgame_broadcastf (&game->lg, "%s wins", peer);
 }
 
+static void
+loa_game_handle_history (loa_game_t *game,
+                        const char *peer)
+{
+    int i;
+
+    for (i = 0; i < game->board.num_moves; i++)
+       loudgame_sendf (&game->lg, peer, "%s",
+                       loa_move_to_string (&game->board.moves[i]));
+}
+
 static void
 loa_game_handle_pass (loa_game_t *game, const char *peer)
 {
@@ -167,6 +179,7 @@ loa_game_handle_help (loa_game_t *game, const char *peer)
                    "\tmove aNbN\tMove a piece, (eg. 'move b1d3')\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"
                    "\thelp     \t\tThis help message\n"
                    "\trules    \t\tA description of the Lines of Action rules\n"
                    "\n"
@@ -243,6 +256,8 @@ loa_game_handle_message (loudgame_t *lg,
        loa_game_handle_pass (game, peer);
     else if (strcmp (message, "new") == 0)
        loa_game_handle_new (game, peer);
+    else if (strcmp (message, "history") == 0)
+       loa_game_handle_history (game, peer);
     else if (strcmp (message, "help") == 0)
        loa_game_handle_help (game, peer);
     else if (strcmp (message, "rules") == 0)
@@ -260,6 +275,8 @@ loa_game_init (loa_game_t *game, int argc, char *argv[])
     if (err)
        return err;
 
+    loa_board_init (&game->board);
+
     loa_game_new_game (game);
 
     return 0;