Пример #1
0
 public Maze(Maze maze)
 {
     _map = new char[Properties.Settings.Default._MazeHeight][];
     for (var x = 0; x < Properties.Settings.Default._MazeHeight; x++)
     {
         var row = new char[Properties.Settings.Default._MazeWidth];
         for (var y = 0; y < Properties.Settings.Default._MazeWidth; y++)
         {
             row[y] = maze.GetSymbol(x, y);
         }
         _map[x] = row;
     }
 }
Пример #2
0
 public static void CleanScoreCard(Maze _maze)
 {
     string _input;
     if (PillCountToScore(_maze) == Properties.Settings.Default._MazeTotalPillCount - 1)
         _input = "0,1,0";
     else
         _input = "0,0,0";
     using (var file = new System.IO.StreamWriter(_pathToScoreCard, false))
     {
         file.Write(_input);
         file.Close();
     }
     _maze.WriteMaze(_pathToGameState);
 }
Пример #3
0
        static void Main(string[] args)
        {
            var maze = new Maze(args[0]);

            if (IsTheGameStart(maze))
            {
                PoisonBucket.FillUpPoisonBucket();
                ScoreKeeper.CleanScoreCard(maze);
            }

            Bot _Bot = new Bot { _maze = maze };

            maze = _Bot.MakeMove();

            maze.WriteMaze(Properties.Settings.Default._OUTPUT_FILE_NAME);
        }
Пример #4
0
        public static List<Point> GenerateMoves(Maze maze, Point currentPoint)
        {
            var nextMoves = new List<Point>();

            if (IsValidPoint(new Point { X = currentPoint.X, Y = currentPoint.Y + 1 }))
            {
                var point = new Point { X = currentPoint.X, Y = currentPoint.Y + 1 };
                if (!IsWall(maze, point) && !IsRespawnZoneRight(point))
                    nextMoves.Add(point);
            }

            if (IsValidPoint(new Point { X = currentPoint.X, Y = currentPoint.Y - 1 }))
            {
                var point = new Point { X = currentPoint.X, Y = currentPoint.Y - 1 };
                if (!IsWall(maze, point) && !IsRespawnZoneLeft(point))
                    nextMoves.Add(point);
            }

            if (IsValidPoint(new Point { X = currentPoint.X + 1, Y = currentPoint.Y }))
            {
                var point = new Point { X = currentPoint.X + 1, Y = currentPoint.Y };
                if (!IsWall(maze, point) && !IsRespawnZoneExitUP(point) && !IsRespawnZone(point))
                {
                    if (!(IsRespawnZone(currentPoint) && maze.GetSymbol(currentPoint.X + 1, currentPoint.Y).Equals(Symbols._PLAYER_B)))
                        nextMoves.Add(new Point { X = currentPoint.X + 1, Y = currentPoint.Y });
                }
            }

            if (IsValidPoint(new Point { X = currentPoint.X - 1, Y = currentPoint.Y }))
            {
                var point = new Point { X = currentPoint.X - 1, Y = currentPoint.Y };
                if (!IsWall(maze, point) && !IsRespawnZoneExitDown(point) && !IsRespawnZone(point))
                {
                    if (!(IsRespawnZone(currentPoint) && maze.GetSymbol(currentPoint.X - 1, currentPoint.Y).Equals(Symbols._PLAYER_B)))
                        nextMoves.Add(new Point { X = currentPoint.X - 1, Y = currentPoint.Y });
                }
            }

            if (IsPortalLeft(currentPoint))
                nextMoves.Add(new Point { X = Properties.Settings.Default._MazePortal2X, Y = Properties.Settings.Default._MazePortal2Y });

            if (IsPortalRight(currentPoint))
                nextMoves.Add(new Point { X = Properties.Settings.Default._MazePortal1X, Y = Properties.Settings.Default._MazePortal1Y });

            return nextMoves;
        }
Пример #5
0
 public static bool IsTheGameStart(Maze _maze)
 {
     var _PILL_COUNT = 0;
     for (var x = 0; x < Properties.Settings.Default._MazeHeight; x++)
     {
         for (var y = 0; y < Properties.Settings.Default._MazeWidth; y++)
         {
             var _symbol = _maze.GetSymbol(x, y);
             if (_symbol.Equals(Symbols._PILL))
                 _PILL_COUNT++;
             if (_symbol.Equals(Symbols._BONUS_PILL))
                 _PILL_COUNT += 10;
         }
     }
     if (_PILL_COUNT == Properties.Settings.Default._MazeTotalPillCount
         || _PILL_COUNT == Properties.Settings.Default._MazeTotalPillCount - 1)
         return true;
     return false;
 }
Пример #6
0
        public static List<Point> PathToPill(Maze maze, Point start, Point destination)
        {
            var list = new List<Point>();
            var closedSet = new List<PathNode>();
            var hScore = Math.Abs(start.X - destination.X) + Math.Abs(start.Y - destination.Y);

            var openSet = new List<PathNode>
            {
                new PathNode
                {
                    Position = start,
                    GScore = 0,
                    HScore = hScore,
                    FScore = hScore
                }

            };

            while (openSet.Count != 0)
            {
                var current = BestNode(openSet);
                if (current.Position.Equals(destination))
                {
                    list.Add(new Point { X = current.GScore });
                    list.Add(ReconstructPath(start, current).Position);
                    return list;
                }
                openSet.Remove(current);
                closedSet.Add(current);

                var childpoints = GenerateMoves(maze, current.Position);

                foreach (var childpoint in childpoints)
                {
                    var gScore = current.GScore + 1;
                    hScore = Math.Abs(childpoint.X - destination.X) + Math.Abs(childpoint.Y - destination.Y);
                    var newChild = new PathNode
                    {
                        Position = childpoint,
                        GScore = gScore,
                        HScore = hScore,
                        FScore = gScore + hScore
                    };

                    if (closedSet.Contains(newChild))
                        continue;
                    var _newChild = FindChild(newChild, openSet);
                    if (_newChild != null
                        && gScore < _newChild.GScore)
                    {
                        openSet.Remove(_newChild);
                        current.InsertChild(newChild);
                        openSet.Add(newChild);
                    }
                    else if (_newChild == null)
                    {
                        current.InsertChild(newChild);
                        openSet.Add(newChild);
                    }
                }
            }
            return list;
        }
Пример #7
0
 static bool IsWall(Maze _maze, Point p)
 {
     return (_maze.GetSymbol(p) == Symbols._WALL);
 }
Пример #8
0
        public static Point SelectPath(Maze maze, Point start, int depth)
        {
            var openSet = new List<PathNode>
            {
                new PathNode{Position = start}
            };
            var closedSet = new List<PathNode>();
            var _depth = 0;

            while (openSet.Count != 0 && _depth < depth)
            {
                var root = openSet.First();
                openSet.Remove(root);

                var childPoints = GenerateMoves(maze, root.Position);

                foreach (var childPoint in childPoints)
                {
                    if (!isChildExplored(root, childPoint))
                    {
                        var _case = maze.GetSymbol(childPoint);
                        switch (_case)
                        {
                            case '.':
                                var newChild = new PathNode
                                {
                                    Position = childPoint,
                                    Score = root.Score + 1
                                };
                                root.InsertChild(newChild);
                                openSet.Add(newChild);
                                break;
                            case '*':
                                newChild = new PathNode
                                {
                                    Position = childPoint,
                                    Score = root.Score + 10
                                };
                                root.InsertChild(newChild);
                                openSet.Add(newChild);
                                break;
                            default:
                                break;
                        }
                    }
                }
                closedSet.Add(root);
                _depth++;
            }

            var current = new PathNode();
            if (openSet.Count != 0)
            {
                current = closedSet.OrderByDescending(pathNode => pathNode.Score).First();
                return ReconstructPath(start, current).Position;
            }

            current = closedSet.OrderByDescending(pathNode => pathNode.Score).First();
            var longestStreaks = closedSet.Where(pathNode => pathNode.Score == current.Score).ToList();
            if (longestStreaks.Count == 1)
                return ReconstructPath(start, current).Position;
            var random = new Random();
            var longestStreakIndex = random.Next(0, longestStreaks.Count);
            return ReconstructPath(start, longestStreaks[longestStreakIndex]).Position;
        }
Пример #9
0
        public static void UpdateScore(Maze _maze, bool PlayerA)
        {
            var _previousMaze = new Maze(_pathToGameState);
            var _previousPillCountToScore = PillCountToScore(_previousMaze);

            var _currentMaze = new Maze(_maze);
            var _currentPillCountToScore = PillCountToScore(_currentMaze);

            var _playerAScore = GetPlayerAScore();
            var _playerBScore = GetPlayerBScore();
            var _TurnsWithNoPointScored = GetTurnsWithNoPointScored();

            if (_currentPillCountToScore == _previousPillCountToScore)
            {
                if (_currentPillCountToScore != Properties.Settings.Default._MazeTotalPillCount
                && _currentPillCountToScore != Properties.Settings.Default._MazeTotalPillCount - 1)
                {
                    _TurnsWithNoPointScored++;
                    string _input = _playerAScore.ToString() + "," + _playerBScore.ToString() + "," + _TurnsWithNoPointScored.ToString();
                    using (var file = new System.IO.StreamWriter(_pathToScoreCard, false))
                    {
                        file.Write(_input);
                        file.Close();
                    }
                }
            }
            else
            {
                _TurnsWithNoPointScored = 0;
                if (PlayerA)
                {
                    _playerAScore = (_currentPillCountToScore == _previousPillCountToScore - 1) ? _playerAScore += 1 : _playerAScore += 10;
                }
                else
                {
                    _playerBScore = (_currentPillCountToScore == _previousPillCountToScore - 1) ? _playerBScore += 1 : _playerBScore += 10;
                }

                string _input = _playerAScore.ToString() + "," + _playerBScore.ToString() + "," + _TurnsWithNoPointScored.ToString();
                using (var file = new System.IO.StreamWriter(_pathToScoreCard, false))
                {
                    file.Write(_input);
                    file.Close();
                }
                _currentMaze.WriteMaze(_pathToGameState);
            }
        }
Пример #10
0
 public static int PillCountToScore(Maze _maze)
 {
     var _PILL_COUNT = 0;
     for (var x = 0; x < Properties.Settings.Default._MazeHeight; x++)
     {
         for (var y = 0; y < Properties.Settings.Default._MazeWidth; y++)
         {
             var _symbol = _maze.GetSymbol(x, y);
             if (_symbol.Equals(Symbols._PILL))
                 _PILL_COUNT++;
             if (_symbol.Equals(Symbols._BONUS_PILL))
                 _PILL_COUNT = _PILL_COUNT + 10;
         }
     }
     return _PILL_COUNT;
 }