]> git.cworth.org Git - lmno-server/commitdiff
Fix Anagrams: broadcast claim-end on word acceptance, remove game steal
authorCarl Worth <cworth@cworth.org>
Sun, 8 Mar 2026 05:27:05 +0000 (00:27 -0500)
committerCarl Worth <cworth@cworth.org>
Sun, 8 Mar 2026 05:27:05 +0000 (00:27 -0500)
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 <noreply@anthropic.com>
anagrams.js

index c081214d00003437810bb5f21607965be1deec90..2f841aea144f716e1da9f13257926cc3f265ad5c 100644 (file)
@@ -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`);
     }
   }