Exemplo n.º 1
0
        private SnakeAction ClosestApple(GameBoard gameBoard)
        {
            Graph graph      = GraphCreator.Create(gameBoard);
            var   myPosition = gameBoard.GetMyHead().Value;

            var        weights     = graph.Dijkstra(graph[myPosition]);
            var        applePoints = gameBoard.GetApples();
            BoardPoint best        = applePoints.FirstOrDefault();
            double     bestWeight  = double.MaxValue;

            foreach (var point in applePoints)
            {
                if (weights[graph[point].NodeNumber] < bestWeight)
                {
                    bestWeight = weights[graph[point].NodeNumber];
                    best       = point;
                }
            }
            var bestNode = graph.Dijkstra(graph[myPosition], graph[best]);

            if (myPosition.ShiftBottom() == bestNode.BoardPoint)
            {
                return(new SnakeAction(false, Direction.Down));
            }
            if (myPosition.ShiftLeft() == bestNode.BoardPoint)
            {
                return(new SnakeAction(false, Direction.Left));
            }
            if (myPosition.ShiftRight() == bestNode.BoardPoint)
            {
                return(new SnakeAction(false, Direction.Right));
            }
            if (myPosition.ShiftTop() == bestNode.BoardPoint)
            {
                return(new SnakeAction(false, Direction.Up));
            }

            return(new SnakeAction(false, Direction.Up));
        }
Exemplo n.º 2
0
 private int FindBonusesConcentration(BoardPoint target, GameBoard gameBoard, int squareSize)
 => FindConcentration(target, gameBoard.GetApples().Concat(gameBoard.GetGold()), squareSize);
 private static IEnumerable <BoardPoint> NiceTargets(GameBoard gameBoard)
 {
     return(gameBoard.GetApples()
            .Concat(gameBoard.GetGold())
            .Concat(gameBoard.GetFuryPills()));
 }