当前位置: 首页>>代码示例>>C++>>正文


C++ ActionType::getPrerequisites方法代码示例

本文整理汇总了C++中ActionType::getPrerequisites方法的典型用法代码示例。如果您正苦于以下问题:C++ ActionType::getPrerequisites方法的具体用法?C++ ActionType::getPrerequisites怎么用?C++ ActionType::getPrerequisites使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ActionType的用法示例。


在下文中一共展示了ActionType::getPrerequisites方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getPrerequistesInProgress

const PrerequisiteSet UnitData::getPrerequistesInProgress(const ActionType & action) const
{
    PrerequisiteSet inProgress;

    for (size_t a(0); a<action.getPrerequisites().size(); ++a)
    {
        const ActionType & actionType = action.getPrerequisites().getActionType(a);
        if (getNumInProgress(actionType) > 0 && getNumCompleted(actionType) == 0)
        {
            inProgress.add(actionType);
        }
    } 

    return inProgress;
}
开发者ID:edran,项目名称:ualbertabot,代码行数:15,代码来源:UnitData.cpp

示例2: whyIsNotLegal

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;
}
开发者ID:edran,项目名称:ualbertabot,代码行数:85,代码来源:GameState.cpp

示例3: isLegal

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;
}
开发者ID:edran,项目名称:ualbertabot,代码行数:85,代码来源:GameState.cpp


注:本文中的ActionType::getPrerequisites方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。