"eiosst", "elrtty", "himnqu", "hlnnrz"
};
-typedef struct _board {
+typedef struct _grid {
char letters[4][4];
/* Private, transient state used by enumerate */
dict_t *results;
-} board_t;
+} grid_t;
static int
rand_within (int num_values)
}
static void
-board_init (board_t *board)
+grid_init (grid_t *grid)
{
int i;
int cubes[16];
shuffle (cubes, 16);
for (i = 0; i < 16; i++)
- board->letters[i / 4][i % 4] = cube_faces[cubes[i]][rand_within(6)];
+ 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 board
+ * ) x 4 rows per grid
* + 1 terminator character
* = 53
*/
-#define BOARD_STRING_MAX 53
+#define GRID_STRING_MAX 53
static void
-board_to_string (board_t *board,
- char board_string[BOARD_STRING_MAX])
+grid_to_string (grid_t *grid,
+ char grid_string[GRID_STRING_MAX])
{
char c;
int x, y;
- char *s = &board_string[0];
+ char *s = &grid_string[0];
for (y = 0; y < 4; y++) {
for (x = 0; x < 4; x++) {
- c = board->letters[y][x];
+ c = grid->letters[y][x];
*s++ = ' ';
*s++ = toupper (c);
if (c == 'q')
#define SEEN_BIT(x, y) (1 << (4*(y)+(x)))
static void
-board_enumerate (board_t *board,
- int x,
- int y,
- int16_t seen,
- char *word,
- dict_cursor_t dict_cursor)
+grid_enumerate (grid_t *grid,
+ int x,
+ int y,
+ int16_t seen,
+ char *word,
+ dict_cursor_t dict_cursor)
{
char c;
int dx, dy;
seen |= SEEN_BIT (x, y);
- c = board->letters[y][x];
+ c = grid->letters[y][x];
word[strlen (word)] = c;
dict_cursor = dict_cursor_next (dict_cursor, c);
if (strlen (word) > 2 &&
DICT_ENTRY_IS_WORD (dict_cursor_resolve (dict_cursor)))
{
- dict_add_word (board->results, word);
+ dict_add_word (grid->results, word);
}
for (dy = -1; dy <= 1; dy++)
for (dx = -1; dx <= 1; dx++)
- board_enumerate (board, x + dx, y + dy, seen, word, dict_cursor);
+ grid_enumerate (grid, x + dx, y + dy, seen, word, dict_cursor);
if (c == 'q')
word [strlen (word) - 1] = '\0';
}
static void
-board_solve (board_t *board, dict_t *dict, dict_t *solution)
+grid_solve (grid_t *grid, dict_t *dict, dict_t *solution)
{
int x, y;
int16_t seen = 0;
char word[18];
- board->results = solution;
+ grid->results = solution;
memset (word, '\0', 18);
for (y = 0; y < 4; y++)
for (x = 0; x < 4; x++)
- board_enumerate (board, x, y, seen, word, dict_root (dict));
+ grid_enumerate (grid, x, y, seen, word, dict_root (dict));
}
#define GAME_LENGTH (3 * 60)
main (void)
{
dict_t dict, solution;
- board_t board;
- char board_string[BOARD_STRING_MAX];
+ grid_t grid;
+ char grid_string[GRID_STRING_MAX];
struct timeval tv;
gettimeofday (&tv, NULL);
dict_init (&dict);
dict_add_words_from_file (&dict, "words.txt");
- board_init (&board);
- board_to_string (&board, board_string);
+ grid_init (&grid);
+ grid_to_string (&grid, grid_string);
dict_init (&solution);
- board_solve (&board, &dict, &solution);
+ grid_solve (&grid, &dict, &solution);
- word_game_play (board_string, &dict, &solution, GAME_LENGTH);
+ word_game_play (grid_string, &dict, &solution, GAME_LENGTH);
dict_fini (&solution);
dict_fini (&dict);