X-Git-Url: https://git.cworth.org/git?p=wordgame;a=blobdiff_plain;f=rack-fancy.c;fp=rack-fancy.c;h=fbc6e119a471df41aadef06008cde4a2d3aecb8f;hp=8659d9ac9f3e09dcfb70cc13f0adeba95991c22d;hb=0a8d1f741a919c9c7e5ae0b8d0261759cca9bc05;hpb=98a8ac80d3f904b6502b39e093d473b8d4d4b246 diff --git a/rack-fancy.c b/rack-fancy.c index 8659d9a..fbc6e11 100644 --- a/rack-fancy.c +++ b/rack-fancy.c @@ -354,13 +354,22 @@ _flag_obscure_word (void *closure, char *word, dict_entry_t *entry) *entry |= RACK_DICT_ENTRY_OBSCURE; } +static void +_at_least_one_is_not_obscure (void *closure, char *word, dict_entry_t *entry) +{ + int *result = closure; + + if ((*entry & RACK_DICT_ENTRY_OBSCURE) == 0) + *result = 1; +} + static void rack_new_game (rack_t *rack) { int i, bottom; char word[MAX_TILES + 1]; int length = MAX_TILES; - int count; + int has_full_length_non_obscure_word; /* We'll shuffle as many times as necessary until we can find a * sequence of letters with at least one full-length @@ -382,24 +391,29 @@ rack_new_game (rack_t *rack) } } + /* Look at each successive run of tiles in the bag until + * finding one that has at least one non-obscure word using + * all of its leters. */ for (i = 0; i + length <= bottom + 1; i++) { memcpy (word, &rack->bag.tiles[i], length); word[length] = '\0'; dict_fini (&rack->solution); dict_init (&rack->solution); subanagram_expand (word, &rack->dict, &rack->solution); - count = dict_for_each_of_length (&rack->solution, - NULL, NULL, - length, length); - if (count) + dict_for_each (&rack->solution, + _flag_obscure_word, &rack->obscure); + has_full_length_non_obscure_word = 0; + dict_for_each_of_length (&rack->solution, + _at_least_one_is_not_obscure, + &has_full_length_non_obscure_word, + length, length); + if (has_full_length_non_obscure_word) goto DONE; i++; } } DONE: - dict_for_each (&rack->solution, - _flag_obscure_word, &rack->obscure); rack->solution_total = dict_count (&rack->solution); goo_canvas_item_simple_changed (GOO_CANVAS_ITEM_SIMPLE (rack->solution_item), FALSE);