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


C++ Agent::getChildren方法代码示例

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


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

示例1: executeAction

/**
 * Agent removes agent in location in group from world and takes resources
 * It also removes links to agents killed by combat (lenders, borrowers, etc.)
 * @param loc :Pointer to Location of the winning agent
 * @param grp : Pointer to Group containing location of losing agent (or possibly an empty location)
 * @see Combat Rule
 * @return true if agent exists at loc else false
 * @exception none
 */
bool AgentCombat::executeAction(Location *loc, group *grp)
{
    if (loc->hasAgent()) {
        Agent *winner = grp->getPrimeMover()->getAgent(); //must equal loc->getAgent()!
        if (grp->getMembers().size()!=0)/*!< we are moving somewhere */
        {
            if (grp->getMembers()[0]->hasAgent()==false) {/*!< moving to empty location */
                loc->getAgent()->incSugar(grp->getMembers()[0]->getSugar());/*!< eat sugar at destination */
                grp->getMembers()[0]->setSugar(0);/*!< sugar at location is consumed */
            }
            else{
                //std::cout <<"COMBAT!"<<std::endl;
                //1. Update victorious agent resources
                Agent *loser = grp->getMembers()[0]->getAgent();//only one member in group - the loser
                winner->incSugar(grp->getMembers()[0]->getReward());//*WHAT IF WE ADD SPICE?*
                grp->getMembers()[0]->setSugar(0);/*!< sugar at location is consumed */
                //2. Kill vanquished agent
                std::pair<int,int> currPosition=loser->getPosition();
                if (loser!=sim->killAgent(currPosition))
                {
                    std::cerr << "Delete of agent failed"<<std::endl;
                }
            }
            //Move agent to new position
            std::pair<int,int> currPosition=winner->getPosition();
            sim->setAgent(currPosition, nullptr);//remove old location ptr to agent
            winner->setPosition(grp->getMembers()[0]->getPosition());//set new position to new location
            sim->setAgent(grp->getMembers()[0]->getPosition(),winner);//add ptr to agent at new location
        }
        else{/*!< we are staying put-not moving */
            loc->getAgent()->incSugar(loc->getSugar());/*!< eat sugar at destination */
            loc->setSugar(0);/*!< sugar at location is consumed */
        }
        for(auto ag:winner->getChildren())/*!< Remove any links to killed children */
        {
            if (ag->isKilled()) {
                winner->removeChild(ag);
            }
        }
        winner->removeKilledLoans();/*!< remove loans with killed agents */
        winner->removeKilledFather();/*!< remove father link if he is killed */
        winner->removeKilledMother();/*!< remove mother link if she is killed */
        return true;
    }else{
        return false;/*!< no agent present so did nothing */
    }
}
开发者ID:BrianD1991,项目名称:FYP,代码行数:56,代码来源:AgentCombat.cpp


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