本文整理汇总了C++中WorldState::GetFlags方法的典型用法代码示例。如果您正苦于以下问题:C++ WorldState::GetFlags方法的具体用法?C++ WorldState::GetFlags怎么用?C++ WorldState::GetFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorldState
的用法示例。
在下文中一共展示了WorldState::GetFlags方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateH
int GOAPAstar::calculateH(WorldState from, WorldState to)
{
auto care = to.GetCare();
auto diff = ( ( from.GetFlags() & care ) ^ ( to.GetFlags() & care ) );
int distance = 0;
for (int i = 0; i < StateType::STATE_NUM; ++i)
if ( ( diff & ( 1LL << i ) ) != 0 )
++distance;
return distance;
}
示例2: nodeInClosed
int GOAPAstar::nodeInClosed(WorldState ws)
{
for (uint i = 0, n = _closed.size(); i < n; ++i)
{
if (_closed[i].ws.GetFlags() == ws.GetFlags())
return i;
}
return -1;
}
示例3: nodeInOpened
int GOAPAstar::nodeInOpened(WorldState ws)
{
for (uint i = 0, n = _open.size(); i < n; ++i)
{
if (_open[i].ws.GetFlags() == ws.GetFlags())
return i;
}
return -1;
}
示例4: getPossibleStateTransitions
void GOAPAstar::getPossibleStateTransitions(GOAPlanner *ap, WorldState state)
{
_transitions.clear();
for (auto &pair : ap->_actions)
{
auto action = pair.second;
auto pre = action.GetPreWorld();
auto care = pre.GetCare();
bool met = (pre.GetFlags() & care) == (state.GetFlags() & care);
if (met)
{
// compute the future world
WorldState to = state;
to.ApplyAction(action);
// add the action and the future world to the transitions array
_transitions.emplace_back(std::make_pair(action, to));
}
}
}
示例5: Plan
void GOAPAstar::Plan(GOAPlanner *ap)
{
// clear open and closed lists
_open.clear();
_closed.clear();
// TODO: Early out if _current == _desired, add plan WANDER
WorldState goal = ap->_desired;
// put start in the open list
astarnode start;
start.ws = ap->_current;
start.parent_ws = ap->_current;
start.g = 0;
start.h = calculateH(ap->_current, goal);
start.f = start.g + start.h;
start.action_name = "";
_open.push_back(start);
for (;;)
{
if (_open.size() == 0)
return;
// find the node with the lowest rank
astarnode curr = openPopLowest();
auto care = goal.GetCare();
bool match = ((curr.ws.GetFlags() & care) == (goal.GetFlags() & care));
// if we've reached our goal state
if (match)
{
reconstructPlan(ap, &curr);
// Success
return;
}
// add current to closed
_closed.push_back(curr);
// fill the transitions array
getPossibleStateTransitions(ap, curr.ws);
// iterate over all possible transitions
for (auto &pair : _transitions)
{
AIAction &action = pair.first;
WorldState &future = pair.second;
astarnode neighbor;
int cost = curr.g + action.GetCost();
int open_index = nodeInOpened(future);
int close_index = nodeInClosed(future);
// if neighbor is in OPEn and cost less than g(neighbor)
if (open_index >= 0 && cost < _open[open_index].g)
{
// remove neighbor from OPEN, because new patch is better
_open.erase(_open.begin() + open_index);
open_index = -1;
}
// if neighbor in CLOSED and cost less than g(neighbor)
if (close_index >= 0 && cost < _closed[close_index].g)
{
// remove neighbor from CLOSED
_closed.erase(_closed.begin() + close_index);
}
// if neighbor not in OPEN and neighbor not in CLOSED
if (close_index == -1 && open_index == -1)
{
neighbor.ws = future;
neighbor.g = cost;
neighbor.h = calculateH(neighbor.ws, goal);
neighbor.f = neighbor.g + neighbor.h;
neighbor.action_name = action.GetName();
neighbor.parent_ws = curr.ws;
_open.push_back(neighbor);
}
}
}
return;
}