lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I like your way much more than mine. The thing is the OO x lua static
only functions..whats the best way to communicate the c++ agent ( a
class object I presume) with the lua, without using other lua
libraries..All C functions you described needs to have access to the
agent.
Id like to do it myself instead of having to pick a library straight
from beginning (I want to learn lua, not some library), than later I
can decide for myself witch library suits me better (or even writing
my own)..

I can think on a static pointer that the c++ update for each agent
with the agent address..then all static functions (the ones you
mention) uses it..Lame?
Is this the basic principle on these lua OO wrappers libraries?

On Sun, Oct 21, 2012 at 7:55 PM, Kevin Martin <kev82@khn.org.uk> wrote:
> On 21 Oct 2012, at 20:40, Giuliano Suminsky wrote:
>
>> How to use lua to define this agent decision making code?
>
>
> As a personal preference, I generally dislike the AI design where it is called and has to return the chosen decision - I would use lua coroutines, so that the AI is called once and never returns unless it wins.
>
> Based on what you've said, this is my first stab at an outline of the Lua interface.
>
> 1) Your AI script should implement one function, play, which takes no arguments, and returns nothing.
>
> 2) You should provide the following functions to play (either through require or globally)
>         i) CurrentHP() - returns HP
>         ii) CurrentLocation() - returns 2 values, your current location
>         iii) GridCell(x, y) - returns a string/table describing the object in the specified grid location
>         iv) MoveTo(x, y) - Sets the desired location to move to
>         v) Shoot(dir) - Sets the desired action as shoot in the specified direction
>         vi) Defend() - Sets the desired action as defend
>         vii) PowerUp() - Sets the desired action as use a power up
>         viii) Execute() - Returns to C++ via coroutine, C++ code then moves and executes action
>
> You could call (iv) to (vii) repeatedly, but nothing would happen until you call (viii), at which point the most recent call from (iv) to (vii) would be applied
>
> 3) If play returns and the player is not dead, play should be called again.
>
> Kev