2 * Copyright © 2006 Carl Worth
4 * This program is free software; you can redistribute it and\/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
19 #include "word-game.h"
26 static const char *subanagram_anagram;
27 static char subanagram_enumerate_word[WORD_GAME_MAX_WORD_LENGTH];
28 static dict_t *subanagram_enumerate_answers;
31 subanagram_enumerate (dict_cursor_t cursor,
38 if (cursor == DICT_CURSOR_NIL)
41 if (DICT_ENTRY_IS_WORD (dict_cursor_resolve (cursor)))
42 dict_add_word (subanagram_enumerate_answers, subanagram_enumerate_word);
44 last = strlen (subanagram_enumerate_word);
46 for (i = 0; i < strlen (subanagram_anagram); i++) {
49 next_seen = seen | (1 << i);
50 c = subanagram_anagram[i];
51 if (c == '?' || c == '_') {
52 for (c = 'a'; c <= 'z'; c++) {
53 subanagram_enumerate_word[last] = c;
54 subanagram_enumerate (dict_cursor_next (cursor, c), next_seen);
57 subanagram_enumerate_word[last] = c;
58 subanagram_enumerate (dict_cursor_next (cursor, c), next_seen);
60 subanagram_enumerate_word[last] = '\0';
65 subanagram_expand (const char *anagram, dict_t *dict, dict_t *answers)
67 subanagram_anagram = anagram;
68 memset (subanagram_enumerate_word, '\0', WORD_GAME_MAX_WORD_LENGTH);
69 subanagram_enumerate_answers = answers;
71 subanagram_enumerate (dict_root (dict), 0);
75 character_compare (const void *_a,
91 dict_t dict, solution;
96 gettimeofday (&tv, NULL);
97 srand (tv.tv_sec ^ tv.tv_usec);
102 memcpy (rack, bag.tiles, 7);
104 qsort (rack, 7, 1, character_compare);
107 dict_add_words_from_file (&dict, "words.txt");
109 dict_init (&solution);
110 subanagram_expand (rack, &dict, &solution);
112 word_game_play (rack, &dict, &solution, 0);
114 dict_fini (&solution);