Updates rules to be closer to original Y.A.R.N

This commit is contained in:
Cam Spry committed 2026-03-02 02:42:54 -05:00
1 parent a65607b054
commit f1e9470710
3 files changed
+50 -18

No files matched your search

+35 -11
View File
@@ -25,7 +25,8 @@ class YarnGame {
this.inProgress = false;
this.gameHost = null;
this.gameSettings = {
scoreLimit: 50,
scoreLimit: 0,
roundLimit: 15,
timeLimit: 60,
botCount: 0,
startText: "It was a dark and stormy night..."
@@ -36,6 +37,7 @@ class YarnGame {
this.yarnStory = []; // { player: "", str: "" }
this.chat = []; // { id, name, msg }
this.round_data = []; // { entry_text, player_id, votes: [] }
this.roundCount = 0; // current round
this.currentPhase = 'lobby'; // lobby, writing, voting, gameOver
this.timer = null;
this.timeRemaining = 0;
@@ -133,6 +135,7 @@ class YarnGame {
async startGame(settings) {
this.gameSettings = { ...this.gameSettings, ...settings };
this.roundCount = 0;
this.startBots(this.gameSettings.botCount);
this.inProgress = true;
this.yarnStory = [{ player: "Narrator", str: this.gameSettings.startText }];
@@ -142,9 +145,13 @@ class YarnGame {
async processBotWriting() {
for (const botObj of this.bots) {
const botText = await botObj.bot.Write(this.getStoryText());
console.log(`Bot text: ${botText}`)
this.submitEntry(botObj.bot_id, botText)
try {
const botText = await botObj.bot.Write(this.getStoryText());
console.log(`Bot text: ${botText}`);
this.submitEntry(botObj.bot_id, botText);
} catch (err) {
console.warn(`Bot ${botObj.bot_id} failed to write:`, err.message || err);
}
}
}
@@ -180,8 +187,13 @@ class YarnGame {
async processBotVoting() {
for (const botObj of this.bots) {
const botVote = await botObj.bot.Vote(this.getStoryText(), this.round_data);
this.submitVote(botObj.bot_id, botVote)
try {
const botVote = await botObj.bot.Vote(this.getStoryText(), this.round_data);
this.submitVote(botObj.bot_id, botVote);
} catch (err) {
// One bot failing to vote is not critical; keep going
console.warn(`Bot ${botObj.bot_id} failed to vote:`, err.message || err);
}
}
}
@@ -257,15 +269,26 @@ class YarnGame {
});
}
this.roundCount++; // increment round counter
return leaders.length === 1 ? leaders[0] : null; // return single winner or null on tie
}
checkGameOver() {
const winner = this.players.find(p => p.score >= this.gameSettings.scoreLimit);
if (winner) {
this.currentPhase = 'gameOver';
this.inProgress = false;
return winner;
// score limit win
if (this.gameSettings.scoreLimit) {
const scoreWinner = this.players.find(p => p.score >= this.gameSettings.scoreLimit);
if (scoreWinner) return scoreWinner;
}
// round limit win
if (this.roundCount >= this.gameSettings.roundLimit && this.gameSettings.roundLimit != 0) {
return this.players.reduce(
(best, p) => (p.score > best.score ? p : best),
this.players[0]
);
}
// if we're one before the round limit, append to the story
if (this.roundCount == this.gameSettings.roundLimit-1) {
this.yarnStory.push({ player: "Narrator", str: "The moral of this story: " });
}
return null;
}
@@ -345,6 +368,7 @@ class YarnGame {
})),
yarnStory: this.yarnStory,
currentPhase: this.currentPhase,
currentRound: this.roundCount+1,
timeRemaining: this.timeRemaining,
round_data: this.currentPhase === 'voting' ? this.round_data.map((e, i) => ({
index: i,