Commit 2210bb63 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: escalating six-boost prevents stuck-at-home frustration

Track rollsWithoutSix per player. Each consecutive failed roll when
all pieces are home ramps the six probability harder — by roll 3-4
a human player has ~40-45% chance of six (vs 17% base). No more
watching bots play while stuck for 6+ turns.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 929a1434
......@@ -22,7 +22,8 @@ export function createGame(numPlayers = 4) {
{ id: `${i}-3`, pos: -1, finished: false }
],
finished: false,
consecutiveSixes: 0
consecutiveSixes: 0,
rollsWithoutSix: 0
});
}
return {
......@@ -39,15 +40,23 @@ export function createGame(numPlayers = 4) {
export function rollDice(game, playerIdx) {
if (!game || playerIdx == null) return Math.floor(Math.random() * 6) + 1;
const player = game.players[playerIdx];
const ctx = getDiceContext(game, playerIdx);
const weights = computeDiceWeights(ctx);
return weightedRoll(weights);
const result = weightedRoll(weights);
if (result === 6) {
player.rollsWithoutSix = 0;
} else {
player.rollsWithoutSix = (player.rollsWithoutSix || 0) + 1;
}
return result;
}
function getDiceContext(game, playerIdx) {
const player = game.players[playerIdx];
const piecesHome = player.pieces.filter(p => p.pos === -1 && !p.finished).length;
const piecesFinished = player.pieces.filter(p => p.finished).length;
const rollsWithoutSix = player.rollsWithoutSix || 0;
const progress = player.pieces.reduce((sum, p) => {
if (p.finished) return sum + FINISH_POS;
......@@ -65,7 +74,7 @@ function getDiceContext(game, playerIdx) {
const isHuman = game.humanPlayers && game.humanPlayers.includes(playerIdx);
const humanCount = game.humanPlayers ? game.humanPlayers.length : 1;
return { playerIdx, piecesHome, piecesFinished, progress, avgOthersProgress, maxOthersProgress, elapsed, isHuman, humanCount };
return { playerIdx, piecesHome, piecesFinished, rollsWithoutSix, progress, avgOthersProgress, maxOthersProgress, elapsed, isHuman, humanCount };
}
function computeDiceWeights(ctx) {
......@@ -97,11 +106,16 @@ function computeDiceWeights(ctx) {
w[4] = Math.max(0.8, w[4] - 0.15);
}
// --- STUCK RESCUE: all pieces at home need a six ---
// --- STUCK RESCUE: escalates with each failed roll ---
// After 2 rolls without six, start boosting hard; by roll 4-5 it's nearly guaranteed
if (ctx.piecesHome === 4) {
w[5] += ctx.isHuman ? 0.9 : 0.6;
const frustration = Math.min(ctx.rollsWithoutSix, 5);
const base = ctx.isHuman ? 0.5 : 0.3;
const escalation = frustration * (ctx.isHuman ? 0.6 : 0.4);
w[5] += base + escalation;
} else if (ctx.piecesHome >= 3) {
w[5] += ctx.isHuman ? 0.5 : 0.3;
const frustration = Math.min(ctx.rollsWithoutSix, 4);
w[5] += (ctx.isHuman ? 0.3 : 0.2) + frustration * 0.25;
}
// --- FINISHING PUSH: accelerate endgame so it stays under 15 min ---
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment