]> git.cworth.org Git - wordgame/blob - rack.c
Ensure that there's at least one full-length word that's not obscure
[wordgame] / rack.c
1 /*
2  * Copyright © 2006 Carl Worth
3  *
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)
7  * any later version.
8  *
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.
13  *
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."
17  */
18
19 #include "word-game.h"
20
21 #include <string.h>
22 #include <ctype.h>
23 #include <sys/time.h>
24 #include <time.h>
25
26 static int
27 character_compare (const void *_a,
28                    const void *_b)
29 {
30     const char *a = _a;
31     const char *b = _b;
32
33     if (*a == '?')
34         return 1;
35     if (*b == '?')
36         return -1;
37     return *a - *b;
38 }
39
40 int
41 main (void)
42 {
43     dict_t dict, solution;
44     struct timeval tv;
45     bag_t bag;
46     char rack[8];
47
48     gettimeofday (&tv, NULL);
49     srand (tv.tv_sec ^ tv.tv_usec);
50
51     bag_init (&bag);
52     bag_shuffle (&bag);
53
54     memcpy (rack, bag.tiles, 7);
55     rack[7] = '\0';
56     qsort (rack, 7, 1, character_compare);
57
58     dict_init (&dict);
59     dict_add_words_from_file (&dict, "words.txt");
60
61     dict_init (&solution);
62     subanagram_expand (rack, &dict, &solution);
63
64     word_game_play (rack, &dict, &solution, 0);
65
66     dict_fini (&solution);
67     dict_fini (&dict);
68
69     return 0;
70 }