event = next_event event.class # => AttackedEvent event.attacker # => '003' agent code name event.damage # => 132If an agent is attacked by another agent, the victim receives an attacked event. The event includes the code name of the attacker and the damage suffered.
Here an example with an iterator:
each_event do |event|
if event.instance_of? AttackedEvent
puts "attacked by #{event.attacker} and suffered #{event.damage}"
end
end
In your tests you can fire the attacked event by using has_been_attacked_by. The method takes the codename of the attacker and an optional damage parameter.
it "should behave different if it has been attacked" do @agent.has_been_attacked_by '003' @agent.think ... endThe new test methods are available with SDK Version 0.9.7.
Download the new SDK V0.9.7
See the documentation.
Keine Kommentare:
Kommentar veröffentlichen