//----------------------------------------------------------------- // Core Gameplay Functions //----------------------------------------------------------------- //Main game loop. Returns the outcome of the game. public GameResults PlayGame() { var progressMade = true; while (!lastRound && progressMade) { progressMade = GameRound(); } DisplayText("Game over"); GameResults results = new GameResults(players, GetWinningPlayers(), roundCount); return(results); }
public TournamentResults PlayTournament() { var wins = new int[Players.Count]; var totalScores = new int[Players.Count]; var totalEarnedPenalties = new int[Players.Count]; var totalAppliedPenalties = new int[Players.Count]; var heatMap = new int[5, 5]; var totalGameRounds = 0u; var ties = 0; var timer = new Stopwatch(); timer.Start(); for (int i = 0; i < Rounds; i++) { // Clone the list so it's not affected by turn order GameManager gm = new GameManager(new List <Player>(Players)); GameResults gameResult = gm.PlayGame(); if (gameResult.winners.Count > 1) { ties++; } foreach (var winner in gameResult.winners) { wins[Players.IndexOf(winner)]++; UpdateHeatMap(heatMap, winner.Wall.Tiles); } for (int j = 0; j < Players.Count; j++) { // players comes back in a different order than it started var player = gameResult.players[j]; var playerIndex = Players.IndexOf(player); totalScores[playerIndex] += player.score; totalEarnedPenalties[playerIndex] += player.totalEarnedPenalties; totalAppliedPenalties[playerIndex] += player.totalAppliedPenalties; } totalGameRounds += gameResult.roundCount; } timer.Stop(); var tournamentResults = new TournamentResults() { Ties = ties, Time = timer.Elapsed, }; for (int i = 0; i < Players.Count; i++) { tournamentResults.WinPercentages.Add(wins[i] / (double)Rounds); tournamentResults.AverageScores.Add(totalScores[i] / (double)Rounds); tournamentResults.AverageEarnedPenalties.Add(totalEarnedPenalties[i] / (double)Rounds); tournamentResults.AverageAppliedPenalties.Add(totalAppliedPenalties[i] / (double)Rounds); } tournamentResults.AverageRounds = totalGameRounds / (double)Rounds; tournamentResults.HeatMap = CompileHeatMap(heatMap); return(tournamentResults); }