]> git.cworth.org Git - wordgame/commitdiff
Print the per-word statistics at the end of the game.
authorCarl Worth <cworth@raht.cworth.org>
Fri, 29 Sep 2006 04:10:11 +0000 (21:10 -0700)
committerCarl Worth <cworth@raht.cworth.org>
Fri, 29 Sep 2006 04:10:11 +0000 (21:10 -0700)
word-game.c

index d4fa77e822582cc82086fc17779857a9baacaaad..2b9fa4e1e3df481096778425c9a1092a9d06b41c 100644 (file)
@@ -57,6 +57,24 @@ _count_possible (dict_cursor_t       cursor,
        _count_possible (dict_cursor_next (cursor, c), depth + 1, possible);
 }
 
+static void
+_print_stats (int found[WORD_GAME_MAX_WORD_LENGTH+1],
+             int possible[WORD_GAME_MAX_WORD_LENGTH+1],
+             int found_total,
+             int possible_total)
+{
+    int i;
+
+    for (i = 2; i <= 17; i++)
+       if (possible[i])
+           printf ("%d:(%d/%d) ", i, found[i], possible[i]);
+
+    printf ("total:(%d/%d = %.2f%%)\n",
+           found_total, possible_total,
+           100 * (double) found_total / possible_total);
+}
+
+
 void
 word_game_play (const char     *puzzle,
                dict_t          *dict,
@@ -108,12 +126,7 @@ word_game_play (const char *puzzle,
                printf ("%s\n", puzzle);
                just_saw_puzzle = TRUE;
            } else {
-               for (i = 2; i <= 17; i++)
-                   if (possible[i])
-                       printf ("%d:(%d/%d) ", i, found[i], possible[i]);
-               printf ("total:(%d/%d = %.2f%%)\n",
-                       found_total, possible_total,
-                       100 * (double) found_total / possible_total);
+               _print_stats (found, possible, found_total, possible_total);
            }
        } else {
            dict_entry_t *entry;
@@ -146,7 +159,11 @@ word_game_play (const char *puzzle,
        }
     } while (remaining > 0);
 
-    printf ("%s\n", puzzle);
+    printf ("\n%s\n", puzzle);
+
+    printf ("\n");
+    _print_stats (found, possible, found_total, possible_total);
+    printf ("\n");
 
     if (found_total) {
        printf ("Words you found:\n");