]> git.cworth.org Git - wordgame/blobdiff - grid.c
Print board before result summary
[wordgame] / grid.c
diff --git a/grid.c b/grid.c
index cce4ab768da43dcd7f8105a7cf0f38ac9328f206..5b57a51964d01d9a7286c679504d6d241cf762c0 100644 (file)
--- a/grid.c
+++ b/grid.c
@@ -45,13 +45,13 @@ typedef struct _board {
     dict_t *results;
 } board_t;
 
-int
+static int
 rand_within (int num_values)
 {
     return (int) ((double) num_values * (rand() / (RAND_MAX + 1.0)));
 }
 
-void
+static void
 shuffle (int *array, int length)
 {
     int i, r, tmp;
@@ -65,7 +65,7 @@ shuffle (int *array, int length)
     }
 }
 
-void
+static void
 board_init (board_t *board)
 {
     int i;
@@ -79,7 +79,7 @@ board_init (board_t *board)
        board->letters[i / 4][i % 4] = cube_faces[cubes[i]][rand_within(6)];
 }
 
-void
+static void
 board_print (board_t *board)
 {
     int x, y;
@@ -98,7 +98,7 @@ board_print (board_t *board)
 }
 
 #define SEEN_BIT(x, y) (1 << (4*(y)+(x)))
-void
+static void
 board_enumerate (board_t       *board,
                 int             x,
                 int             y,
@@ -203,11 +203,12 @@ main (void)
        sprintf (prompt, "%02d:%02d ", minutes, seconds);
        response = readline (prompt);
        add_history (response);
-       chomp (response);
        if (strlen (response) == 0) {
            board_print (&board);
        } else {
            dict_entry_t *entry;
+           if (response[strlen (response) - 1] == '\n')
+               response[strlen (response) - 1] = '\0';
            entry = dict_lookup (&solution, response);
            if (DICT_ENTRY_IS_WORD (entry)) {
                if (*entry & GRID_WORD_SEEN)
@@ -228,7 +229,9 @@ main (void)
        minutes = remaining / 60;
     } while (remaining > 0);
 
-    printf ("\nWords you found:\n");
+    board_print (&board);
+
+    printf ("Words you found:\n");
     found = dict_print_by_length_if (&solution, seen_predicate);
 
     printf ("\nWords you missed:\n");