From: Carl Worth Date: Fri, 29 Sep 2006 03:41:05 +0000 (-0700) Subject: grid: Rename "board" to "grid" X-Git-Url: https://git.cworth.org/git?p=wordgame;a=commitdiff_plain;h=bcb7792b716e8903450e023cd4648fb89a6434ce grid: Rename "board" to "grid" --- diff --git a/grid.c b/grid.c index fe3d540..8f30a1b 100644 --- a/grid.c +++ b/grid.c @@ -30,12 +30,12 @@ char *cube_faces[16] = { "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) @@ -58,7 +58,7 @@ shuffle (int *array, int length) } static void -board_init (board_t *board) +grid_init (grid_t *grid) { int i; int cubes[16]; @@ -68,28 +68,28 @@ board_init (board_t *board) 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') @@ -105,12 +105,12 @@ board_to_string (board_t *board, #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; @@ -127,7 +127,7 @@ board_enumerate (board_t *board, 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); @@ -139,12 +139,12 @@ board_enumerate (board_t *board, 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'; @@ -152,19 +152,19 @@ board_enumerate (board_t *board, } 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) @@ -172,8 +172,8 @@ int 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); @@ -182,13 +182,13 @@ main (void) 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);