Skip to content

Commit

Permalink
add indexing solutions from allowed guesses
Browse files Browse the repository at this point in the history
  • Loading branch information
Lana-chan committed Mar 13, 2023
1 parent a61b8a3 commit 106bd24
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
44 changes: 42 additions & 2 deletions Src/palmdle.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ static Boolean CheckValidAnswerID(UInt16 uiCheckID, const char* szCheckID) {
if (StrCompare(szTmp, szCheckID)) boolValid = false;

// NYT starts id at 1 not 0
if (uiCheckID - 1 >= ANSWER_COUNT) boolValid = false;
// v2.1: we are now pulling from allowed guesses as well
if (uiCheckID - 1 >= ANSWER_COUNT + ALLOWED_COUNT) boolValid = false;

if (!boolValid) {
FrmAlert(AlertInvalidID);
Expand Down Expand Up @@ -684,6 +685,41 @@ static void ShowIDInputForm(FormType* frmMain, PalmdleVars* pstVars) {
FrmDeleteForm(frmDialog);
}

/***************************
* Description: fetch word from allowed guesses list and populate solution word
* Input : pstVars - vars struct, game state must be enNoGame for new game
* Output : none
* Return : none
***************************/
static void FetchSolutionFromAllowed(PalmdleVars* pstVars) {
PalmdleGame* pstGame = &pstVars->stGame;

unsigned int uiWantedIndex = pstGame->uiCheckedIndex - ANSWER_COUNT;

unsigned int uiAllowedIndex = 0;
unsigned int uiAllowedCount = 0;
unsigned int i;
for (i = 0; i < ALLOWED_INDEX_COUNT; i++) {
uiAllowedCount += *(unsigned char*)(pstVars->allowed_idx_ptr + i);
if (uiAllowedCount >= uiWantedIndex) {
uiAllowedIndex = i;
break;
}
}

unsigned char ucAllowedWord[B26_LEN];
MemMove(ucAllowedWord, pstVars->allowed_ptr + (uiWantedIndex * (B26_LEN)), B26_LEN);
unsigned int uiAllowedWordInt = ucAllowedWord[0] << 8 | ucAllowedWord[1];

pstGame->szWord[0] = 'A' + (uiAllowedIndex / 26);
pstGame->szWord[1] = 'A' + (uiAllowedIndex % 26);
pstGame->szWord[4] = 'A' + (uiAllowedWordInt % 26);
uiAllowedWordInt /= 26;
pstGame->szWord[3] = 'A' + (uiAllowedWordInt % 26);
uiAllowedWordInt /= 26;
pstGame->szWord[2] = 'A' + (uiAllowedWordInt % 26);
}

/***************************
* Description: initialize game struct
* Input : pstVars - vars struct, game state must be enNoGame for new game
Expand Down Expand Up @@ -771,7 +807,11 @@ static void GameInit(PalmdleVars* pstVars, Boolean fIsDaily) {
}
}

MemMove(pstGame->szWord, pstVars->answer_ptr + pstGame->uiCheckedIndex * (WORD_LEN), WORD_LEN);
if (pstGame->uiCheckedIndex < ANSWER_COUNT) {
MemMove(pstGame->szWord, pstVars->answer_ptr + pstGame->uiCheckedIndex * (WORD_LEN), WORD_LEN);
} else {
FetchSolutionFromAllowed(pstVars);
}
pstGame->szWord[WORD_LEN] = (char)'\0';

pstVars->boolHideLetters = false;
Expand Down
2 changes: 1 addition & 1 deletion Src/palmdle.rcp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DATA "word" ID AllowedListFile "allowedlist.bin"
DATA "word" ID AllowedIndexFile "allowedindex.bin"
DATA "word" ID AnswerListFile "answerlist.bin"

VERSION "2.0.1"
VERSION "2.1"
ICON "assets/icon1bpp.bmp" "" "" "assets/icon8bpp.bmp" TRANSPARENT 254 0 254
LAUNCHERCATEGORY "Games"

Expand Down
2 changes: 1 addition & 1 deletion Src/strings.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define GAME_TITLE "Palmdle"
#define ABOUT_TITLE "Palmdle v2.0.1"
#define ABOUT_TITLE "Palmdle v2.1"
#define RANDOM_TITLE "Random"
#define ONLINE_TITLE "Online"
#define OFFLINE_TITLE "Classic"
Expand Down

0 comments on commit 106bd24

Please sign in to comment.