]> git.earman.xyz Git - sensor-watch.git/commitdiff
WORDLE_USE_DAILY_STREAK logic changed
authorDavid Volovskiy <devolov@gmail.com>
Tue, 27 Aug 2024 16:31:22 +0000 (12:31 -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

index 1cf931b41c122a5b4e8ba96e5e15ef18615485b8..bcab8f07bb8520d14293cb9905466c926af74911 100644 (file)
@@ -248,7 +248,7 @@ static void display_title(wordle_state_t *state) {
     show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen);
 }
 
-#if !WORDLE_USE_DAILY_STREAK
+#if WORDLE_USE_DAILY_STREAK != 2
 static void display_continue_result(bool continuing) {
     watch_display_string(continuing ? "y" : "n", 9);
 }
@@ -264,7 +264,7 @@ static void display_continue(wordle_state_t *state) {
 static void display_streak(wordle_state_t *state) {
     char buf[12];
     state->curr_screen = SCREEN_STREAK;
-#if WORDLE_USE_DAILY_STREAK
+#if WORDLE_USE_DAILY_STREAK != 2
     if (state->streak > 99)
         sprintf(buf, "WO  St--dy");
     else
@@ -277,7 +277,7 @@ static void display_streak(wordle_state_t *state) {
     show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen);
 }
 
-#if WORDLE_USE_DAILY_STREAK
+#if WORDLE_USE_DAILY_STREAK == 2
 static void display_wait(wordle_state_t *state) {
     state->curr_screen = SCREEN_WAIT;
     if (state->streak < 40) {
@@ -290,18 +290,15 @@ static void display_wait(wordle_state_t *state) {
     }
     show_skip_wrong_letter_indicator(state->skip_wrong_letter, state->curr_screen);
 }
+#endif
 
 static uint32_t get_day_unix_time(void) {
     watch_date_time now = watch_rtc_get_date_time();
+#if WORDLE_USE_DAILY_STREAK == 2
     now.unit.hour = now.unit.minute = now.unit.second = 0;
+#endif
     return watch_utility_date_time_to_unix_time(now, 0);
 }
-#else
-static uint32_t get_day_unix_time(void) {
-    watch_date_time now = watch_rtc_get_date_time();
-    return watch_utility_date_time_to_unix_time(now, 0);
-}
-#endif
 
 static void display_lose(wordle_state_t *state, uint8_t subsecond) {
     char buf[WORDLE_LENGTH + 6];
@@ -358,8 +355,8 @@ static bool act_on_btn(wordle_state_t *state, const uint8_t pin) {
         display_playing(state);
         return true;
     case SCREEN_TITLE:
-#if WORDLE_USE_DAILY_STREAK
-        if (state->prev_day == get_day_unix_time()) {
+#if WORDLE_USE_DAILY_STREAK == 2
+        if (state->day_last_game_started == get_day_unix_time()) {
             display_wait(state);
         }
         else if (is_playing(state))
@@ -376,7 +373,7 @@ static bool act_on_btn(wordle_state_t *state, const uint8_t pin) {
 #endif
         return true;
     case SCREEN_STREAK:
-        state->curr_day = get_day_unix_time();
+        state->day_last_game_started = get_day_unix_time();
         reset_board(state);
         return true;
     case SCREEN_WIN:
@@ -388,7 +385,7 @@ static bool act_on_btn(wordle_state_t *state, const uint8_t pin) {
         state->position = get_first_pos(state->word_elements_result);
         display_playing(state);
         return true;
-#if WORDLE_USE_DAILY_STREAK
+#if WORDLE_USE_DAILY_STREAK == 2
     case SCREEN_WAIT:
         (void) pin;
         display_title(state);
@@ -444,8 +441,8 @@ static void get_result(wordle_state_t *state) {
         state->curr_screen = SCREEN_WIN;
         if (state->streak < 0x7F)
             state->streak++;
-#if WORDLE_USE_DAILY_STREAK
-        state->prev_day = get_day_unix_time();
+#if WORDLE_USE_DAILY_STREAK == 2
+        state->day_last_game_started = get_day_unix_time();  // On the edge-case where we solve the puzzle at midnight
 #endif
         return;
     }
@@ -496,12 +493,10 @@ void wordle_face_setup(movement_settings_t *settings, uint8_t watch_face_index,
 void wordle_face_activate(movement_settings_t *settings, void *context) {
     (void) settings;
     wordle_state_t *state = (wordle_state_t *)context;
+#if WORDLE_USE_DAILY_STREAK != 0
     uint32_t now = get_day_unix_time();
-#if WORDLE_USE_DAILY_STREAK
-    if (state->curr_day != now) reset_all_elements(state);
-    if (now >= (state->prev_day + (60 *60 * 24))) state->streak = 0;
-#else
-    if (is_playing(state) && now >= (state->curr_day + (60 *60 * 24))) {
+    if (now >= (state->day_last_game_started + (60 *60 * 24)) &&
+        (is_playing(state) || WORDLE_USE_DAILY_STREAK == 2)) {
         state->streak = 0;
         reset_board(state);
     }
index ffb3782da585179b4cf44ffe7a9b72d35eb53e50..b035f140b7fc1b61f2929d6690554675d885a9e8 100644 (file)
 
 #define WORDLE_LENGTH 5
 #define WORDLE_MAX_ATTEMPTS 6
-#define WORDLE_USE_DAILY_STREAK false  // If true, the board will reset daily and the streak will go to zero if the game isn't played for a day
-                                       // If false, then the streak will still reset if the game is not completed within 24 hours
+/*  WORDLE_USE_DAILY_STREAK
+ *  0 = Don't ever reset the streak or the puzzle.
+ *  1 = Reset the streak and puzzle 24hrs after starting a puzzle and not finishing it.
+ *      If the last puzzle was started at 8AM, it'll be considered failed at 8AM the next day.
+ *  2 = Reset the streak and puzzle if a puzzle goes unsolved or not started a day after the previous one.
+ *      If the last puzzle was started at 8AM, it'll be considered failed at midnight the next day.
+ *      This will not be the case if the puzzle is started at 8AM, continued at 11:59PM and solved at 12:01AM, the game will let that slide.
+ *      Starting a new game instead of continuing is not allowed in this state.
+*/
+#define WORDLE_USE_DAILY_STREAK 1
 #define WORDLE_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.
 /*  WORDLE_USE_RANDOM_GUESS
  *  0 = Don't allow quickly choosing a random quess
@@ -120,10 +128,7 @@ typedef struct {
     uint8_t streak;
     WordleScreen curr_screen;
     bool known_wrong_letters[WORDLE_NUM_VALID_LETTERS];
-    uint32_t curr_day;
-#if WORDLE_USE_DAILY_STREAK
-    uint32_t prev_day;
-#endif
+    uint32_t day_last_game_started;
 } wordle_state_t;
 
 void wordle_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);