- for (y = 0; y < 4; y++)
- for (x = 0; x < 4; x++)
- board_enumerate (board, x, y, seen, &word, dict);
-
- string_fini (&word);
-}
-
-#define GAME_LENGTH (3 * 60)
-int
-main (void)
-{
- dict_t dict;
- board_t board;
- trie_t *solution;
- struct timeval tv, tv_stop;
- int remaining, minutes, seconds;
- int found, missed;
- char prompt[7], *response;
- string_t word;
-
- gettimeofday (&tv, NULL);
- srand (tv.tv_sec ^ tv.tv_usec);
-
- dict_init (&dict);
- dict_add_words_from_file (&dict, "words.txt");
- board_init (&board);
-
- solution = trie_create ();
- board_solve (&board, &dict, solution);
-
- board_print (&board);
-
- gettimeofday (&tv, NULL);
- tv_stop = tv;
- tv_stop.tv_sec += GAME_LENGTH;
- remaining = GAME_LENGTH;
- do {
- minutes = remaining / 60;
- seconds = remaining % 60;
- sprintf (prompt, "%02d:%02d ", minutes, seconds);
- response = readline (prompt);
- add_history (response);
- chomp (response);
- if (strlen (response) == 0) {
- board_print (&board);
- } else {
- trie_t *t;
- t = trie_find (solution, response);
- if (t && (t->flags & TRIE_FLAGS_IS_WORD)) {
- if (t->flags & TRIE_FLAGS_SEEN)
- printf ("(repeat)\n");
- else
- t->flags |= TRIE_FLAGS_SEEN;
- } else {
- t = trie_find (&dict, response);
- if (t && (t->flags & TRIE_FLAGS_IS_WORD))
- printf ("(a good word, but it's not in the puzzle)\n");
- else
- printf ("*** %s is not a word\n", response);
- }
- }
- free (response);
- gettimeofday (&tv, NULL);
- remaining = floor (0.5 + (tv_stop.tv_sec - tv.tv_sec) + (tv_stop.tv_usec - tv.tv_usec) / 1000000.0);
- minutes = remaining / 60;
- } while (remaining > 0);
-
- printf ("\nWords you found:\n");
- string_init (&word);
- found = trie_print_seen (solution, &word);
- string_fini (&word);
- printf ("\n");
-
- printf ("\nWords you missed:\n");
- string_init (&word);
- missed = trie_print_unseen (solution, &word);
- string_fini (&word);
- printf ("\n");
-
- printf ("\nYou found %d of %d words (%.2f%%)\n",
- found, found + missed,
- 100 * (double) found / (found + missed));
-
- dict_fini (&dict);
-
- return 0;