raven的ai处理:
先据评估项(函数)进行评估选出当前最优一项,据此项产生对应的新行为处理对象(先清除之前的所有行为),调用它的process()来处理.
具体如下:
一。行为评估项:
每个bot有一个brain(即Goal_Think类),在brain中有一个评估列表m_Evaluators;
raven中主要是有4种需要评估的行为:
1.拿药包
2.探索
3.攻击
4.拿武器
具体如下:
double HealthBias = RandInRange(LowRangeOfBias, HighRangeOfBias);
double ShotgunBias = RandInRange(LowRangeOfBias, HighRangeOfBias);
double RocketLauncherBias = RandInRange(LowRangeOfBias, HighRangeOfBias);
double RailgunBias = RandInRange(LowRangeOfBias, HighRangeOfBias);
double ExploreBias = RandInRange(LowRangeOfBias, HighRangeOfBias);
double AttackBias = RandInRange(LowRangeOfBias, HighRangeOfBias);
//create the evaluator objects
m_Evaluators.push_back(new GetHealthGoal_Evaluator(HealthBias));
m_Evaluators.push_back(new ExploreGoal_Evaluator(ExploreBias));
m_Evaluators.push_back(new AttackTargetGoal_Evaluator(AttackBias));
m_Evaluators.push_back(new GetWeaponGoal_Evaluator(ShotgunBias,
type_shotgun));
m_Evaluators.push_back(new GetWeaponGoal_Evaluator(RailgunBias,
type_rail_gun));
m_Evaluators.push_back(new GetWeaponGoal_Evaluator(RocketLauncherBias,
type_rocket_launcher));
上述评估项目主要派生了一个 CalculateDesirability(), 以便bot在更新时遍历该评估表,
调用它们的CalculateDesirability()选出最优先的行为项,并调用它的SetGoal(m_pOwnerBot)方法;
对应被选中的评估项的SetGoal函数内容:
void AttackTargetGoal_Evaluator::SetGoal(Raven_Bot* pBot)
{
pBot->GetBrain()->AddGoal_AttackTarget();
}
void ExploreGoal_Evaluator::SetGoal(Raven_Bot* pBot)
{
pBot->GetBrain()->AddGoal_Explore();
}
void GetHealthGoal_Evaluator::SetGoal(Raven_Bot* pBot)
{
pBot->GetBrain()->AddGoal_GetItem(type_health);
}
void GetWeaponGoal_Evaluator::SetGoal(Raven_Bot* pBot)
{
pBot->GetBrain()->AddGoal_GetItem(m_iWeaponType);
}
二。行为处理类:
在上述SetGoal对应具体函数中所调用的brain方法具体产生的行为如下:
void Goal_Think::AddGoal_Explore()
{
if (notPresent(goal_explore))
{
RemoveAllSubgoals();
AddSubgoal( new Goal_Explore(m_pOwner));
}
}
void Goal_Think::AddGoal_GetItem(unsigned int ItemType)
{
if (notPresent(ItemTypeToGoalType(ItemType)))
{
RemoveAllSubgoals();
AddSubgoal( new Goal_GetItem(m_pOwner, ItemType));
}
}
void Goal_Think::AddGoal_AttackTarget()
{
if (notPresent(goal_attack_target))
{
RemoveAllSubgoals();
AddSubgoal( new Goal_AttackTarget(m_pOwner));
}
}
当bot更新时会调用brain的process,从而调用到对应的subgoal中的Process()函数
注意:
每个goal在处理时还可以产生它自己的子goal。因为有时候在处理一个goal时需要等完成
另一个子goal后才能处理。 即状态管理使用了树结构.
posted on 2013-04-07 11:08
flipcode 阅读(256)
评论(0) 编辑 收藏 引用