public static AnalyzedMap Get()
        {
            var mapHash  = Game.MapHash;
            var fileName = $"{PathToData}{mapHash}.dat";
            var result   = AnalyzedMap.TryLoadFromFile(fileName);

            if (result.HasValue)
            {
                return(result.Value);
            }

            var analyzedMap = Analyze();

            analyzedMap.SaveToFile(fileName);

            return(analyzedMap);
        }
示例#2
0
        public AnalyzedMapExtra(AnalyzedMap analyzedMap)
        {
            _analyzedMap = analyzedMap;

            var myStartLocation  = Game.Self.StartLocation.ToWalkTile().AsTuple();
            var myMainBaseRegion = _analyzedMap.MapRegions.First(r => r.ContentTiles.Contains(myStartLocation));

            MyNaturals = myMainBaseRegion.AdjacentChokes.SelectMany(ch => ch.AdjacentRegions).Except(myMainBaseRegion.Yield())
                         .Distinct()
                         .Where(r => r.ResourceSites.Any())
                         .ToList();

            MyStartRegion = myMainBaseRegion;

            ChokesBetweenMainAndNaturals = MyStartRegion.AdjacentChokes
                                           .Intersect(MyNaturals.SelectMany(n => n.AdjacentChokes)).ToList();

            NaturalsEntrances = MyNaturals.SelectMany(n => n.AdjacentChokes)
                                .Except(ChokesBetweenMainAndNaturals).ToList();

            AllResourceRegions = _analyzedMap.MapRegions.Where(mr => mr.ResourceSites.Any()).ToList();
        }
示例#3
0
 public GameInfo(AnalyzedMap analyzedMap)
 {
     _analyzedMap = analyzedMap;
 }
示例#4
0
        public Bot()
        {
            //MapExporter.ExportMap();
            _analyzedMap      = TerrainAnalyzerAdapter.Get();
            _analyzedMapExtra = new AnalyzedMapExtra(_analyzedMap);
            _gameInfo         = new GameInfo(_analyzedMap);

            UnitSpawned         = _unitSpawned.Publish();
            UnitDestroyed       = _unitDestroyed.Publish();
            TrainingStarted     = _trainingStarted.Publish();
            ConstructionStarted = _constructionStarted.Publish();

            _buildOrderScheduler = new BuildOrderScheduler(TrainingStarted, ConstructionStarted, _analyzedMapExtra, _gameInfo);

            var entranceToNaturalExp = _analyzedMapExtra.MyNaturals.FirstOrDefault()?.AdjacentChokes
                                       .Except(_analyzedMapExtra.ChokesBetweenMainAndNaturals).FirstOrDefault();
            var hasEntranceToNaturalExp = entranceToNaturalExp != null;
            var entranceToGuard         = hasEntranceToNaturalExp
                ? entranceToNaturalExp
                : _analyzedMapExtra.ChokesBetweenMainAndNaturals.FirstOrDefault() ?? _analyzedMapExtra.MyStartRegion.AdjacentChokes.FirstOrDefault();

            if (entranceToGuard == null)
            {
                throw new InvalidOperationException("No main base entrance found. Probably an island map");
            }

            var main = _analyzedMapExtra.MyStartRegion;

            _behaviors = new IBehavior[]
            {
                new IdleWorkersToMineral(main),
                new ThreeWorkersOnGas(main),
                //new CounterAttackStackWorkers(baseLocation),
                new WorkersAttackClosestEnemy(main),
                new AttackEnemiesInBase(main),
                //new StepBackIfUnderAttack(),
                new RangedKite(),
                new RememberEnemyBuildings(),
                new TowersAttackLowestHp(),
                new RetreatIfOutnumbered(_gameInfo),
            };

            if (!_analyzedMapExtra.MyNaturals.Any())
            {
                _behaviors = _behaviors.Concat(new IBehavior[]
                {
                    new IdleFightersGuardEntrance(main, entranceToGuard),
                    new OrderIdleUnitsToAttack(UnitType.Zerg_Zergling, 6, main),
                    new OrderIdleUnitsToAttack(UnitType.Zerg_Hydralisk, 20, main),
                }).ToArray();
                return;
            }

            var natural = _analyzedMapExtra.MyNaturals.First();

            _behaviors = _behaviors.Concat(new IBehavior[]
            {
                new IdleWorkersToMineral(natural),
                new ThreeWorkersOnGas(natural),
                new WorkersAttackClosestEnemy(natural),
                new AttackEnemiesInBase(natural),
                new IdleFightersGuardEntrance(natural, entranceToGuard),
                new FightersRallyPoint(main, natural),
                new OrderIdleUnitsToAttack(UnitType.Zerg_Zergling, 6, natural),
                new OrderIdleUnitsToAttack(UnitType.Zerg_Hydralisk, 20, natural),
                new IdleFightersAttackClosestEnemy(natural, _analyzedMapExtra),
                new BalanceWorkersMainNatural(main, natural),
            }).ToArray();
        }