* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
*/
-#include "word-game.h"
+#include "grid.h"
#include <string.h>
#include <ctype.h>
-#include <sys/time.h>
-#include <time.h>
char *cube_faces[16] = {
"aaeeng", "abbjoo", "achops", "affkps",
"eiosst", "elrtty", "himnqu", "hlnnrz"
};
-typedef struct _grid {
- char letters[4][4];
-
- /* Private, transient state used by enumerate */
- dict_t *results;
-} grid_t;
-
static int
rand_within (int num_values)
{
}
}
-static void
+void
grid_init (grid_t *grid)
{
int i;
grid->letters[i / 4][i % 4] = cube_faces[cubes[i]][rand_within(6)];
}
-/* ( 3 chars per cell
- * x 4 cells per row
- * + 1 newline per row
- * ) x 4 rows per grid
- * + 1 terminator character
- * = 53
- */
-#define GRID_STRING_MAX 53
-static void
-grid_to_string (grid_t *grid,
- char grid_string[GRID_STRING_MAX])
+char *
+grid_string (grid_t *grid)
{
char c;
int x, y;
- char *s = &grid_string[0];
+ char *s = grid->string;
for (y = 0; y < 4; y++) {
for (x = 0; x < 4; x++) {
*s++ = '\n';
}
*s = '\0';
+
+ return grid->string;
}
#define SEEN_BIT(x, y) (1 << (4*(y)+(x)))
word [strlen (word) - 1] = '\0';
}
-static void
+void
grid_solve (grid_t *grid, dict_t *dict, dict_t *solution)
{
int x, y;
for (x = 0; x < 4; x++)
grid_enumerate (grid, x, y, seen, word, dict_root (dict));
}
-
-#define GAME_LENGTH (3 * 60)
-int
-main (void)
-{
- dict_t dict, solution;
- grid_t grid;
- char grid_string[GRID_STRING_MAX];
- struct timeval tv;
-
- gettimeofday (&tv, NULL);
- srand (tv.tv_sec ^ tv.tv_usec);
-
- dict_init (&dict);
- dict_add_words_from_file (&dict, "words.txt");
-
- grid_init (&grid);
- grid_to_string (&grid, grid_string);
-
- dict_init (&solution);
- grid_solve (&grid, &dict, &solution);
-
- word_game_play (grid_string, &dict, &solution, GAME_LENGTH);
-
- dict_fini (&solution);
- dict_fini (&dict);
-
- return 0;
-}