Exemplo n.º 1
0
// only used for adding existing buildings from a BWAPI Game * object
void UnitData::addCompletedBuilding(const ActionType & action, const FrameCountType timeUntilFree, const ActionType & constructing, const ActionType & addon)
{
    _numUnits[action.ID()] += action.numProduced();

    _maxSupply += action.supplyProvided();

    // if it's an extractor
	if (action.isRefinery()) 
	{
		// take those workers from minerals and put them into it
		_mineralWorkers -= 3; _gasWorkers += 3;
	}	

    // if it's a building that can produce units, add it to the building data
	if (action.isBuilding() && !action.isSupplyProvider())
	{
		_buildings.addBuilding(action, timeUntilFree, constructing, addon);
	}

    // special case for hatcheries
    if (action.isBuilding() && (action.getUnitType() == BWAPI::UnitTypes::Zerg_Hatchery))
    {
        _hatcheryData.addHatchery(1);
    }
}
// recursively checks the tech tree of Action and sets each to have goalMax of 1
void DFBB_BuildOrderSmartSearch::recurseOverStrictDependencies(const ActionType & actionType)
{
    if (actionType.isResourceDepot() || actionType.isWorker() || actionType.isSupplyProvider() || actionType.isRefinery())
    {
        return;
    }

    PrerequisiteSet recursivePrerequisites = actionType.getRecursivePrerequisites();

    for (size_t a(0); a < recursivePrerequisites.size(); ++a)
    {
        const ActionType & actionType = recursivePrerequisites.getActionType(a);

        if (actionType.isResourceDepot() ||actionType.isWorker() || actionType.isSupplyProvider() || actionType.isRefinery())
        {
            continue;
        }

        _goal.setGoalMax(actionType, std::max((UnitCountType)1, _goal.getGoalMax(actionType)));
    }
}
Exemplo n.º 3
0
void UnitData::removeCompletedAction(const ActionType & action)
{
	//Logger::LogAppendToFile(BOSS_LOGFILE, "Unit removed " + action.getName());
	const static ActionType Lair = ActionTypes::GetActionType("Zerg_Lair");
	const static ActionType Hive = ActionTypes::GetActionType("Zerg_Hive");

	_numUnits[action.ID()] -= action.numProduced();


		// a lair or hive from a hatchery don't produce additional supply
	if (action != Lair && action != Hive)
	{
		_maxSupply -= action.supplyProvided();
	}


	if (action.isWorker())
	{
		if (_mineralWorkers > 0)
		{
			_mineralWorkers--;
		}
		else if (_gasWorkers > 0)
		{
			_gasWorkers--;
		}
	}

	// if it's an extractor
	if (action.isRefinery())
	{
		// take those workers from minerals and put them into it
		_mineralWorkers += 3; _gasWorkers -= 3;
	}
	BOSS_ASSERT(_mineralWorkers >= 0, "Can't have negative mineral workers");
	BOSS_ASSERT(_gasWorkers >= 0, "Can't have negative gas workers");
	// if it's a building that can produce units, add it to the building data
	if (action.isBuilding() && !action.isSupplyProvider())
	{
		if (!action.isMorphed())
		{
			_buildings.removeBuilding(action, ActionTypes::None);
		}
	}

	// special case for hatcheries
	if (action.isBuilding() && (action.getUnitType() == BWAPI::UnitTypes::Zerg_Hatchery))
	{
		_hatcheryData.removeHatchery();
	}
}
Exemplo n.º 4
0
void UnitData::addCompletedAction(const ActionType & action, bool wasBuilt)
{
    const static ActionType Lair = ActionTypes::GetActionType("Zerg_Lair");
    const static ActionType Hive = ActionTypes::GetActionType("Zerg_Hive");

    _numUnits[action.ID()] += action.numProduced();

    if (wasBuilt)
    {
        // a lair or hive from a hatchery don't produce additional supply
        if (action != Lair && action != Hive)
        {
            _maxSupply += action.supplyProvided();
        }
    }
    else
    {
        _maxSupply += action.supplyProvided();
    }
    
    if (action.isWorker()) 
	{ 
		_mineralWorkers++;
	}

    // if it's an extractor
	if (action.isRefinery()) 
	{
		// take those workers from minerals and put them into it
		_mineralWorkers -= 3; _gasWorkers += 3;
	}	

    // if it's a building that can produce units, add it to the building data
	if (action.isBuilding() && !action.isSupplyProvider())
	{
        if (!action.isMorphed())
        {
            _buildings.addBuilding(action, ActionTypes::None);
        }
	}

    // special case for hatcheries
    if (action.isBuilding() && (action.getUnitType() == BWAPI::UnitTypes::Zerg_Hatchery))
    {
        _hatcheryData.addHatchery(wasBuilt ? 1 : 3);
    }
}
Exemplo n.º 5
0
bool GameState::whyIsNotLegal(const ActionType & action) const
{
    const size_t numRefineries  = _units.getNumTotal(ActionTypes::GetRefinery(getRace()));
    const size_t numDepots      = _units.getNumTotal(ActionTypes::GetResourceDepot(getRace()));
    const size_t refineriesInProgress = _units.getNumInProgress(ActionTypes::GetRefinery(getRace()));

    // we can never build a larva
    static const ActionType & Zerg_Larva = ActionTypes::GetActionType("Zerg_Larva");
    if (action == Zerg_Larva)
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Cannot build a Larva" << std::endl;
        return false;
    }

    // check if the tech requirements are met
    if (!_units.hasPrerequisites(action.getPrerequisites()))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Tech requirements not met" << std::endl;
        return false;
    }

    // if it's a unit and we are out of supply and aren't making an overlord, it's not legal
    if (!action.isMorphed() && ((_units.getCurrentSupply() + action.supplyRequired()) > (_units.getMaxSupply() + _units.getSupplyInProgress())))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Not enough supply to construct" << std::endl;
        return false;
    }

    // specific rule for never leaving 0 workers on minerals
    if (action.isRefinery() && (getNumMineralWorkers() <= 4))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Cannot leave 0 workers on minerals" << std::endl;
        return false;
    }

    // if it's a new building and no drones are available, it's not legal
    if (!action.isMorphed() && action.isBuilding() && (getNumMineralWorkers() <= 1) && (getNumBuildingWorkers() == 0))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - No building worker available" << std::endl;
        return false;
    }

    // we can't build a building with our last worker
    if (!action.isMorphed() && action.isBuilding() && (getNumMineralWorkers() <= 1 + 3*refineriesInProgress) && (getNumBuildingWorkers() == 0))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Can't build with last worker" << std::endl;
        return false;
    }

    // if we have no gas income we can't make a gas unit
    if (!canAffordGas(action) && !_units.hasGasIncome())
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - No gas income for gas unit" << std::endl;
        return false;
    }

    // if we have no mineral income we'll never have a minerla unit
    if (!canAffordMinerals(action) && !_units.hasMineralIncome())
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - No mineral income" << std::endl;
        return false;
    }

    // don't build more refineries than resource depots
    if (action.isRefinery() && (numRefineries >= numDepots))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Can't have more refineries than depots" << std::endl;
        return false;
    }

    // we don't need to go over the maximum supply limit with supply providers
    if (action.isSupplyProvider() && (_units.getMaxSupply() + _units.getSupplyInProgress() >= 400))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Can't go over max supply bound with providers" << std::endl;
        return false;
    }

    if (action.isTech() && getUnitData().getNumTotal(action) > 0)
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Can't produce additional copy of tech" << std::endl;
        return false;
    }

    return true;
}
Exemplo n.º 6
0
bool GameState::isLegal(const ActionType & action) const
{
    const size_t numRefineries  = _units.getNumTotal(ActionTypes::GetRefinery(getRace()));
    const size_t numDepots      = _units.getNumTotal(ActionTypes::GetResourceDepot(getRace()));
    const size_t refineriesInProgress = _units.getNumInProgress(ActionTypes::GetRefinery(getRace()));

    // we can never build a larva
    static const ActionType & Zerg_Larva = ActionTypes::GetActionType("Zerg_Larva");
    if (action == Zerg_Larva)
    {
        return false;
    }

    // check if the tech requirements are met
    if (!_units.hasPrerequisites(action.getPrerequisites()))
    {
        return false;
    }
	
    // if it's a unit and we are out of supply and aren't making an overlord, it's not legal
	if (!action.isMorphed() && !action.isSupplyProvider() && ((_units.getCurrentSupply() + action.supplyRequired()) > (_units.getMaxSupply() + _units.getSupplyInProgress())))
    {
        return false;
    }

    // TODO: require an extra for refineries byt not buildings
    // rules for buildings which are built by workers
    if (action.isBuilding() && !action.isMorphed() && !action.isAddon())
    {
        // be very strict about when we can make refineries to ensure we have enough workers to go in gas
        if (action.isRefinery() && (getNumMineralWorkers() <= (4 + 3*refineriesInProgress)))
        {
            return false;
        }

        int workersPerRefinery = 3;
        int workersRequiredToBuild = getRace() == Races::Protoss ? 0 : 1;
        int buildingIsRefinery = action.isRefinery() ? 1 : 0;
        int candidateWorkers = getNumMineralWorkers() + _units.getNumInProgress(ActionTypes::GetWorker(getRace())) + getNumBuildingWorkers();
        int workersToBeUsed = workersRequiredToBuild + workersPerRefinery*(refineriesInProgress);

        if (candidateWorkers < workersToBeUsed)
        {
            return false;
        }
    }

    // if we have no gas income we can't make a gas unit
    if (!canAffordGas(action) && !_units.hasGasIncome())
    {
        return false;
    }

    // if we have no mineral income we'll never have a minerla unit
    if (!canAffordMinerals(action) && !_units.hasMineralIncome())
    {
        return false;
    }

    // don't build more refineries than resource depots
    if (action.isRefinery() && (numRefineries >= numDepots))
    {
        return false;
    }

    // we don't need to go over the maximum supply limit with supply providers
    if (action.isSupplyProvider() && (_units.getMaxSupply() + _units.getSupplyInProgress() > 400))
    {
        return false;
    }

    // can only build one of a tech type
    if (action.isTech() && getUnitData().getNumTotal(action) > 0)
    {
        return false;
    }

    // check to see if an addon can ever be built
    if (action.isAddon() && !_units.getBuildingData().canBuildEventually(action) && (_units.getNumInProgress(action.whatBuildsActionType()) == 0))
    {
        return false;
    }

    return true;
}