コード例 #1
0
ファイル: GreedyBot.cs プロジェクト: pgillett/PacMan
        public Direction SuggestNextDirection(BotGame game)
        {
            _game = game;

            var currentLocation = _graph.GetNodeForLocation(_game.PacMan.Location);

            var shortestDistances = DistancesCalculator.CalculateDistances(_game, _graph, currentLocation);

            var nearestCoin = FindNearestCoin(_game.Coins, shortestDistances);

            Direction bestDirectionToNearestCoin;

            if (nearestCoin == CellLocation.TopLeft)
            {
                // No more coins are available,  game is meant to be finished.  Pick any direction
                // and hope to stay away from the ghosts
                bestDirectionToNearestCoin = currentLocation.AvailableMoves.First().Direction;
            }
            else
            {
                bestDirectionToNearestCoin = shortestDistances.DirectionToTarget(nearestCoin);
            }

            var nearestGhost = FindNearestGhost(_game.Ghosts, shortestDistances);

            bestDirectionToNearestCoin = AvoidGhost(currentLocation, shortestDistances, bestDirectionToNearestCoin, nearestGhost);

            return(bestDirectionToNearestCoin);
        }
コード例 #2
0
            void Mark(IEnumerable <Vector2> points, Cell.States state)
            {
                foreach (var point in points.Where(IsInBounds))
                {
                    cells[point.X, point.Y].State = state;
                }

                DistancesCalculator.Update(AllCoords, this);
            }
コード例 #3
0
            void Mark(Vector2 point, Cell.States state)
            {
                cells[point.X, point.Y].State = state;
                var subjectPoints = Enumerable.Range(0, Width)
                                    .Select(x => new Vector2(x, point.Y))
                                    .Union(Enumerable.Range(0, Height)
                                           .Select(y => new Vector2(point.X, y)));

                DistancesCalculator.Update(subjectPoints, this);
            }
コード例 #4
0
            void InitCells(int width, int height)
            {
                for (var x = 0; x < width; x++)
                {
                    for (var y = 0; y < height; y++)
                    {
                        cells[x, y] = InitCell(new Vector2(x, y));
                    }
                }

                DistancesCalculator.Update(AllCoords, this);
            }