GetMove() public method

public GetMove ( Maze maze, String outputFilePath, StreamWriter logFile ) : Maze
maze Maze
outputFilePath String
logFile System.IO.StreamWriter
return Maze
Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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 GameResult 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 == 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 == 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);
                    }
                    else gameOutcome = ProcessIllegalMove(logFile, gameOutcome, ref winner);

                    _maze.WriteMaze(gamePlayDirectoryPath + "\\" + Properties.Settings.Default.SettingGamePlayFile);
                    CreateIterationStateFile(folderPath);
                    _iteration++;
                    foreach (var player in _playerPool.GetPlayers())
                    {
                        Console.Write(player.GetSymbol() + "," + player.GetPlayerName() + ": " + player.GetScore() + "  ");
                    }
                    Console.WriteLine();
                    _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();

            return new GameResult()
            {
                Players = _playerPool.GetPlayers(),
                Outcome = gameOutcome,
                Iterations = _iteration - 1,
                Folder = folderPath
            };
        }