@@ -160,33 +160,37 @@ private GoapResult SolveAstar(GoapState stateCurrent, ConditionInterface goal, i
160
160
// if not arrived to the max depth...
161
161
if ( current . depth < maxDepth )
162
162
{
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 ) ;
184
165
}
185
166
}
186
167
187
168
return CreateFailureResult ( ) ;
188
169
}
189
170
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
+
190
194
private GoapResult CreateSuccessResult ( AstarQueue latestQueue )
191
195
{
192
196
// action list
0 commit comments