[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: noob - How to architect c++ code to use lua as external code
- From: Kevin Martin <kev82@...>
- Date: Sun, 21 Oct 2012 22:55:28 +0100
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