Minor fixes to capitalization, 2026 -> HTML5 naming

This commit is contained in:
Cam Spry committed 2026-03-02 01:44:39 -05:00
1 parent c87654ed7c
commit a65607b054
3 files changed
+44 -23

No files matched your search

+41 -20
View File
@@ -213,30 +213,51 @@ class YarnGame {
tallyVotes() {
if (this.round_data.length === 0) return null;
// Find winner (most votes)
let winner = this.round_data[0];
// 1. Award 1 point per vote to every sentence
for (const entry of this.round_data) {
if (entry.votes.length > winner.votes.length) {
winner = entry;
const p = this.getPlayer(entry.player_id);
if (p) p.score += entry.votes.length;
}
// 2. Find the top vote count
const maxVotes = Math.max(...this.round_data.map(e => e.votes.length));
const leaders = this.round_data.filter(e => e.votes.length === maxVotes);
// 3. Decide bonus points
if (leaders.length === 1) {
// Single winner: +3
const winner = leaders[0];
const p = this.getPlayer(winner.player_id);
if (p) p.score += 3;
} else {
// Tie: longest gets +2, rest +1
const longest = leaders.reduce(
(a, b) => (b.entry_text.length > a.entry_text.length ? b : a),
leaders[0]
);
for (const l of leaders) {
const p = this.getPlayer(l.player_id);
if (p) p.score += l === longest ? 2 : 1;
}
}
// Award points
const winnerPlayer = this.getPlayer(winner.player_id);
if (winnerPlayer) {
winnerPlayer.score += 5 + winner.votes.length;
}
// Add to story
if (winner.entry_text) {
// 4. Append winning (or tied-longest) entry to the story
const storyEntry =
leaders.length === 1
? leaders[0]
: leaders.reduce(
(a, b) => (b.entry_text.length > a.entry_text.length ? b : a),
leaders[0]
);
if (storyEntry?.entry_text) {
this.yarnStory.push({
player: winnerPlayer ? winnerPlayer.name : "Unknown",
str: winner.entry_text
player: this.getPlayer(storyEntry.player_id)?.name ?? "Unknown",
str: storyEntry.entry_text
});
}
return winner;
return leaders.length === 1 ? leaders[0] : null; // return single winner or null on tie
}
checkGameOver() {
@@ -421,8 +442,8 @@ io.on('connection', (socket) => {
const game = games[currentRoom];
if (!game || game.gameHost !== playerId) return;
if (game.players.length < 2 && settings.botCount == 0) {
socket.emit('error', { message: 'Need at least 2 players to start' });
if ((game.players.length + settings.botCount) < 3) {
socket.emit('error', { message: 'Need at least 3 players to start' });
return;
}