/* ────────────────────────────────────────────────────────────────
   Phase 6 Sprint 6.6 — Party & Minigame Templates
   
   Minigame Collection, Quiz, Board Game, Reaction, Drawing/Guessing
──────────────────────────────────────────────────────────────── */
const DEFAULT_MINIGAME_COLLECTION_CONFIG = {
    maxPlayers: 12,
    roundsPerGame: 10,
    minigameTimeLimit: 60,
    transitionDuration: 5,
    selectionMode: 'random',
    scoreMode: 'points',
    bonusRound: true,
    bonusEveryNRounds: 5,
    tiebreaker: true,
};
function createMinigameCollectionState(players) {
    return {
        currentRound: 0,
        players: players.map(p => ({ ...p, score: 0, stars: 0, wins: 0, connected: true })),
        currentMinigame: null,
        phase: 'lobby',
        history: [],
    };
}
function awardPoints(state, rankings, basePoints = 10) {
    var _a;
    for (const rank of rankings) {
        const player = state.players.find(p => p.id === rank.playerId);
        if (!player)
            continue;
        // Points: 1st=10, 2nd=7, 3rd=5, 4th=3, 5th+=1
        const pointMap = { 1: basePoints, 2: 7, 3: 5, 4: 3 };
        player.score += (_a = pointMap[rank.position]) !== null && _a !== void 0 ? _a : 1;
        if (rank.position === 1)
            player.wins++;
    }
}
const DEFAULT_QUIZ_CONFIG = {
    questionsPerRound: 10,
    timePerQuestion: 15,
    answerOptions: 4,
    scoreForCorrect: 100,
    bonusForSpeed: true,
    streakBonus: 50,
    maxPlayers: 12,
    categoryCount: 5,
    lifelines: ['50/50', 'skip', 'extra_time'],
};
function createQuizState(playerIds) {
    const scores = new Map();
    const streaks = new Map();
    const answers = new Map();
    const lifelinesUsed = new Map();
    for (const id of playerIds) {
        scores.set(id, 0);
        streaks.set(id, 0);
        answers.set(id, null);
        lifelinesUsed.set(id, new Set());
    }
    return {
        currentQuestion: 0, scores, streaks, answers,
        lifelinesUsed, phase: 'waiting', timer: 0,
    };
}
function scoreQuizAnswer(state, playerId, answerIndex, correctIndex, timeRemaining, config) {
    var _a, _b;
    const correct = answerIndex === correctIndex;
    const streak = (_a = state.streaks.get(playerId)) !== null && _a !== void 0 ? _a : 0;
    if (!correct) {
        state.streaks.set(playerId, 0);
        return 0;
    }
    let points = config.scoreForCorrect;
    if (config.bonusForSpeed) {
        points += Math.floor((timeRemaining / config.timePerQuestion) * config.scoreForCorrect * 0.5);
    }
    const newStreak = streak + 1;
    state.streaks.set(playerId, newStreak);
    points += (newStreak - 1) * config.streakBonus;
    const current = (_b = state.scores.get(playerId)) !== null && _b !== void 0 ? _b : 0;
    state.scores.set(playerId, current + points);
    return points;
}
const DEFAULT_BOARD_GAME_CONFIG = {
    boardType: 'linear',
    spaceCount: 40,
    diceCount: 2,
    diceSides: 6,
    maxPlayers: 12,
    turnOrder: 'clockwise',
    startSpace: 0,
    winCondition: 'reach_end',
    eventSpaces: true,
    shopSpaces: true,
    branchPaths: false,
};
function rollDice(count, sides) {
    const results = [];
    for (let i = 0; i < count; i++) {
        results.push(1 + Math.floor(Math.random() * sides));
    }
    return results;
}
function createBoardGameState(playerInfos, config) {
    return {
        currentTurn: 1,
        currentPlayer: 0,
        players: playerInfos.map(p => ({
            ...p, position: config.startSpace,
            score: 0, coins: 10, items: [], skippedTurns: 0,
        })),
        diceResult: [],
        phase: 'roll',
    };
}
const DEFAULT_REACTION_CONFIG = {
    type: 'speed_tap',
    roundCount: 10,
    roundDuration: 30,
    minReactionTime: 200,
    targetCount: 1,
    decoyChance: 0.2,
    penaltyForDecoy: 50,
    targetShowDuration: 2,
    speedIncrease: 0.05,
    maxPlayers: 12,
};
function createReactionState(playerIds) {
    const scores = new Map();
    const times = new Map();
    for (const id of playerIds) {
        scores.set(id, 0);
        times.set(id, []);
    }
    return {
        round: 0, scores, reactionTimes: times,
        currentTargets: [], phase: 'waiting', nextTargetId: 1,
    };
}
function getAverageReactionTime(state, playerId) {
    const times = state.reactionTimes.get(playerId);
    if (!times || times.length === 0)
        return 0;
    let sum = 0;
    for (const t of times)
        sum += t;
    return sum / times.length;
}
const DEFAULT_DRAWING_CONFIG = {
    roundDuration: 80,
    maxPlayers: 12,
    roundsPerPlayer: 2,
    hintInterval: 20,
    maxHints: 3,
    canvasWidth: 800,
    canvasHeight: 600,
    brushColors: ['#000000', '#FF0000', '#0000FF', '#00FF00', '#FFFF00', '#FF00FF', '#FF8800', '#FFFFFF'],
    brushSizes: [2, 5, 10, 20],
    categories: ['animals', 'objects', 'food', 'activities', 'places'],
    pointsForGuess: 100,
    pointsForDrawer: 50,
    bonusForSpeed: true,
};
function createDrawingState(playerIds) {
    var _a;
    const scores = new Map();
    for (const id of playerIds)
        scores.set(id, 0);
    return {
        currentDrawer: (_a = playerIds[0]) !== null && _a !== void 0 ? _a : '',
        currentWord: '', hint: '', hintsGiven: 0,
        timer: 0, strokes: [], scores,
        guessedPlayers: new Set(),
        round: 0, phase: 'choosing',
    };
}
function generateHint(word, hintsGiven) {
    const chars = [];
    // Reveal more letters with each hint
    const revealCount = Math.min(Math.ceil(word.length * 0.3 * (hintsGiven + 1)), word.length);
    const indices = new Set();
    // Always reveal first letter
    indices.add(0);
    // Randomly reveal more
    while (indices.size < revealCount) {
        indices.add(Math.floor(Math.random() * word.length));
    }
    for (let i = 0; i < word.length; i++) {
        if (word[i] === ' ')
            chars.push(' ');
        else if (indices.has(i))
            chars.push(word[i]);
        else
            chars.push('_');
    }
    return chars.join('');
}
function checkGuess(guess, word) {
    return guess.trim().toLowerCase() === word.trim().toLowerCase();
}

export { DEFAULT_BOARD_GAME_CONFIG, DEFAULT_DRAWING_CONFIG, DEFAULT_MINIGAME_COLLECTION_CONFIG, DEFAULT_QUIZ_CONFIG, DEFAULT_REACTION_CONFIG, awardPoints, checkGuess, createBoardGameState, createDrawingState, createMinigameCollectionState, createQuizState, createReactionState, generateHint, getAverageReactionTime, rollDice, scoreQuizAnswer };
//# sourceMappingURL=PartyTemplates.js.map
