Exemple #1
0
 private int FindEnemyConcentration(BoardPoint target, GameBoard gameBoard, int squareSize)
 => FindConcentration(target,
                      gameBoard.FindAllElements(EnemyHeadDown, EnemyHeadUp, EnemyHeadLeft, EnemyHeadRight, EnemyHeadEvil),
                      squareSize);
Exemple #2
0
 private int FindBonusesConcentration(BoardPoint target, GameBoard gameBoard, int squareSize)
 => FindConcentration(target, gameBoard.GetApples().Concat(gameBoard.GetGold()), squareSize);
Exemple #3
0
 private int FindEvilSnakesConcentration(BoardPoint target, GameBoard gameBoard, int squareSize)
 => FindConcentration(target, gameBoard.FindAllElements(EnemyHeadEvil), squareSize);
Exemple #4
0
        private IReadOnlyCollection <WeightedRoute> FindWeightedRoutes(IReadOnlyList <Route> routes,
                                                                       PathFinder pathFinder, GameBoard gameBoard, Route max)
        {
            var weighted = new ConcurrentBag <WeightedRoute>();

            Parallel.ForEach(routes, route =>
            {
                var furtherRoute    = FindAnyFurtherRoute(route, pathFinder, max.Length / 2);
                int lookupAreaSize  = max.Length - route.Length;
                var routesInArea    = FindRoutesInArea(route, pathFinder, lookupAreaSize);
                var routeProperties = new RouteProperties
                {
                    IsDeadEnd    = !furtherRoute.Any(),
                    TargetIsFury = route.GoalElement == FuryPill,
                    RoutesInArea = routesInArea,
                    EvilIsNear   = FindEvilNear(route.GoalPoint, pathFinder, FearArea),
                    PreyInArea   = FindPreyInArea(route, pathFinder, FuryArea),

                    BonusesInTarget = FindBonusesConcentration(route.GoalPoint, gameBoard, 6),
                    EnemiesInTarget = FindEnemyConcentration(route.GoalPoint, gameBoard, 6),
                    EnemyIsNear     = FindEnemyConcentration(route.Path.Skip(1).First(), gameBoard, 6),
                    //EvilIsNear = FindEvilSnakesConcentration(route.Path.Skip(1).First(), gameBoard, 6),
                    Hunting    = route.GoalElement.IsEnemy(),
                    StoneEater = route.GoalElement == Stone
                };
                weighted.Add(new WeightedRoute(route, routeProperties));
            });

            return(weighted);
        }
 private static IEnumerable <BoardPoint> NiceTargets(GameBoard gameBoard)
 {
     return(gameBoard.GetApples()
            .Concat(gameBoard.GetGold())
            .Concat(gameBoard.GetFuryPills()));
 }
        private IReadOnlyList <BoardPoint> FindPath(BoardPoint start, BoardPoint goal, GameBoard board)
        {
            var frontier = new Queue <BoardPoint>();

            frontier.Enqueue(start);

            var cameFrom = new Dictionary <BoardPoint, BoardPoint> {
                [start] = new BoardPoint()
            };

            while (frontier.Count > 0)
            {
                var current = frontier.Dequeue();
                foreach (var next in GetNeighbors(current, board))
                {
                    if (!cameFrom.ContainsKey(next))
                    {
                        frontier.Enqueue(next);
                        cameFrom[next] = current;
                    }
                }
            }

            if (!cameFrom.ContainsKey(goal))
            {
                return(Array.Empty <BoardPoint>());
            }

            {
                var current = goal;
                var path    = new List <BoardPoint>(cameFrom.Count - 1)
                {
                    current
                };
                while (current != start)
                {
                    current = cameFrom[current];
                    path.Add(current);
                }

                path.Reverse();
                return(path);
            }
        }
        private void Report(BoardPoint start, BoardPoint next, IReadOnlyList <BoardPoint> best, GameBoard gameBoard,
                            string name = "GOTO")
        {
            var last = best.Last();

            Console.WriteLine($"{name} {gameBoard.GetElementAt(last)} at {last}\t{start} -> {next}");
        }
 public PathFinder(GameBoard board, bool isFury)
 {
     _board = board;
     IsFury = isFury;
 }