Skip to content

Commit 352cf3f

Browse files
committed
feat: reduce cost of allowedRepetition calls
If the action is repeatable, we can immediately return true
1 parent 4bc3c1b commit 352cf3f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

astar.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func astar(from states, goal goalInterface, actions Actions, maxDepth int) Plan
2727
states: states{
2828
Agent: from.Agent,
2929
data: data,
30-
hash: from.data.hashStates(),
30+
hash: data.hashStates(),
3131
},
3232
parentNode: nil,
3333
cost: 0,
@@ -179,10 +179,14 @@ func simulateActionState(action *Action, nodeStates states) (states, bool) {
179179
}
180180

181181
func allowedRepetition(action *Action, parentNode node) bool {
182+
if action.repeatable {
183+
return true
184+
}
185+
182186
node := &parentNode
183187
for node != nil {
184188
if node.Action.name == action.name {
185-
return action.repeatable
189+
return false
186190
}
187191

188192
node = node.parentNode

0 commit comments

Comments
 (0)