public static Player DetermineWinner(PlayerPool playerPool, Enums.GameOutcome gameOutcome) { if (playerPool.GetPlayers()[0].GetScore() != playerPool.GetPlayers()[1].GetScore()) return playerPool.GetPlayers().OrderByDescending(x => x.GetScore()).First(); if (gameOutcome == Enums.GameOutcome.NoScoringMaxed) return playerPool.GetNextPlayer(); return null; }
public GameResult Run(String folderPath) { var gamePlayDirectoryPath = System.Environment.CurrentDirectory + System.IO.Path.DirectorySeparatorChar + folderPath; Directory.CreateDirectory(gamePlayDirectoryPath); var outputFilePath = gamePlayDirectoryPath + System.IO.Path.DirectorySeparatorChar + Properties.Settings.Default.SettingGamePlayFile; _maze.WriteMaze(outputFilePath); Player winner = null; var gameOutcome = Enums.GameOutcome.ProceedToNextRound; Directory.CreateDirectory(folderPath); Directory.CreateDirectory(folderPath + System.IO.Path.DirectorySeparatorChar + Properties.Settings.Default.SettingReplayFolder); var logFile = new StreamWriter(folderPath + System.IO.Path.DirectorySeparatorChar + Properties.Settings.Default.SettingMatchLogFileName); CreateIterationStateFile(folderPath); logFile.WriteLine("[GAME] : Match started"); _iteration++; while (gameOutcome == Enums.GameOutcome.ProceedToNextRound) { _currentPlayer = _playerPool.GetNextPlayer(); var mazeFromPlayer = _currentPlayer.GetMove(_maze, gamePlayDirectoryPath + System.IO.Path.DirectorySeparatorChar + Properties.Settings.Default.SettingGamePlayFile, logFile); if (mazeFromPlayer != null) { var mazeValidationOutcome = GetMazeValidationOutcome(logFile, mazeFromPlayer); if (mazeValidationOutcome == Enums.MazeValidationOutcome.ValidMaze) { var opponentPosition = _maze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_B); var previousPosition = _maze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_A); var currentPosition = mazeFromPlayer.FindCoordinateOf(Symbols.SYMBOL_PLAYER_A); var turnOutcome = GetTurnOutcome(mazeFromPlayer, currentPosition, previousPosition, opponentPosition, logFile); if (turnOutcome != Enums.TurnOutcome.MoveMadeAndDroppedPoisonPillIllegally) { RegenerateOpponentIfDead(opponentPosition, mazeFromPlayer); gameOutcome = GetGameOutcome(mazeFromPlayer, logFile, gameOutcome, turnOutcome); winner = DeterminIfWinner(gameOutcome, mazeFromPlayer, winner); } else { gameOutcome = ProcessIllegalMove(logFile, gameOutcome, ref winner); } _maze.WriteMaze(gamePlayDirectoryPath + System.IO.Path.DirectorySeparatorChar + Properties.Settings.Default.SettingGamePlayFile); Maze iterationFileMaze = CreateIterationStateFile(folderPath); _iteration++; foreach (var player in _playerPool.GetPlayers()) { Console.Write(player.GetSymbol() + "," + player.GetPlayerName() + ": " + player.GetScore() + " "); } Console.WriteLine(); iterationFileMaze.Print(); } else { gameOutcome = ProcessIllegalMove(logFile, gameOutcome, ref winner); } } else { gameOutcome = ProcessIllegalMove(logFile, gameOutcome, ref winner); } } CreateMatchInfo(gameOutcome, winner, logFile); logFile.Close(); var replayMatchOutcome = new StreamWriter(folderPath + System.IO.Path.DirectorySeparatorChar + "replay" + System.IO.Path.DirectorySeparatorChar + "matchinfo.out"); CreateMatchInfo(gameOutcome, winner, replayMatchOutcome); replayMatchOutcome.Close(); return(new GameResult() { Players = _playerPool.GetPlayers(), Outcome = gameOutcome, Iterations = _iteration - 1, Folder = folderPath }); }
public static Player DetermineWinner(PlayerPool playerPool) { if (playerPool.GetPlayers()[0].GetScore() != playerPool.GetPlayers()[1].GetScore()) return playerPool.GetPlayers().OrderByDescending(x => x.GetScore()).First(); return null; }