예제 #1
0
 public PointDTO GetSnakeNewHead(SnakeDTO snake, SizeDTO boardSize)
 {
     var index = Offsets.FindIndex(t => t.Direction == snake.Direction);
     var offset = Offsets[(index + MoveOffset + 4)%4];
     var newHead = OffsetModulo(snake.Head, offset.Offset, boardSize);
     return newHead;
 }
예제 #2
0
        private Move GetPrefferedDirection(IEnumerable<PointDTO> food, List<Move> moves, SnakeDTO mySnake, SizeDTO boardSize)
        {
            var foodGroup = food.Select(f => new { Food = f, Metric = (Distance(mySnake.Head, f, boardSize) - NumOfNeigh(food, f) * 2) });

            var closestFoods = foodGroup.OrderBy(f => f.Metric).Select(f => f.Food);

            if (!closestFoods.Any())
            {
                return Move.None;
            }

            var closestFood = closestFoods.First();

            return moves.OrderBy(f => Distance(f.GetSnakeNewHead(mySnake, boardSize), closestFood)).First();
        }