Skip to content

Commit

Permalink
refactor: relocate guess hitmap generation
Browse files Browse the repository at this point in the history
## Why
Player guess hitmap was only being generated after checking if the guess
was correct which lead to the guess hitmap not being generated at all if
the guess was right on the first time, preventing it from being
rendered.
## How
By relocating the guess hitmap generation, generating it regardless of
it being the correct guess or not.
  • Loading branch information
rccsousa committed Nov 7, 2024
1 parent 4225686 commit 9ec05ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
File renamed without changes.
14 changes: 14 additions & 0 deletions powershell_scripts/extract_abis.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# PowerShell script to extract contract ABIs from smart contracts using forge inspect

param(
[Parameter(Mandatory=$true)]
[string]$contract,

[Parameter(Mandatory=$true)]
[string]$path
)

$command = "forge inspect $contract abi | Set-Content -Path $path -Encoding UTF8"

Write-Host "Executing command: $command"
Invoke-Expression $command
8 changes: 5 additions & 3 deletions src/Wordle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,17 @@ contract Wordle {
return false;
}

// Initiate a hitmap for the guess, even if its the correct one,
// to render it on the frontend
StructTypes.CharState[] memory guessHitmap = StringUtils.generateHitmap(guess);

if (StringUtils.areEqual(guess, HIDDEN_WORD)) {
emit CorrectGuess(guess, "Well done!");
return true;
}

emit RemainingAttempts(ATTEMPTS[player], "Attempts left.");
ATTEMPTS[player]--;

StructTypes.CharState[] memory guessHitmap = StringUtils.generateHitmap(guess);
ATTEMPTS[player]--;

// Check if the guess matches the hidden word immediately.
if (StringUtils.areEqual(guess, HIDDEN_WORD)) {
Expand Down

0 comments on commit 9ec05ba

Please sign in to comment.