Ejemplo n.º 1
0
        private CellLocation FindNearestCoinOrPowerPill(IReadOnlyCollection <CellLocation> coins, IReadOnlyCollection <CellLocation> powerPills, Distances shortestDistances)
        {
            var bestTarget       = default(CellLocation);
            var shortestDistance = int.MaxValue;

            foreach (var coin in coins)
            {
                var distanceToCoin = shortestDistances.DistanceTo(coin);

                if (distanceToCoin < shortestDistance)
                {
                    shortestDistance = distanceToCoin;
                    bestTarget       = coin;
                }
            }

            foreach (var pill in powerPills)
            {
                var distanceToPill = shortestDistances.DistanceTo(pill);

                if (distanceToPill < shortestDistance)
                {
                    shortestDistance = distanceToPill;
                    bestTarget       = pill;
                }
            }

            return(bestTarget);
        }
Ejemplo n.º 2
0
        private BotGhost?FindNearestGhost(BotGhost[] ghosts, Distances shortestDistances)
        {
            var closestGhost     = default(BotGhost);
            var shortestDistance = int.MaxValue;

            foreach (var ghost in ghosts.Where(g => !g.Edible))
            {
                var distanceToGhost = shortestDistances.DistanceTo(ghost.Location);

                if (distanceToGhost < shortestDistance)
                {
                    shortestDistance = distanceToGhost;
                    closestGhost     = ghost;
                }
            }

            return(closestGhost);
        }
Ejemplo n.º 3
0
        private CellLocation FindNearestCoin(IReadOnlyCollection <CellLocation> coins, Distances shortestDistances)
        {
            var bestCoin         = default(CellLocation);
            var shortestDistance = int.MaxValue;

            foreach (var coin in coins)
            {
                var distanceToCoin = shortestDistances.DistanceTo(coin);

                if (distanceToCoin < shortestDistance)
                {
                    shortestDistance = distanceToCoin;
                    bestCoin         = coin;
                }
            }

            return(bestCoin);
        }
Ejemplo n.º 4
0
        private Direction AvoidGhost(LinkedCell currentLocation,
                                     Distances shortestDistances, Direction bestDirectionToNearestCoin, BotGhost?nearestGhost)
        {
            if (nearestGhost is object)
            {
                var distanceToGhost = shortestDistances.DistanceTo(nearestGhost.Location);
                if (distanceToGhost < 5)
                {
                    var directionToScaryGhost = shortestDistances.DirectionToTarget(nearestGhost.Location);
                    if (directionToScaryGhost == bestDirectionToNearestCoin)
                    {
                        bestDirectionToNearestCoin = PickDifferentDirection(currentLocation, directionToScaryGhost);
                    }
                }
            }

            return(bestDirectionToNearestCoin);
        }