Beispiel #1
0
        private Tile ChooseTarget()
        {
            HashSet <Tile> targets = new HashSet <Tile>();

            targets.UnionWith(map.AllEnemyPlayers);
            targets.UnionWith(map.AllMonsters);
            targets.UnionWith(map.AllWalls);

            float maxPriority = 0;
            float numberOfTargetsOnMaxPriority = 0;
            Tile  finalTarget = default;


            foreach (var target in targets)
            {
                var nearestWalkable = GetNearestWalkableTileToPlaceBomb(target, out var numberOfTargets);
                if (nearestWalkable == null)
                {
                    continue;
                }
                if (IsTileDangerousToGo(pathfinder.NextTileOnPath(nearestWalkable.Value)))
                {
                    continue;
                }
                if (map.GetManhattanDistance(myTile, target) == 1)
                {
                    continue;
                }

                float score = 0;
                if (target.IsEnemyPlayer)
                {
                    score = GameLib.PlayerKillScore;
                }
                if (target.IsMonster)
                {
                    score = GameLib.MonsterKillScore;
                }
                if (target.IsRegularWall)
                {
                    score = GameLib.WallDestroyScore;
                }

                if (blastZone.ContainsKey(target) && map.GetManhattanDistance(myTile, target) < 5)
                {
                    score *= (blastZone[target] - 1) * 0.25f;
                    score  = Math.Clamp(score, 0, int.MaxValue);
                    if (target.IsRegularWall)
                    {
                        score = 0;
                    }
                }

                var distance = Math.Clamp(pathfinder.GetDistance(nearestWalkable.Value) - 3, 1, int.MaxValue);
                if (distance > 1000)
                {
                    continue;
                }

                float priority = score / (distance * distance);
                if (Math.Abs(priority - maxPriority) < 0.01 && numberOfTargets > numberOfTargetsOnMaxPriority)
                {
                    maxPriority = priority;
                    finalTarget = nearestWalkable.Value;
                }
                if (priority > maxPriority)
                {
                    maxPriority = priority;
                    finalTarget = nearestWalkable.Value;
                }
            }
            return(finalTarget);
        }
Beispiel #2
0
        private AgentAction PlantBomb(HashSet <Tile> safeTiles)
        {
            var tileTo = pathfinder.NextTileOnPath(safeTiles.OrderBy(x => pathfinder.GetDistance(x)).First());

            return(GameLib.BombDirectionTo(myTile, tileTo));
        }