Follow-up Comment #1, patch #1432 (project wesnoth):

I haven't quite followed the new AI design, but I think the evaluator is
meant to be executed in a tight loop and performances therefore matter. If
so, rather than basing the Lua code on LuaKernel::run_event, you should base
it on LuaKernel::run_filter. Instead of calling the compiler each time the
snippet is executed, this approach requires it to be a global symbol, that
is, a precompiled function.

Even better, instead of having evaluation and execution functions, you could
just have an initialization function. (In that case, it doesn't have to be a
precompiled symbol, we can go back to an on-the-fly script.) This script
would return a table of functions.

I think it will be more clear with an example. Here is an initialization
script to be called only when loading or changing an AI.


local data = ...
return {
  evaluate = function(unit)
    if unit.role == "keeper" and data.dont_move_keepers then return -10000
end
  end,
  execute = whatever,
  serialize = function() return data end
}


Note that these functions are closures: they share the "data" table, in which
they can store whichever internal data they may need; but since this table is
local, it is obviously invisible from other AIs. See
lua_action_handler::handle for an example how to keep things around.

The ai_execute_move function seems to have a rather complicated interface. I
guess that, most of the times, a unit will consume its movement points, so it
should be "!keep_movement" rather than "remove_movement". This way the
designer could just ignore the argument. Also, the "side" argument is quite
redundant; it has to be the side of the unit at location "from", doesn't it?
Also, it would make sense to allow to pass the unit directly rather than its
coordinates; see intf_find_path for an example of how it is done.

But, in fact, I'm not even sure to understand why one would need an
ai_execute_move function. Don't we expect the move chosen by the "evaluate"
part to be performed in the "execute" part? I don't see why the AI is allowed
to move a completely unrelated unit.

    _______________________________________________________

Reply to this item at:

  <http://gna.org/patch/?1432>

_______________________________________________
  Message posté via/par Gna!
  http://gna.org/


_______________________________________________
Wesnoth-bugs mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-bugs

Reply via email to