Created
May 11, 2011 07:27
-
-
Save dhoelzgen/966044 to your computer and use it in GitHub Desktop.
SaboteurAgent in experimental DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'simple_agent' | |
class SaboteurAgent < SimpleAgent | |
on_percept :visibleEntity do |name, position, team, status| | |
next if team == @team | |
broadcast | |
if enemy = @enemies[name] | |
enemy.position = position | |
enemy.status = status | |
else | |
@enemies[name] = Enemy.new( name, position, team, status ) | |
end | |
end | |
motivate :attack do | |
next -1 if bb.disabled | |
next -1 unless bb.position | |
candidates = @enemies.values.find_all { |enemy| enemy.position == bb.position && enemy.enabled } | |
target = candidates.sort.last | |
if bb.transient[:attack_target] = target | |
80 | |
else | |
-1 | |
end | |
end | |
on_goal :attack do | |
say "Attacking #{bb.transient[:attack_target].name}" | |
next skip! unless has_energy 2 | |
attack! bb.transient[:attack_target] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment