X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=word-game.c;h=2b9fa4e1e3df481096778425c9a1092a9d06b41c;hb=76c92c2f9f062d3bc3cbbf57416fe6b23f1d114b;hp=8c9af9a59071feda5567f90cfecea9f014f32083;hpb=a6f9c10c08f706c3c25ab81fef956339490e50f3;p=wordgame diff --git a/word-game.c b/word-game.c index 8c9af9a..2b9fa4e 100644 --- a/word-game.c +++ b/word-game.c @@ -57,6 +57,24 @@ _count_possible (dict_cursor_t cursor, _count_possible (dict_cursor_next (cursor, c), depth + 1, possible); } +static void +_print_stats (int found[WORD_GAME_MAX_WORD_LENGTH+1], + int possible[WORD_GAME_MAX_WORD_LENGTH+1], + int found_total, + int possible_total) +{ + int i; + + for (i = 2; i <= 17; i++) + if (possible[i]) + printf ("%d:(%d/%d) ", i, found[i], possible[i]); + + printf ("total:(%d/%d = %.2f%%)\n", + found_total, possible_total, + 100 * (double) found_total / possible_total); +} + + void word_game_play (const char *puzzle, dict_t *dict, @@ -82,7 +100,7 @@ word_game_play (const char *puzzle, for (i=0; i < 17; i++) possible_total += possible[i]; - printf ("%s\n\n", puzzle); + printf ("%s\n", puzzle); just_saw_puzzle = TRUE; remaining = time_limit_seconds; @@ -105,15 +123,10 @@ word_game_play (const char *puzzle, break; if (strlen (response) == 0) { if (! just_saw_puzzle) { - printf ("%s\n\n", puzzle); + printf ("%s\n", puzzle); just_saw_puzzle = TRUE; } else { - for (i = 2; i <= 17; i++) - if (possible[i]) - printf ("%d:(%d/%d) ", i, found[i], possible[i]); - printf ("total:(%d/%d = %.2f%%)\n", - found_total, possible_total, - 100 * (double) found_total / possible_total); + _print_stats (found, possible, found_total, possible_total); } } else { dict_entry_t *entry; @@ -146,14 +159,23 @@ word_game_play (const char *puzzle, } } while (remaining > 0); - printf ("%s\n\n", puzzle); + printf ("\n%s\n", puzzle); - printf ("Words you found:\n"); - dict_print_by_length_if (answers, seen_predicate); - - printf ("\nWords you missed:\n"); - dict_print_by_length_if (answers, unseen_predicate); printf ("\n"); + _print_stats (found, possible, found_total, possible_total); + printf ("\n"); + + if (found_total) { + printf ("Words you found:\n"); + dict_print_by_length_if (answers, seen_predicate); + printf ("\n"); + } + + if (found_total < possible_total) { + printf ("Words you missed:\n"); + dict_print_by_length_if (answers, unseen_predicate); + printf ("\n"); + } printf ("You found %d of %d words (%.2f%%)\n", found_total, possible_total,