#include <stdlib.h>
#include <string.h>
#include "wordle_face.h"
+#if USE_DAILY_STREAK
+#include "watch_utility.h"
+#endif
/*
TODO:
* Add quick iteration (8x freq to get to the letter we want)
* Fix the word matching (if answer is AAAAA and we put in AACAA, the C blinks)
-* Verify pressing back always work when the board is G_G_G
-* Add daily streak and wait for next day
-* Add a way tpo recount previous attempts
+* Add a way to recount previous attempts
*/
U | 514 P has more words with the other letters here (281 vs 198)
P | 448
*/
-static const char _valid_letters[] = {'E', 'S', 'A', 'R', 'O', 'L', 'I', 'N', 'C', 'P'};
+static const char _valid_letters[] = {'A', 'C', 'E', 'I', 'L', 'N', 'O', 'P', 'R', 'S'};
// Number of words found: 281
static const char _legal_words[][WORDLE_LENGTH + 1] = {
}
static bool check_word(wordle_state_t *state) {
-
+ WordleLetterResult checked_letter_in_answer[WORDLE_LENGTH] = {WORDLE_LETTER_WRONG};
// Exact
bool is_exact_match = true;
for (size_t i = 0; i < WORDLE_LENGTH; i++) {
- if (_valid_letters[state->word_elements[i]] == _legal_words[state->curr_answer][i])
- state->word_elements_result[i] = WORDLE_LETTER_CORRECT;
+ if (_valid_letters[state->word_elements[i]] == _legal_words[state->curr_answer][i]) {
+ state->word_elements_result[i] = checked_letter_in_answer[i] = WORDLE_LETTER_CORRECT;
+ }
else {
state->word_elements_result[i] = WORDLE_LETTER_WRONG;
is_exact_match = false;
// Wrong Location
for (size_t i = 0; i < WORDLE_LENGTH; i++) {
for (size_t j = 0; j < WORDLE_LENGTH; j++) {
- if (state->word_elements_result[j] != WORDLE_LETTER_WRONG) continue;
+ if (checked_letter_in_answer[j] != WORDLE_LETTER_WRONG) continue;
if (_valid_letters[state->word_elements[i]] == _legal_words[state->curr_answer][j]) {
printf("me: %c them: %c\r\n", _valid_letters[state->word_elements[i]], _legal_words[state->curr_answer][j]);
- state->word_elements_result[j] = WORDLE_LETTER_WRONG_LOC;
+ state->word_elements_result[i] = checked_letter_in_answer[j] = WORDLE_LETTER_WRONG_LOC;
break;
}
}
static void display_streak(wordle_state_t *state) {
char buf[12];
state->curr_screen = SCREEN_STREAK;
- printf("streak %d \r\n", state->streak);
+#if USE_DAILY_STREAK
sprintf(buf, "WO St%2ddy", state->streak);
+#else
+ sprintf(buf, "WO St%4d", state->streak);
+#endif
watch_display_string(buf, 0);
watch_set_colon();
}
+#if USE_DAILY_STREAK
+static void display_wait(wordle_state_t *state) {
+ state->curr_screen = SCREEN_WAIT;
+ if (state->streak < 40) {
+ char buf[13];
+ sprintf(buf,"WO%2d WaIt ", state->streak);
+ watch_display_string(buf, 0);
+ }
+ else { // Streak too long to display in top-right
+ watch_display_string("WO WaIt ", 0);
+ }
+}
+#endif
+
static void display_lose(wordle_state_t *state, uint8_t subsecond) {
char buf[WORDLE_LENGTH + 6];
sprintf(buf," L %s", subsecond % 2 ? _legal_words[state->curr_answer] : " ");
}
static uint8_t get_next_pos(uint8_t curr_pos, WordleLetterResult *word_elements_result) {
- uint8_t pos = curr_pos;
- do {
- pos++;
- if (pos > WORDLE_LENGTH) return WORDLE_LENGTH + 1;
- } while (word_elements_result[pos] == WORDLE_LETTER_CORRECT);
- return pos;
+ for (size_t pos = curr_pos+1; pos < WORDLE_LENGTH; pos++) {
+ if (word_elements_result[pos] != WORDLE_LETTER_CORRECT)
+ return pos;
+ }
+ return WORDLE_LENGTH;
}
static uint8_t get_prev_pos(uint8_t curr_pos, WordleLetterResult *word_elements_result) {
- int8_t pos = curr_pos;
- do {
- pos--;
- if (pos < 0) return curr_pos;
- } while (word_elements_result[pos] == WORDLE_LETTER_CORRECT);
- return pos;
+ if (curr_pos == 0) return 0;
+ for (int8_t pos = curr_pos-1; pos >= 0; pos--) {
+ if (word_elements_result[pos] != WORDLE_LETTER_CORRECT)
+ return pos;
+ }
+ return curr_pos;
}
+#if USE_DAILY_STREAK
+static uint32_t get_day_unix_time(void) {
+ watch_date_time now = watch_rtc_get_date_time();
+ now.unit.hour = now.unit.minute = now.unit.second = 0;
+ return watch_utility_date_time_to_unix_time(now, 0);
+}
+#endif
+
static void display_result(wordle_state_t *state, uint8_t subsecond) {
char buf[WORDLE_LENGTH + 1];
for (size_t i = 0; i < WORDLE_LENGTH; i++)
state->curr_screen = SCREEN_PLAYING;
return true;
case SCREEN_TITLE:
+#if USE_DAILY_STREAK
+ if (state->prev_day == get_day_unix_time()) {
+ display_wait(state);
+ return true;
+ }
+#endif
display_streak(state);
return true;
case SCREEN_STREAK:
case SCREEN_WIN:
case SCREEN_LOSE:
display_title(state);
- return true;
+ return true;
+#if USE_DAILY_STREAK
+ case SCREEN_WAIT:
+ display_title(state);
+ return true;
+#endif
default:
return false;
}
memset(*context_ptr, 0, sizeof(wordle_state_t));
wordle_state_t *state = (wordle_state_t *)*context_ptr;
state->curr_screen = SCREEN_TITLE;
-
}
// Do any pin or peripheral setup here; this will be called whenever the watch wakes from deep sleep.
}
(void) settings;
wordle_state_t *state = (wordle_state_t *)context;
movement_request_tick_frequency(2);
+#if USE_DAILY_STREAK
+ if (state->prev_day <= (get_day_unix_time() + (60 *60 * 24))) state->streak = 0;
+#endif
if (state->curr_screen == SCREEN_TITLE)
display_title(state);
}
display_letter(state, true);
if (state->word_elements[state->position] == _num_valid_letters) break;
state->position = get_next_pos(state->position, state->word_elements_result);
- if(WORDLE_LENGTH == (state->position)) {
+ if (state->position >= WORDLE_LENGTH) {
bool exact_match = check_word(state);
if (exact_match) {
state->curr_screen = SCREEN_WIN;
state->streak++;
+#if USE_DAILY_STREAK
+ state->prev_day = get_day_unix_time();
+#endif
break;
}
if (state->attempt++ >= WORDLE_MAX_ATTEMPTS) {