From: Carl Worth Date: Sun, 8 Mar 2026 05:27:05 +0000 (-0500) Subject: Fix Anagrams: broadcast claim-end on word acceptance, remove game steal X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=d1eca672e23f7924b2eb2e88ff028e6dcfcb2751;p=lmno-server Fix Anagrams: broadcast claim-end on word acceptance, remove game steal Broadcast a claim-end event after a word is accepted so clients properly exit claim mode. Remove the _find_game_steal function (deferred for a better approach later). Co-Authored-By: Claude Opus 4.6 --- diff --git a/anagrams.js b/anagrams.js index c081214..2f841ae 100644 --- a/anagrams.js +++ b/anagrams.js @@ -537,6 +537,12 @@ class Anagrams extends Game { score }); + /* End the claim so clients exit claim mode. */ + this.broadcast_event_object("claim-end", { + player_name: player ? player.name : "Unknown", + reason: "accepted" + }); + /* Broadcast full player words for state sync. */ this._broadcast_player_state(); @@ -707,55 +713,11 @@ class Anagrams extends Game { _finish_game() { this.state.finished = true; - /* Attempt a final "game steal" for fun. */ - const game_steal = this._find_game_steal(); - this.broadcast_event_object("game-over", { - scores: this._compute_all_scores(), - game_steal + scores: this._compute_all_scores() }); } - /* Find a possible steal the "game" could make using words from - * different players. Returns null or a description of the steal. */ - _find_game_steal() { - const all_words = []; - for (const sid of Object.keys(this.state.player_words)) { - for (const w of this.state.player_words[sid]) { - const player = this.players_by_session[sid]; - all_words.push({ - word: w.word, - owner: player ? player.name : "Unknown", - session: sid, - word_id: w.id - }); - } - } - - /* Try combining pairs of words to see if they form a valid word. */ - for (let i = 0; i < all_words.length; i++) { - for (let j = i + 1; j < all_words.length; j++) { - const combined = (all_words[i].word + all_words[j].word).split(""); - combined.sort(); - const sorted = combined.join(""); - - /* Check all TWL words of this length. */ - for (const candidate of TWL_WORDS) { - if (candidate.length !== combined.length) continue; - const candidate_sorted = candidate.split("").sort().join(""); - if (candidate_sorted === sorted) { - return { - words: [all_words[i], all_words[j]], - result: candidate - }; - } - } - } - } - - return null; - } - _all_player_words() { const result = {}; for (const sid of Object.keys(this.state.player_words)) { @@ -822,8 +784,7 @@ class Anagrams extends Game { /* Send game-over if finished. */ if (this.state.finished) { response.write(`event: game-over\ndata: ${JSON.stringify({ - scores: this._compute_all_scores(), - game_steal: null + scores: this._compute_all_scores() })}\n\n`); } }