Skip to content

Commit 9d0c0a0

Browse files
ralyodioclaude
andauthored
Fix hangman: lowercase r swallowed by restart binding during play (#79)
The Update key switch bound "r" to restart, but returned early even when the game was still active, so lowercase r could never be entered as a letter guess (Shift+R worked because "R" didn't match the case). Now r only restarts when dead; otherwise it falls through to the guess logic. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 47a88b2 commit 9d0c0a0

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

plugins/arcade/hangman.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ func (h *hangman) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
7878
case "q", "esc":
7979
return h, back
8080
case "r":
81+
// Only "restart" once dead; during play, r is a normal letter guess
82+
// and must fall through to the guessing logic below.
8183
if h.dead {
8284
return newHangman(h.user, h.ctx), nil
8385
}
84-
return h, nil
8586
case " ", "enter":
8687
if h.won {
8788
h.deal() // advance to the next word

plugins/arcade/hangman_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ func TestHangmanDeathAfterSixMisses(t *testing.T) {
6868
}
6969
}
7070

71+
// The "r" restart binding must not swallow r as a letter guess during play.
72+
func TestHangmanLowercaseRIsAGuess(t *testing.T) {
73+
h := newTestHangman("ROUTER")
74+
for _, r := range "router" {
75+
m, _ := h.Update(key(r))
76+
h = m.(*hangman)
77+
}
78+
if !h.won {
79+
t.Fatalf("lowercase r should count as a guess and solve ROUTER")
80+
}
81+
}
82+
7183
func TestHangmanLowercaseInputAndAdvance(t *testing.T) {
7284
h := newTestHangman("CAT")
7385
for _, r := range "cat" { // lowercase should still solve

0 commit comments

Comments
 (0)