Example #1
0
File: Bot.cs Project: evilz/TyrSc2
        private bool CheckSurrender()
        {
            if (!AllowGG)
            {
                return(false);
            }
            int buildings = 0;
            int health    = 0;
            int shield    = 0;

            foreach (Agent agent in UnitManager.Agents.Values)
            {
                if (agent.IsBuilding)
                {
                    buildings++;
                    health = (int)System.Math.Max(health, agent.Unit.Health);
                    shield = (int)System.Math.Max(shield, agent.Unit.Shield);
                }
            }
            if (buildings <= 1 &&
                shield == 0 &&
                health <= 150)
            {
                return(true);
            }

            int bases    = UnitManager.Count(UnitTypes.NEXUS) + UnitManager.Count(UnitTypes.COMMAND_CENTER) + UnitManager.Count(UnitTypes.COMMAND_CENTER_FLYING) + UnitManager.Count(UnitTypes.ORBITAL_COMMAND) + UnitManager.Count(UnitTypes.ORBITAL_COMMAND_FLYING) + UnitManager.Count(UnitTypes.PLANETARY_FORTRESS) + UnitManager.Count(UnitTypes.HATCHERY) + UnitManager.Count(UnitTypes.LAIR) + UnitManager.Count(UnitTypes.HIVE);
            int workers  = UnitManager.Count(UnitTypes.SCV) + UnitManager.Count(UnitTypes.PROBE) + UnitManager.Count(UnitTypes.DRONE);
            int minerals = (int)Observation.Observation.PlayerCommon.Minerals - ReservedMinerals;

            if (bases > 0 && workers > 0)
            {
                return(false);
            }

            if (workers > 0 && minerals >= 400)
            {
                return(false);
            }

            if (bases > 0 && minerals >= 50)
            {
                return(false);
            }

            foreach (Agent agent in UnitManager.Agents.Values)
            {
                if (agent.IsCombatUnit)
                {
                    return(false);
                }
            }

            return(true);
        }