hangman: fix display never showing guessed letters + improve word-guess feedback
Lint / Shell (shellcheck) (push) Successful in 9s
Lint / JS (eslint) (push) Successful in 6s
Lint / Python (ruff) (push) Successful in 5s
Lint / Python deps (pip-audit) (push) Successful in 44s
Lint / Secret scan (gitleaks) (push) Successful in 4s

- _hangman_display compared uppercase word chars against lowercase
  guessed_letters set, so letters were never revealed after correct guesses
- Word guess wrong path now shows the board and remaining guesses
- Winner display now includes the guesser's name on correct word guess

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-22 01:04:27 -04:00
parent c9d9febbe0
commit 115749e232
+19 -7
View File
@@ -1226,8 +1226,8 @@ _HANGMAN_STAGES = [
def _hangman_display(game: dict) -> str: def _hangman_display(game: dict) -> str:
word = game["word"] word = game["word"]
guessed = game["guessed_letters"] guessed = game["guessed_letters"] # stored lowercase
return " ".join(c if c in guessed else "_" for c in word.upper()) return " ".join(c if c.lower() in guessed else "_" for c in word.upper())
async def _generate_hangman_word() -> dict | None: async def _generate_hangman_word() -> dict | None:
@@ -1340,24 +1340,36 @@ async def cmd_guess(client: AsyncClient, room_id: str, sender: str, args: str):
# Full word guess # Full word guess
if len(guess) > 1: if len(guess) > 1:
winner = sender.split(":")[0].lstrip("@")
if guess == word: if guess == word:
del _HANGMAN_GAMES[room_id] del _HANGMAN_GAMES[room_id]
plain = f"🎉 {sender.split(':')[0].lstrip('@')} got it! The word was: {word.upper()}" plain = f"🎉 {winner} got it! The word was: {word.upper()}"
html = ( html = (
f'<font color="#22c55e"><strong>🎉 Correct! The word was: {word.upper()}</strong></font><br>' f'<font color="#22c55e"><strong>🎉 {winner} got it! The word was: {word.upper()}</strong></font>'
f'Guessed by {sender.split(":")[0].lstrip("@")}!'
) )
await send_html(client, room_id, plain, html) await send_html(client, room_id, plain, html)
else: else:
game["wrong_count"] += 1 game["wrong_count"] += 1
display = _hangman_display(game)
if game["wrong_count"] >= 6: if game["wrong_count"] >= 6:
del _HANGMAN_GAMES[room_id] del _HANGMAN_GAMES[room_id]
plain = f"Wrong! Game over — the word was: {word.upper()}" plain = f"'{guess.upper()}' is wrong! Game over — the word was: {word.upper()}"
html = f'<font color="#ef4444"><strong>❌ Wrong! Game over — the word was: {word.upper()}</strong></font>' html = f'<font color="#ef4444"><strong>❌ Wrong! Game over — the word was: {word.upper()}</strong></font>'
await send_html(client, room_id, plain, html) await send_html(client, room_id, plain, html)
else: else:
remaining = 6 - game["wrong_count"] remaining = 6 - game["wrong_count"]
await send_text(client, room_id, f"'{guess.upper()}' is wrong! {remaining} wrong guesses remaining.") plain = (
f"'{guess.upper()}' is wrong! {remaining} guesses remaining.\n"
f"{_HANGMAN_STAGES[game['wrong_count']]}\n"
f"Word: {display}\nHint: {game['hint']}"
)
html = (
f'<font color="#ef4444"><strong>❌ \'{guess.upper()}\' is wrong!</strong></font> '
f'{remaining} guesses remaining.<br>'
f'<strong>Word:</strong> <code>{display}</code><br>'
f'<strong>Hint:</strong> {game["hint"]}'
)
await send_html(client, room_id, plain, html)
return return
# Single letter guess # Single letter guess