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();
_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)) {
/* 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`);
}
}