import { Round, GameConfig } from "../types";

export const calculatePlayerTotalScore = (
  playerId: string,
  rounds: Round[],
  gameConfig?: GameConfig,
  isEndGameCalculation = false,
): number => {
  if (gameConfig?.calculatePlayerTotal) {
    return gameConfig.calculatePlayerTotal(
      rounds,
      playerId,
      isEndGameCalculation,
    );
  }
  return rounds.reduce((total, round) => {
    const pScore = round.scores.find((s) => s.playerId === playerId);
    return total + (pScore?.score || 0);
  }, 0);
};
