Added ability to guess non-dict words and repeats as that can save 11.5KB of watch memory

This commit is contained in:
David Volovskiy 2024-08-25 07:15:08 -04:00
parent 5149e7e1dd
commit 0d16d126cd
4 changed files with 43 additions and 13 deletions

View file

@ -95,6 +95,17 @@ static void display_all_letters(wordle_state_t *state) {
state->position = prev_pos;
}
#if !ALLOW_NON_WORD_AND_REPEAT_GUESSES
static void display_not_in_dict(wordle_state_t *state) {
state->curr_screen = SCREEN_NO_DICT;
watch_display_string("nodict", 4);
}
static void display_already_guessed(wordle_state_t *state) {
state->curr_screen = SCREEN_ALREADY_GUESSED;
watch_display_string("GUESSD", 4);
}
static uint32_t check_word_in_dict(uint8_t *word_elements) {
bool is_exact_match;
for (uint16_t i = 0; i < _num_words; i++) {
@ -120,6 +131,9 @@ static uint32_t check_word_in_dict(uint8_t *word_elements) {
return _num_words + _num_possible_words;
}
#endif
static bool check_word(wordle_state_t *state) {
// Exact
bool is_exact_match = true;
@ -167,9 +181,11 @@ static void reset_all_elements(wordle_state_t *state) {
state->word_elements[i] = _num_valid_letters;
state->word_elements_result[i] = WORDLE_LETTER_WRONG;
}
#if !ALLOW_NON_WORD_AND_REPEAT_GUESSES
for (size_t i = 0; i < WORDLE_MAX_ATTEMPTS; i++) {
state->guessed_words[i] = _num_words + _num_possible_words;
}
#endif
state->using_random_guess = false;
state->attempt = 0;
}
@ -245,16 +261,6 @@ static uint32_t get_day_unix_time(void) {
}
#endif
static void display_not_in_dict(wordle_state_t *state) {
state->curr_screen = SCREEN_NO_DICT;
watch_display_string("nodict", 4);
}
static void display_already_guessed(wordle_state_t *state) {
state->curr_screen = SCREEN_ALREADY_GUESSED;
watch_display_string("GUESSD", 4);
}
static void display_lose(wordle_state_t *state, uint8_t subsecond) {
char buf[WORDLE_LENGTH + 6];
sprintf(buf," L %s", subsecond % 2 ? _valid_words[state->curr_answer] : " ");
@ -373,6 +379,7 @@ static bool act_on_btn(wordle_state_t *state, const uint8_t pin) {
}
static void get_result(wordle_state_t *state) {
#if !ALLOW_NON_WORD_AND_REPEAT_GUESSES
// Check if it's in the dict
uint16_t in_dict = check_word_in_dict(state->word_elements);
if (in_dict == _num_words + _num_possible_words) {
@ -389,6 +396,7 @@ static void get_result(wordle_state_t *state) {
}
state->guessed_words[state->attempt] = in_dict;
#endif
bool exact_match = check_word(state);
if (exact_match) {
reset_all_elements(state);

View file

@ -63,6 +63,7 @@
#define WORDLE_LENGTH 5
#define WORDLE_MAX_ATTEMPTS 6
#define USE_DAILY_STREAK false
#define ALLOW_NON_WORD_AND_REPEAT_GUESSES false // This allows non-words to be entered and repeat guesses to be made. It saves ~11.5KB of ROM.
/* USE_RANDOM_GUESS
* 0 = Don't allow quickly choosing a random quess
@ -103,7 +104,9 @@ typedef struct {
// Anything you need to keep track of, put it here!
uint8_t word_elements[WORDLE_LENGTH];
WordleLetterResult word_elements_result[WORDLE_LENGTH];
#if !ALLOW_NON_WORD_AND_REPEAT_GUESSES
uint16_t guessed_words[WORDLE_MAX_ATTEMPTS];
#endif
uint8_t attempt : 4;
uint8_t position : 3;
bool using_random_guess : 1;

View file

@ -67,6 +67,7 @@ static const char _valid_words[][WORDLE_LENGTH + 1] = {
// These are words that'll never be used, but still need to be in the dictionary for guesses.
// Number of words found: 1898
static const char _possible_words[][WORDLE_LENGTH + 1] = {
#if !ALLOW_NON_WORD_AND_REPEAT_GUESSES
"AALII", "AARTI", "ACAIS", "ACARI", "ACCAS", "ACERS", "ACETA", "ACHAR", "ACHES",
"ACHOO", "ACINI", "ACNES", "ACRES", "ACROS", "ACTIN", "ACTON", "AECIA", "AEONS",
"AERIE", "AEROS", "AESIR", "AHEAP", "AHENT", "AHINT", "AINEE", "AIOLI", "AIRER",
@ -278,6 +279,7 @@ static const char _possible_words[][WORDLE_LENGTH + 1] = {
"TRATT", "TREEN", "TREES", "TRESS", "TREST", "TRETS", "TRIAC", "TRIER", "TRIES",
"TRILL", "TRINE", "TRINS", "TRIOL", "TRIOR", "TRIOS", "TRIPS", "TRIST", "TROAT",
"TROIS", "TRONA", "TRONC", "TRONE", "TRONS", "TROTH", "TROTS", "TSARS",
#endif
};
#if (USE_RANDOM_GUESS == 2)

View file

@ -1156,6 +1156,17 @@ def print_valid_words(letters=alphabet):
'''
Prints the array of valid words that the wordle_face.c can use
'''
print("#ifndef WORDLE_FACE_DICT_H_")
print("#define WORDLE_FACE_DICT_H_")
print("\n#ifndef WORDLE_LENGTH")
print("#define WORDLE_LENGTH 5")
print("#endif")
print("\n#ifndef USE_RANDOM_GUESS")
print("#define USE_RANDOM_GUESS 2")
print("#endif\n")
items_per_row = 9
valid_words = list_of_valid_words(letters, valid_list)
valid_words = capitalize_all_and_remove_duplicates(valid_words)
@ -1186,6 +1197,7 @@ def print_valid_words(letters=alphabet):
print("\n// These are words that'll never be used, but still need to be in the dictionary for guesses.")
print(f"// Number of words found: {len(possible_words)}")
print("static const char _possible_words[][WORDLE_LENGTH + 1] = {")
print("#if !ALLOW_NON_WORD_AND_REPEAT_GUESSES")
i = 0
while i < len(possible_words):
print(" ", end='')
@ -1193,10 +1205,15 @@ def print_valid_words(letters=alphabet):
print(f'"{clean_chars(possible_words[i])}", ', end='')
i+=1
print('')
print("};")
print('')
print("#endif")
print("};\n")
print(f"\nstatic const uint16_t _num_unique_words = {num_uniq}; // The _valid_words array begins with this many words where each letter is different.")
print("#if (USE_RANDOM_GUESS == 2)")
print(f"static const uint16_t _num_random_guess_words = {num_uniq}; // The _valid_words array begins with this many words where each letter is different.")
print("#elif (USE_RANDOM_GUESS == 1)")
print("static const uint16_t _num_random_guess_words = _num_words;")
print("#endif")
print("\n#endif // WORDLE_FACE_DICT_H_")
def get_sec_val_and_units(seconds):