public async Task <bool> Build(Observation currentObservation, int unitType, int width, int height)
        {
            var workers = currentObservation.GetPlayerUnits(new[] { (uint)_constantManager.WorkerUnitIndex });
            var worker  = workers[0]; // Use first selected worker for now

            var mapManager = Game.MapManager;
            var point      = mapManager.GetAvailableDiamondInMainBase(width, height);

            var countOfUnitType = currentObservation.GetPlayerUnits(unitType, false).Count;

            await SendBuildRequest(worker, unitType, point);

            return(true);

            //var response = await _connectionService.ReceiveRequestAsync();

            // Check if Build was successful and update MapManager
            // TODO: Move this to BuildQueue
            //if (response != null && response.HasAction && response.Action.Result.Contains(ActionResult.Success))
            //{

            //    if (currentObservation.GetPlayerUnits(unitType, false).Count > countOfUnitType)
            //    {
            //    }
            //}
        }
示例#2
0
        public async Task AttackMove(Observation currentObservation)
        {
            var units = currentObservation.GetPlayerUnits(new[] { (uint)_constantManager.FirstArmyUnit });

            foreach (var unit in units)
            {
                await SendAttackRequest(unit, Game.ResponseGameInfo.StartRaw.StartLocations[0]);
            }
        }
示例#3
0
        public async Task <bool> BuildUnitIfEmptyQueue(Observation currentObservation, int buildingType, int unitType)
        {
            foreach (var building in currentObservation.GetPlayerUnits(buildingType))
            {
                if (building.Orders.Count == 0)
                {
                    await SendBuildRequest(building, unitType);

                    return(true);
                }
            }
            return(false);
        }
示例#4
0
        public async Task <bool> BuildWorkerIfEmptyQueue(Observation currentObservation)
        {
            if (currentObservation.PlayerCommon.FoodWorkers < 18)                                // Decision
            {
                var baseUnits = currentObservation.GetPlayerUnits(_constantManager.BaseTypeIds); // Base Manager
                // Single command centre for now
                // Check queue is empty
                if (baseUnits[0].Orders.Count == 0)
                {
                    await SendBuildRequest(baseUnits[0], _constantManager.WorkerUnitIndex);

                    return(true);
                }
            }
            return(false);
        }
示例#5
0
        public async Task Act(Observation currentObservation)
        {
            var constantManager = new ConstantManager(Race.Terran);
            var supplyUnit      = constantManager.SupplyUnit;

            // Fill queue
            if (RequireSupply(currentObservation) && currentObservation.GetPlayerUnitsInProgress(supplyUnit).Count == 0 &&
                !_queue.Any(b => b.UnitType == supplyUnit))
            {
                Console.WriteLine("Queue supply");
                _queue.Enqueue(new BuildQueueItem
                {
                    Action        = () => _buildingManager.Build(currentObservation, supplyUnit, 2, 2),
                    PreviousCount = currentObservation.GetPlayerUnits(supplyUnit, false).Count,
                    UnitType      = supplyUnit
                });
            }
            if (currentObservation.GetPlayerUnits(supplyUnit).Count == 1 && currentObservation.GetPlayerUnits(constantManager.FirstArmyBuilding, false).Count < 3 &&
                !_queue.Any(b => b.UnitType == constantManager.FirstArmyBuilding))
            {
                Console.WriteLine("Queue baracks");

                _queue.Enqueue(new BuildQueueItem
                {
                    Action        = () => _buildingManager.Build(currentObservation, constantManager.FirstArmyBuilding, 3, 3),
                    PreviousCount = currentObservation.GetPlayerUnits(constantManager.FirstArmyBuilding, false).Count,
                    UnitType      = constantManager.FirstArmyBuilding
                });
            }
            if (currentObservation.GetPlayerUnits(constantManager.FirstArmyBuilding).Count > 0 &&
                !_queue.Any(b => b.UnitType == constantManager.FirstArmyUnit))
            {
                Console.WriteLine("Queue marine");

                _queue.Enqueue(new BuildQueueItem
                {
                    Action        = () => _unitManager.BuildUnitIfEmptyQueue(currentObservation, constantManager.FirstArmyBuilding, constantManager.FirstArmyUnit),
                    PreviousCount = currentObservation.GetPlayerUnits(constantManager.FirstArmyUnit, false).Count,
                    UnitType      = constantManager.FirstArmyUnit
                });
            }
            if (currentObservation.GetPlayerUnits(constantManager.FirstArmyUnit).Count >= 24 &&
                DateTime.Now.Subtract(_attackTime).TotalMinutes > 2)
            {
                Console.WriteLine("Attack move");

                await _armyManager.AttackMove(currentObservation);

                _attackTime = DateTime.Now;
            }

            // Trigger next build queue item, dequeue if previous trigger was successful or too delayed
            // Next trigger waits till Act is called again
            if (_queue.Count > 0)
            {
                var buildItem = _queue.Peek();
                if (!buildItem.Triggered)
                {
                    if (currentObservation.PlayerCommon.Minerals >= Game.ResponseData.Units.First(a => a.UnitId == buildItem.UnitType).MineralCost)
                    {
                        var actionAvailable = await buildItem.Action();

                        buildItem.ActTime   = DateTime.Now;
                        buildItem.Triggered = true;
                        if (!actionAvailable)
                        {
                            _queue.Dequeue();
                        }
                    }
                }
                else
                {
                    // Check if previous trigger was successful
                    if (currentObservation.GetPlayerUnits(buildItem.UnitType, false).Count > buildItem.PreviousCount)
                    {
                        _queue.Dequeue();
                    }
                    // Previous trigger was delayed
                    else if (DateTime.Now.Subtract(buildItem.ActTime).TotalSeconds > 8)
                    {
                        Console.WriteLine($"BuildItem failed: {buildItem}");
                        _queue.Dequeue();
                    }
                }
            }
        }