コード例 #1
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;
        }
コード例 #2
0
ファイル: Maze.cs プロジェクト: rm2k/pacman-duel-bot
 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;
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: rm2k/pacman-duel-bot
 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;
 }
コード例 #4
0
 static bool IsWall(Maze _maze, Point p)
 {
     return (_maze.GetSymbol(p) == Symbols._WALL);
 }
コード例 #5
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;
        }
コード例 #6
0
ファイル: ScoreKeeper.cs プロジェクト: rm2k/pacman-duel-bot
 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;
 }