]> git.cworth.org Git - loudgame/blobdiff - lg-loa.c
Add support for a 'history' command
[loudgame] / lg-loa.c
index 4bf623076442ea9d8c9d7e7369fb8a3226f3f355..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
@@ -143,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)
 {
@@ -168,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"
@@ -244,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)
@@ -261,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;