]> git.earman.xyz Git - sensor-watch.git/commitdiff
Added ability to guess non-dict words and repeats as that can save 11.5KB of watch...
authorDavid Volovskiy <devolov@gmail.com>
Sun, 25 Aug 2024 11:15:08 +0000 (07:15 -0400)
committerDavid Volovskiy <devolov@gmail.com>
Tue, 3 Sep 2024 20:11:54 +0000 (16:11 -0400)
movement/watch_faces/complication/wordle_face.c
movement/watch_faces/complication/wordle_face.h
movement/watch_faces/complication/wordle_face_dict.h
utils/wordle_face/wordle_list.py

index 9ce29bdf62c72c1f49060da962d0e2f814b9c839..f44e4a66615895b44a1cd9e97dd4c57a72c0c416 100644 (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);
index 6ae1fbd839b77157150fac7b6a9177ea5232b076..52fd71f66fa71f335f394fc5a36344dcf028b541 100644 (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;
index 1942b16e85b30c8430eaddc555067aa791eb686d..00ae3ac3c7a6472c0ae5faf4f07c91c36d4430bc 100644 (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)
index d951bac998ed1d5f236307b82629e1862027b9a8..68481e02922ae7f9924e41f522ef42cae1e9ff6a 100644 (file)
@@ -1156,6 +1156,17 @@ def print_valid_words(letters=alphabet):
     '''\r
     Prints the array of valid words that the wordle_face.c can use\r
     '''\r
+    print("#ifndef WORDLE_FACE_DICT_H_")\r
+    print("#define WORDLE_FACE_DICT_H_")\r
+\r
+    print("\n#ifndef WORDLE_LENGTH")\r
+    print("#define WORDLE_LENGTH 5")\r
+    print("#endif")\r
+\r
+    print("\n#ifndef USE_RANDOM_GUESS")\r
+    print("#define USE_RANDOM_GUESS 2")\r
+    print("#endif\n")\r
+    \r
     items_per_row = 9\r
     valid_words = list_of_valid_words(letters, valid_list)\r
     valid_words = capitalize_all_and_remove_duplicates(valid_words)\r
@@ -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.")\r
     print(f"// Number of words found: {len(possible_words)}")\r
     print("static const char _possible_words[][WORDLE_LENGTH + 1] = {")\r
+    print("#if !ALLOW_NON_WORD_AND_REPEAT_GUESSES")\r
     i = 0\r
     while i < len(possible_words):\r
         print("    ", end='')\r
@@ -1193,10 +1205,15 @@ def print_valid_words(letters=alphabet):
             print(f'"{clean_chars(possible_words[i])}", ', end='')\r
             i+=1\r
         print('')\r
-    print("};")\r
-    print('')\r
+    print("#endif")\r
+    print("};\n")\r
     \r
-    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.")\r
+    print("#if (USE_RANDOM_GUESS == 2)")\r
+    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.")\r
+    print("#elif (USE_RANDOM_GUESS == 1)")\r
+    print("static const uint16_t _num_random_guess_words = _num_words;")\r
+    print("#endif")\r
+    print("\n#endif // WORDLE_FACE_DICT_H_")\r
 \r
 \r
 def get_sec_val_and_units(seconds):\r