FindCoordinateOf() public méthode

public FindCoordinateOf ( char symbol ) : Point
symbol char
Résultat Point
        private static IEnumerable<Point> GetPossibleMoves(Maze previousMaze)
        {
            var previousCoordinate = previousMaze.FindCoordinateOf(Properties.Settings.Default.SymbolPlayerA);
            var moveList = new List<Point>();
            if (previousCoordinate.Y + 1 < Properties.Settings.Default.MazeWidth)
                if (!previousMaze.GetSymbol(previousCoordinate.X, previousCoordinate.Y + 1).Equals(Properties.Settings.Default.SymbolWall) &&
                    !WasInRespawnEntranceA(previousCoordinate.X, previousCoordinate.Y))
                    moveList.Add(new Point(previousCoordinate.X, previousCoordinate.Y + 1));

            if (previousCoordinate.Y - 1 >= 0)
                if (!previousMaze.GetSymbol(previousCoordinate.X, previousCoordinate.Y - 1).Equals(Properties.Settings.Default.SymbolWall) &&
                    !WasInRespawnEntranceB(previousCoordinate.X, previousCoordinate.Y))
                    moveList.Add(new Point(previousCoordinate.X, previousCoordinate.Y - 1));

            if (previousCoordinate.X + 1 < Properties.Settings.Default.MazeHeight)
                if (!previousMaze.GetSymbol(previousCoordinate.X + 1, previousCoordinate.Y).Equals(Properties.Settings.Default.SymbolWall) &&
                    !WasInRespawnZone(previousCoordinate.X, previousCoordinate.Y))
                    moveList.Add(new Point(previousCoordinate.X + 1, previousCoordinate.Y));

            if (previousCoordinate.X - 1 >= 0)
                if (!previousMaze.GetSymbol(previousCoordinate.X - 1, previousCoordinate.Y).Equals(Properties.Settings.Default.SymbolWall) &&
                    !WasInRespawnZone(previousCoordinate.X, previousCoordinate.Y))
                    moveList.Add(new Point(previousCoordinate.X - 1, previousCoordinate.Y));

            if (previousCoordinate.X.Equals(Properties.Settings.Default.MazeHeight / 2 - 1) && previousCoordinate.Y.Equals(Properties.Settings.Default.MazeWidth - 1))
                moveList.Add(new Point(Properties.Settings.Default.MazeHeight / 2 - 1, 0));

            if (previousCoordinate.X.Equals(Properties.Settings.Default.MazeHeight / 2 - 1) && previousCoordinate.Y.Equals(0))
                moveList.Add(new Point(Properties.Settings.Default.MazeHeight / 2 - 1, Properties.Settings.Default.MazeWidth - 1));

            return moveList;
        }
        private static IEnumerable<Point> GetPossibleMoves(Maze previousMaze)
        {
            var previousCoordinate = previousMaze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_A);
            var opponentCoordinate = previousMaze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_B);
            var moveList = new List<Point>();
            // Right
            if (previousCoordinate.Y + 1 < Properties.Settings.Default.MazeWidth)
                if (previousMaze.GetSymbol(previousCoordinate.X, previousCoordinate.Y + 1) != Symbols.SYMBOL_WALL &&
                    !WasInRespawnPoint(previousCoordinate.X, previousCoordinate.Y))
                    moveList.Add(new Point(previousCoordinate.X, previousCoordinate.Y + 1));

            // Left
            if (previousCoordinate.Y - 1 >= 0)
                if (previousMaze.GetSymbol(previousCoordinate.X, previousCoordinate.Y - 1) != Symbols.SYMBOL_WALL &&
                    !WasInRespawnPoint(previousCoordinate.X, previousCoordinate.Y))
                    moveList.Add(new Point(previousCoordinate.X, previousCoordinate.Y - 1));

            // Down
            if (previousCoordinate.X + 1 < Properties.Settings.Default.MazeHeight)
                if (previousMaze.GetSymbol(previousCoordinate.X + 1, previousCoordinate.Y) != Symbols.SYMBOL_WALL &&
                    !WasInRespawnEntranceA(previousCoordinate.X, previousCoordinate.Y) &&
                    !WasInRespawnPoint(previousCoordinate.X + 1, previousCoordinate.Y) &&
                    // Opponent cannot be eaten while in the respawn zone.
                    (!WasInRespawnZone(opponentCoordinate.X, opponentCoordinate.Y) || previousCoordinate.Y!=opponentCoordinate.Y || previousCoordinate.X + 1!=opponentCoordinate.X))
                    moveList.Add(new Point(previousCoordinate.X + 1, previousCoordinate.Y));

            // Up
            if (previousCoordinate.X - 1 >= 0)
                if (previousMaze.GetSymbol(previousCoordinate.X - 1, previousCoordinate.Y) != Symbols.SYMBOL_WALL &&
                    !WasInRespawnEntranceB(previousCoordinate.X, previousCoordinate.Y) &&
                    !WasInRespawnPoint(previousCoordinate.X - 1, previousCoordinate.Y) &&
                    // Opponent cannot be eaten while in the respawn zone.
                    (!WasInRespawnZone(opponentCoordinate.X, opponentCoordinate.Y) || previousCoordinate.Y!=opponentCoordinate.Y || previousCoordinate.X - 1!=opponentCoordinate.X))
                    moveList.Add(new Point(previousCoordinate.X - 1, previousCoordinate.Y));

            // Wrap right
            if (previousCoordinate.X == (Properties.Settings.Default.MazeHeight / 2 - 1) && previousCoordinate.Y == (Properties.Settings.Default.MazeWidth - 1))
                moveList.Add(new Point(Properties.Settings.Default.MazeHeight / 2 - 1, 0));

            // Wrap left
            if (previousCoordinate.X == (Properties.Settings.Default.MazeHeight / 2 - 1) && previousCoordinate.Y == 0)
                moveList.Add(new Point(Properties.Settings.Default.MazeHeight / 2 - 1, Properties.Settings.Default.MazeWidth - 1));

            return moveList;
        }
Exemple #3
0
 private Player DeterminIfWinner(Enums.GameOutcome gameOutcome, Maze mazeFromPlayer, Player winner)
 {
     mazeFromPlayer.SwapPlayerSymbols();
     _maze = mazeFromPlayer;
     if (_maze.FindCoordinateOf(_secondMazePlayer).IsEmpty)
     {
         _maze.SetSymbol(Properties.Settings.Default.MazeCenterX, Properties.Settings.Default.MazeCenterY, _secondMazePlayer);
     }
     if (gameOutcome != Enums.GameOutcome.ProceedToNextRound)
     {
         winner = GameJudge.DetermineWinner(_playerPool, gameOutcome);
     }
     return(winner);
 }
Exemple #4
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
            });
        }
 private static bool IsPillDroppedInRespawnZone(Maze currentMaze, Maze previousMaze)
 {
     var previousCoordinateA = previousMaze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_A);
     if (currentMaze.GetSymbol(previousCoordinateA) == Symbols.SYMBOL_POISON_PILL)
         return WasInRespawnZone(previousCoordinateA.X, previousCoordinateA.Y);
     return false;
 }
 private static Boolean IsPossibleMoveMade(Maze currentMaze, Maze previousMaze)
 {
     var currentPosition = currentMaze.FindCoordinateOf(Symbols.SYMBOL_PLAYER_A);
     return GetPossibleMoves(previousMaze).Any(coordinate => coordinate.X.Equals(currentPosition.X) && coordinate.Y.Equals(currentPosition.Y));
 }
 private static Boolean IsPossibleMoveMade(Maze currentMaze, Maze previousMaze)
 {
     var currentPosition = currentMaze.FindCoordinateOf(Properties.Settings.Default.SymbolPlayerA);
     return GetPossibleMoves(previousMaze).Any(coordinate => coordinate.X.Equals(currentPosition.X) && coordinate.Y.Equals(currentPosition.Y));
 }
 private Player DeterminIfWinner(Enums.GameOutcome gameOutcome, Maze mazeFromPlayer, Player winner)
 {
     mazeFromPlayer.SwapPlayerSymbols();
     _maze = mazeFromPlayer;
     if (_maze.FindCoordinateOf(_secondMazePlayer).IsEmpty)
     {
         _maze.SetSymbol(Properties.Settings.Default.MazeCenterX, Properties.Settings.Default.MazeCenterY, _secondMazePlayer);
     }
     if (gameOutcome != Enums.GameOutcome.ProceedToNextRound)
         winner = GameJudge.DetermineWinner(_playerPool, gameOutcome);
     return winner;
 }