public void Run(String folderPath)
{
var gamePlayDirectoryPath = Properties.Settings.Default.SettingPrimaryDriveName + "\\" + folderPath;
Directory.CreateDirectory(gamePlayDirectoryPath);
var outputFilePath = gamePlayDirectoryPath + "\\" + Properties.Settings.Default.SettingGamePlayFile;
_maze.WriteMaze(outputFilePath);
Player winner = null;
var gameOutcome = Enums.GameOutcome.ProceedToNextRound;
Directory.CreateDirectory(folderPath);
Directory.CreateDirectory(folderPath + "\\" + Properties.Settings.Default.SettingReplayFolder);
var logFile = new StreamWriter(folderPath + "\\" + Properties.Settings.Default.SettingMatchLogFileName);
logFile.WriteLine("[GAME] : Match started");
while (gameOutcome.Equals(Enums.GameOutcome.ProceedToNextRound))
{
_currentPlayer = _playerPool.GetNextPlayer();
var mazeFromPlayer = _currentPlayer.GetMove(_maze, gamePlayDirectoryPath + "\\" + Properties.Settings.Default.SettingGamePlayFile, logFile);
if (mazeFromPlayer != null)
{
var mazeValidationOutcome = GetMazeValidationOutcome(logFile, mazeFromPlayer);
if (mazeValidationOutcome.Equals(Enums.MazeValidationOutcome.ValidMaze))
{
var opponentPosition = _maze.FindCoordinateOf(Properties.Settings.Default.SymbolPlayerB);
var previousPosition = _maze.FindCoordinateOf(Properties.Settings.Default.SymbolPlayerA);
var currentPosition = mazeFromPlayer.FindCoordinateOf(Properties.Settings.Default.SymbolPlayerA);
var turnOutcome = GetTurnOutcome(mazeFromPlayer, currentPosition, previousPosition, opponentPosition, logFile);
if (!turnOutcome.Equals(Enums.TurnOutcome.MoveMadeAndDroppedPoisonPillIllegally))
{
gameOutcome = GetGameOutcome(logFile, gameOutcome, turnOutcome);
winner = DeterminIfWinnerWinner(gameOutcome, mazeFromPlayer, winner);
}
else gameOutcome = ProcessIllegalMove(logFile, gameOutcome, ref winner);
}
else gameOutcome = ProcessIllegalMove(logFile, gameOutcome, ref winner);
_maze.WriteMaze(gamePlayDirectoryPath + "\\" + Properties.Settings.Default.SettingGamePlayFile);
CreateIterationStateFile(folderPath);
_iteration++;
_maze.Print();
}
else gameOutcome = ProcessIllegalMove(logFile, gameOutcome, ref winner);
}
CreateMatchInfo(gameOutcome, winner, logFile);
logFile.Close();
var replayMatchOutcome = new StreamWriter(folderPath + "\\replay\\matchinfo.out");
CreateMatchInfo(gameOutcome, winner, replayMatchOutcome);
replayMatchOutcome.Close();
}