Пример #1
0
        public Direction?GetNextDirection(Ghost ghost, Game game)
        {
            var availableMoves = GetAvailableMovesForLocation(ghost.Location, game.Walls);

            availableMoves.Remove(ghost.Direction.Opposite());

            if (availableMoves.Count() == 1)
            {
                return(availableMoves.First());
            }

            var target = _directToLocation.GetLocation(game);

            return(availableMoves
                   .OrderBy(possibleDirection => (ghost.Location + possibleDirection) - target)
                   .ThenBy(p => (int)p)
                   .First());
        }
Пример #2
0
        public Direction?GetNextDirection(Ghost ghost, Game game)
        {
            var placesCannotMove = game.Walls.AsEnumerable();

            if (_canWalkDoors)
            {
                placesCannotMove = placesCannotMove.Except(game.Doors);
            }
            var availableMoves = GetAvailableMovesForLocation(ghost.Location, placesCannotMove);

            availableMoves.Remove(ghost.Direction.Opposite());

            if (availableMoves.Count() == 1)
            {
                return(availableMoves.First());
            }

            var target = _directToLocation.GetLocation(game);

            return(availableMoves
                   .OrderBy(possibleDirection => (ghost.Location + possibleDirection) - target)
                   .ThenBy(p => (int)p)
                   .First());
        }