Skip to content

Commit 0d6fb13

Browse files
committed
1 parent 86d14ce commit 0d6fb13

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

Scripts/Goap/GoapSolver/GoapSolver_Pathfinding.cs

+25-21
Original file line numberDiff line numberDiff line change
@@ -160,33 +160,37 @@ private GoapResult SolveAstar(GoapState stateCurrent, ConditionInterface goal, i
160160
// if not arrived to the max depth...
161161
if (current.depth < maxDepth)
162162
{
163-
// ...find next nodes
164-
foreach (GoapAction action in actionPool.Values)
165-
{
166-
// if the action is available...
167-
if (action.IsAvailable(current.state))
168-
{
169-
// ...go to this state
170-
GoapState nextState = action.Simulate(current.state, false);
171-
double costCurrent = current.currentCost + action.cost;
172-
double costEstimated = EstimateCost(nextState, goal);
173-
queue.Enqueue(
174-
new AstarQueue(
175-
nextState,
176-
current,
177-
costCurrent,
178-
costEstimated,
179-
action
180-
)
181-
);
182-
}
183-
}
163+
// ...enqueue next nodes
164+
EnqueueNextActions(queue, current, goal);
184165
}
185166
}
186167

187168
return CreateFailureResult();
188169
}
189170

171+
private void EnqueueNextActions(
172+
PriorityQueue<AstarQueue> queue,
173+
AstarQueue current,
174+
ConditionInterface goal
175+
)
176+
{
177+
// ...find next nodes
178+
foreach (GoapAction action in actionPool.Values)
179+
{
180+
// if the action is available...
181+
if (action.IsAvailable(current.state))
182+
{
183+
// ...go to this state
184+
GoapState nextState = action.Simulate(current.state, false);
185+
double costCurrent = current.currentCost + action.cost;
186+
double costEstimated = EstimateCost(nextState, goal);
187+
queue.Enqueue(
188+
new AstarQueue(nextState, current, costCurrent, costEstimated, action)
189+
);
190+
}
191+
}
192+
}
193+
190194
private GoapResult CreateSuccessResult(AstarQueue latestQueue)
191195
{
192196
// action list

0 commit comments

Comments
 (0)