Skip to content

Commit

Permalink
Avoid some unnecessary overhead in AI choice function.
Browse files Browse the repository at this point in the history
  • Loading branch information
bilts committed Jan 20, 2012
1 parent 4fcc865 commit b456d46
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions basicAI.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ class BasicAI
choiceSet = {} choiceSet = {}
for choice in choices for choice in choices
choiceSet[choice] = choice choiceSet[choice] = choice

nullable = null in choices


# Get the priority list. # Get the priority list.
priority = priorityfunc.bind(this)(state, my) priority = priorityfunc.call(this, state, my)
# Now look up all the preferences in that list. The moment we encounter # Now look up all the preferences in that list. The moment we encounter
# a valid choice, we can return it. # a valid choice, we can return it.
for preference in priority for preference in priority
if preference is null and null in choices if preference is null and nullable
return null return null
if choiceSet[preference]? if choiceSet[preference]?
return choiceSet[preference] return choiceSet[preference]
Expand All @@ -103,7 +105,7 @@ class BasicAI
if (choice is null) or (choice is no) if (choice is null) or (choice is no)
value = 0 value = 0
else else
value = valuefunc.bind(this)(state, choice, my) value = valuefunc.call(this, state, choice, my)
if value > bestValue if value > bestValue
bestValue = value bestValue = value
bestChoice = choice bestChoice = choice
Expand Down

0 comments on commit b456d46

Please sign in to comment.