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


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

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


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

示例1: executeAction

/*
 * Check location for agent. If present check to see if due to die.  If so then remove all sugar.
 * If agent is not dying then check each parent to see if they are dying.
 * If they are take the correct share of their sugar (total sugar divided by number of children.
 * Note: We do not bother to check if any of their other children may be dying - just to simplify code
 * @param loc :location to check for agent
 * @see Inheritance Rule
 * @return true if agent was presnt otherwise false
 * @exception none
 */
bool Inheritance::executeAction(Location * loc, group *)
{
    //offloads to intel MIC (experiment)
    //will only work with intel devices with Xeon Phi
#pragma offload target(mic:0)
    {
        if (loc->hasAgent()) {
            Agent *theAgent = loc->getAgent();
            if (theAgent->getAge() == theAgent->getMaxAge()) {//I am dying
                theAgent->setSugar(0);
            }
            else {//I am alive check to see if parents are dying
                if (theAgent->getFather()->getAge() == theAgent->getFather()->getMaxAge()) {
                    theAgent->incSugar(theAgent->getFather()->getSugar() / theAgent->getFather()->getChildrenCount());
                }
                if (theAgent->getMother()->getAge() == theAgent->getMother()->getMaxAge()) {
                    theAgent->incSugar(theAgent->getMother()->getSugar() / theAgent->getMother()->getChildrenCount());
                }
            }
            return true;
        } else {
            return false;/*!< no agent present so did nothing */
        }
    }
}
开发者ID:AaronCMcDermott,项目名称:GPU-Sugarscape,代码行数:35,代码来源:Inheritance.cpp


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