Mittwoch, 10. November 2010

Secure your steps, how to disengage from a move action

Update: This feature has been removed in with the beginning of the 3rd season. Instead use look_at for agents in level Clone War.

In Zero X the simulation and all agents are running continuously. That's one big difference to other programming games, that usually are round based. The consequence is, that in the time between an agent inspects his environment with a look_around and the action he takes, with a move_to for example, the environment can change.
For example a field is free, when he makes the look_around, but has been occupied in the meanwhile by another agent, when he moves. This would result in a unintended attack against this other agent.

Although this case is rare, as a look_around and a move_to are very close. But this time gape can grow bigger as the analysis of the environment takes more time. In general agents have to deal with this kind of insecurity about their perception. This one of the many challenges in this game.

But in order to handle better this kind of insecurity, starting with season 2, move_to can now take a block.
move_to(x,y) {|target| ... }
The argument passed to the block is another view of the target field at the exact time of the movement. This gives the agent the chance to check the preconditions of his action. If they are not fulfilled anymore, he can now disengage from the move action.

move_to(x,y) do |target|
  unless target.has_no_population?
     disengage 'field is not free anymore!'
  end
end
Disengage can take a message, that will then be displayed in your reports. The action is canceled and the agent remains on his starting field. But disengage comes not for free. A move_to would cost 6 action points, disengage from this action still costs 3 action points.

Disengage can only be used within an action block like the one in move_to.

Keine Kommentare: