]> git.cworth.org Git - wordgame/blobdiff - grid.c
Add printing to dict interface. Breakup grid prints by letter count.
[wordgame] / grid.c
diff --git a/grid.c b/grid.c
index 44ffa9d23f7487b90a8c0c71f542ae267d364c62..d796cabee7b4ed2bda6fb00d31810f6a0f0096e6 100644 (file)
--- a/grid.c
+++ b/grid.c
@@ -28,6 +28,9 @@
 
 #include "dict.h"
 
+/* Remember that dict reserves the 0th bit for IS_WORD */
+#define GRID_WORD_SEEN (1<<1)
+
 char *cube_faces[16] = {
     "aaeeng", "abbjoo", "achops", "affkps",
     "aoottw", "cimotu", "deilrx", "delrvy",
@@ -139,7 +142,7 @@ board_enumerate (board_t    *board,
     string_chop (word);
 }
 
-void
+static void
 board_solve (board_t *board, dict_t *dict, dict_t *solution)
 {
     int x, y;
@@ -157,6 +160,18 @@ board_solve (board_t *board, dict_t *dict, dict_t *solution)
     string_fini (&word);
 }
 
+static bool_t
+seen_predicate (dict_entry_t entry)
+{
+    return entry & GRID_WORD_SEEN;
+}
+
+static bool_t
+unseen_predicate (dict_entry_t entry)
+{
+    return ! seen_predicate (entry);
+}
+
 #define GAME_LENGTH (3 * 60)
 int
 main (void)
@@ -198,10 +213,10 @@ main (void)
            dict_entry_t *entry;
            entry = dict_lookup (&solution, response);
            if (DICT_ENTRY_IS_WORD (entry)) {
-               if (*entry & TRIE_FLAGS_SEEN)
+               if (*entry & GRID_WORD_SEEN)
                    printf ("(repeat)\n");
                else
-                   *entry |= TRIE_FLAGS_SEEN;
+                   *entry |= GRID_WORD_SEEN;
            } else {
                entry = dict_lookup (&dict, response);
                if (DICT_ENTRY_IS_WORD (entry))
@@ -217,18 +232,13 @@ main (void)
     } while (remaining > 0);
 
     printf ("\nWords you found:\n");
-    string_init (&word);
-    found = trie_print_seen (&solution, &word);
-    string_fini (&word);
-    printf ("\n");
+    found = dict_print_by_length_if (&solution, seen_predicate);
 
     printf ("\nWords you missed:\n");
-    string_init (&word);
-    missed = trie_print_unseen (&solution, &word);
-    string_fini (&word);
+    missed = dict_print_by_length_if (&solution, unseen_predicate);
     printf ("\n");
 
-    printf ("\nYou found %d of %d words (%.2f%%)\n",
+    printf ("You found %d of %d words (%.2f%%)\n",
            found, found + missed,
            100 * (double) found / (found + missed));