LUA and AI

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

LUA and AI

Christophe Gimenez
Okay that seems a strange question...

But here is my problem : as I would (and will) use LUA as the scripting 
langage for a game project I've started to find information about AI in 
games (and of course I don't know a word about AI).

Thus, do you think that implementing basic AI principles could be done with 
LUA ?

If yes, we to start from ?

I've spent many many many hours and collected many many many links, pdf, 
doc, html files but for the moment I could'nt learn some basic that I could 
use in a game.

thanks

[ if there is an AI-GOD in the mailing list, please send me a mail ;-) ]

Reply | Threaded
Open this post in threaded view
|

Re: LUA and AI

Nicholas Hesketh
That would depend on the sort of AI you're trying to do, and the number of entities you need to do
it for.

For the mid to high level portion of rpg character AI it should be ideal as the scripting
flexibility outweighs computational overhead, and you can always migrate the expensive stuff to
C/C++ as the game develops.

Using it for adaptive pathfinding of several hundred units in a strategy game is probably not a good
idea though ;-)

It's a case of flexibility verses performance, but you'll probably find scripting useful for at
least a portion of your game logic.

Nick Hesketh.
-----Original Message-----
From: Christophe Gimenez <[hidden email]>
To: Multiple recipients of list <[hidden email]>
Date: 24 March 2000 19:51
Subject: LUA and AI


>
>Okay that seems a strange question...
>
>But here is my problem : as I would (and will) use LUA as the scripting
>langage for a game project I've started to find information about AI in
>games (and of course I don't know a word about AI).
>
>Thus, do you think that implementing basic AI principles could be done with
>LUA ?
>
>If yes, we to start from ?
>
>I've spent many many many hours and collected many many many links, pdf,
>doc, html files but for the moment I could'nt learn some basic that I could
>use in a game.
>
>thanks
>
>[ if there is an AI-GOD in the mailing list, please send me a mail ;-) ]
>
>

Reply | Threaded
Open this post in threaded view
|

Re: LUA and AI

Sean Thomas Middleditch
Nicholas Hesketh wrote:

> That would depend on the sort of AI you're trying to do, and the number of entities you need to do
> it for.
>
> For the mid to high level portion of rpg character AI it should be ideal as the scripting
> flexibility outweighs computational overhead, and you can always migrate the expensive stuff to
> C/C++ as the game develops.
>
> Using it for adaptive pathfinding of several hundred units in a strategy game is probably not a good
> idea though ;-)
>
> It's a case of flexibility verses performance, but you'll probably find scripting useful for at
> least a portion of your game logic.
>
> Nick Hesketh.
> -----Original Message-----
> From: Christophe Gimenez <[hidden email]>
> To: Multiple recipients of list <[hidden email]>
> Date: 24 March 2000 19:51
> Subject: LUA and AI
>
> >
> >Okay that seems a strange question...
> >
> >But here is my problem : as I would (and will) use LUA as the scripting
> >langage for a game project I've started to find information about AI in
> >games (and of course I don't know a word about AI).
> >
> >Thus, do you think that implementing basic AI principles could be done with
> >LUA ?
> >
> >If yes, we to start from ?
> >
> >I've spent many many many hours and collected many many many links, pdf,
> >doc, html files but for the moment I could'nt learn some basic that I could
> >use in a game.
> >
> >thanks
> >
> >[ if there is an AI-GOD in the mailing list, please send me a mail ;-) ]
> >
> >

AI is fun.  The best AI model I've seen was implemented in Java for a roguelike game... The
object-oriented nature rocked.

For an AI, write the unmutable stuff (like pathfinding, logic, etc.) in your C/C++ code.  Then write
the control in script.

Something like (in PSEUDO code)

if (see_enemy) then
 enter_battle ()
endif

if (is_dying) then
 find_path (ESCAPE)
 follow_path ()
endif

etc.
That's a damn poor example, but I'm tired, so I have an excuse.  ;-)

I think for controlling actions (like go north 3, west 4, get item, east 6, say "My, it is raining
frogs.", attack duck,  south 3, west 2, say "Oh no!  I lost my magic Blunt Stick of Sharpness!!!") a
specialized language would do best... something simple like

MOVE east 3
SAY "I'm lost"

is best.

Sean Middleditch



Reply | Threaded
Open this post in threaded view
|

RE: LUA and AI

Christophe Gimenez
In reply to this post by Christophe Gimenez
My question was unclear...

Of course the A* algorythme will be only implement in C++...

The problem is :

1) we have (will have) 100 functions available for the scripts (ex: 
castOf(who), isPlayer(who))
2) we have 10 or 20 incoming type of message (ex: on_hitBy(who), 
on_near(who),)

Some NPC must be able to be pre-programmed to execute a succesion of 
commands : that's the problem, I have no idea of doing a such thing and I 
don't know of to avoid TONS and TONS of "if then else"... I think (but I'm 
perhaps wrong), that having some simple knowledge in AI would help, but I 
can't find any thing on the web to help me (I've red many many articles but 
nothing help)

Any idea or am I always unclear ?

Thanks

-----Message d'origine-----
De:	Sean Thomas Middleditch [SMTP:[hidden email]]
Date:	samedi 25 mars 2000 01:22
A:	Multiple recipients of list
Objet:	Re: LUA and AI

Nicholas Hesketh wrote:

> That would depend on the sort of AI you're trying to do, and the number 
of entities you need to do
> it for.
>
> For the mid to high level portion of rpg character AI it should be ideal 
as the scripting
> flexibility outweighs computational overhead, and you can always migrate 
the expensive stuff to
> C/C++ as the game develops.
>
> Using it for adaptive pathfinding of several hundred units in a strategy 
game is probably not a good
> idea though ;-)
>
> It's a case of flexibility verses performance, but you'll probably find 
scripting useful for at
> least a portion of your game logic.
>
> Nick Hesketh.
> -----Original Message-----
> From: Christophe Gimenez <[hidden email]>
> To: Multiple recipients of list <[hidden email]>
> Date: 24 March 2000 19:51
> Subject: LUA and AI
>
> >
> >Okay that seems a strange question...
> >
> >But here is my problem : as I would (and will) use LUA as the scripting
> >langage for a game project I've started to find information about AI in
> >games (and of course I don't know a word about AI).
> >
> >Thus, do you think that implementing basic AI principles could be done 
with
> >LUA ?
> >
> >If yes, we to start from ?
> >
> >I've spent many many many hours and collected many many many links, pdf,
> >doc, html files but for the moment I could'nt learn some basic that I 
could
> >use in a game.
> >
> >thanks
> >
> >[ if there is an AI-GOD in the mailing list, please send me a mail ;-) ]
> >
> >

AI is fun.  The best AI model I've seen was implemented in Java for a 
roguelike game... The
object-oriented nature rocked.

For an AI, write the unmutable stuff (like pathfinding, logic, etc.) in 
your C/C++ code.  Then write
the control in script.

Something like (in PSEUDO code)

if (see_enemy) then
 enter_battle ()
endif

if (is_dying) then
 find_path (ESCAPE)
 follow_path ()
endif

etc.
That's a damn poor example, but I'm tired, so I have an excuse.  ;-)

I think for controlling actions (like go north 3, west 4, get item, east 6, 
say "My, it is raining
frogs.", attack duck,  south 3, west 2, say "Oh no!  I lost my magic Blunt 
Stick of Sharpness!!!") a
specialized language would do best... something simple like

MOVE east 3
SAY "I'm lost"

is best.

Sean Middleditch

Reply | Threaded
Open this post in threaded view
|

RE: LUA and AI

Vincent Penquerc'h-2
> Some NPC must be able to be pre-programmed to execute a succesion of
> commands : that's the problem, I have no idea of doing a such thing and I
> don't know of to avoid TONS and TONS of "if then else"... I think
> (but I'm
> perhaps wrong), that having some simple knowledge in AI would help, but I
> can't find any thing on the web to help me (I've red many many
> articles but
> nothing help)
You might want to search Amit Patel's page in a web search engine.
It's full of very interesting stuff on AI...

--
Lyrian

Reply | Threaded
Open this post in threaded view
|

Re: LUA and AI

Sean Thomas Middleditch
In reply to this post by Christophe Gimenez
Hmm, I'm still not sure what it is you mean, then.

E-Mail be personally at [hidden email] and I'll see if I can
help.  I love playing with AI.  I was the lead AI developer for a few
niftified projects over the web, so I should be able to help.

Sean Middleditch

----- Original Message -----
From: Christophe Gimenez <[hidden email]>
To: Multiple recipients of list <[hidden email]>
Sent: Monday, March 27, 2000 8:03 AM
Subject: RE: LUA and AI


> My question was unclear...
>
> Of course the A* algorythme will be only implement in C++...
>
> The problem is :
>
> 1) we have (will have) 100 functions available for the scripts (ex:
> castOf(who), isPlayer(who))
> 2) we have 10 or 20 incoming type of message (ex: on_hitBy(who),
> on_near(who),)
>
> Some NPC must be able to be pre-programmed to execute a succesion of
> commands : that's the problem, I have no idea of doing a such thing and I
> don't know of to avoid TONS and TONS of "if then else"... I think (but I'm
> perhaps wrong), that having some simple knowledge in AI would help, but I
> can't find any thing on the web to help me (I've red many many articles
but
> nothing help)
>
> Any idea or am I always unclear ?
>
> Thanks
>
> -----Message d'origine-----
> De: Sean Thomas Middleditch [SMTP:[hidden email]]
> Date: samedi 25 mars 2000 01:22
> A: Multiple recipients of list
> Objet: Re: LUA and AI
>
> Nicholas Hesketh wrote:
>
> > That would depend on the sort of AI you're trying to do, and the number
> of entities you need to do
> > it for.
> >
> > For the mid to high level portion of rpg character AI it should be ideal
> as the scripting
> > flexibility outweighs computational overhead, and you can always migrate
> the expensive stuff to
> > C/C++ as the game develops.
> >
> > Using it for adaptive pathfinding of several hundred units in a strategy
> game is probably not a good
> > idea though ;-)
> >
> > It's a case of flexibility verses performance, but you'll probably find
> scripting useful for at
> > least a portion of your game logic.
> >
> > Nick Hesketh.
> > -----Original Message-----
> > From: Christophe Gimenez <[hidden email]>
> > To: Multiple recipients of list <[hidden email]>
> > Date: 24 March 2000 19:51
> > Subject: LUA and AI
> >
> > >
> > >Okay that seems a strange question...
> > >
> > >But here is my problem : as I would (and will) use LUA as the scripting
> > >langage for a game project I've started to find information about AI in
> > >games (and of course I don't know a word about AI).
> > >
> > >Thus, do you think that implementing basic AI principles could be done
> with
> > >LUA ?
> > >
> > >If yes, we to start from ?
> > >
> > >I've spent many many many hours and collected many many many links,
pdf,
> > >doc, html files but for the moment I could'nt learn some basic that I
> could
> > >use in a game.
> > >
> > >thanks
> > >
> > >[ if there is an AI-GOD in the mailing list, please send me a mail
;-) ]
> > >
> > >
>
> AI is fun.  The best AI model I've seen was implemented in Java for a
> roguelike game... The
> object-oriented nature rocked.
>
> For an AI, write the unmutable stuff (like pathfinding, logic, etc.) in
> your C/C++ code.  Then write
> the control in script.
>
> Something like (in PSEUDO code)
>
> if (see_enemy) then
>  enter_battle ()
> endif
>
> if (is_dying) then
>  find_path (ESCAPE)
>  follow_path ()
> endif
>
> etc.
> That's a damn poor example, but I'm tired, so I have an excuse.  ;-)
>
> I think for controlling actions (like go north 3, west 4, get item, east
6,
> say "My, it is raining
> frogs.", attack duck,  south 3, west 2, say "Oh no!  I lost my magic Blunt
> Stick of Sharpness!!!") a
> specialized language would do best... something simple like
>
> MOVE east 3
> SAY "I'm lost"
>
> is best.
>
> Sean Middleditch
>
>

Reply | Threaded
Open this post in threaded view
|

RE: LUA and AI

Ashley Fryer-2
In reply to this post by Christophe Gimenez

> From: Christophe Gimenez
> Sent: Monday, March 27, 2000 5:05 AM
>
> 1) we have (will have) 100 functions available for the scripts (ex:
> castOf(who), isPlayer(who))
> 2) we have 10 or 20 incoming type of message (ex: on_hitBy(who),
> on_near(who),)
>
> Some NPC must be able to be pre-programmed to execute a succesion of
> commands : that's the problem, I have no idea of doing a such thing and I
> don't know of to avoid TONS and TONS of "if then else".


It looks like you are planning to use an event-driven approach, which is
good.

Some additional event-hooks you might use:

Time-based callbacks:  on_Time(who)
This allows you to write loops.  Each iteration of the loop is another
callback.  This keeps the other scripts from hanging while the loop is going
on.

Pathfinding callbacks: on_GoalSuccess(who), on_GoalFail(who)
This calls the object back when the path-finding engine stops moving it.

Animation callbacks: on_AnimationFinished(who)
This calls the object when its one-time animation is finished.  This is
important if you want to string a series of animated behaviors together.

Input callbacks: on_KeyDown, on_MouseMove, etc.
This lets objects track user input.  If you have NPCs which can have dialog
with the user, you'll need some way for the NPC to get input.


About implementing callbacks... work out a way for each callback to carry
extra data from the object.  For example, suppose you would normally
register a pathing callback with:

    WalkTo( who, goal_x, goal_y )

Allow the caller to attach optional extra data to the callback with:

    WalkTo( who, goal_x, goal_y, EXTRA_DATA )

Then when the callback occurs:

    on_GoalSuccess( who, EXTRA_DATA )

The object's data is passed back.  There are millions of situations where
this comes in handy, and it can simplify your code.


For the rest of your NPC programming, take a look at finite state machines.
The behavior of your NPCs can be modelled as FSMs, where each state
transition is triggered by one of the on_Events.  Lua's tables and
function-objects make it a good language for implementing this.

Regards,
ashley


Reply | Threaded
Open this post in threaded view
|

RE: LUA and AI

Christophe Gimenez
In reply to this post by Christophe Gimenez
Thanks alot for your answers !!

-----Message d'origine-----
De:	Ashley Fryer [SMTP:[hidden email]]
Date:	lundi 27 mars 2000 23:45
A:	Multiple recipients of list
Objet:	RE: LUA and AI


It looks like you are planning to use an event-driven approach, which is
good.

--> Yes and here is THE rule : "never handle immediatly a message that have 
been fired by a response to a message"
I will use a "one turn" handling event method. If a message fire another 
event this message will be put in the queue of the pending events.

Some additional event-hooks you might use:

Time-based callbacks:  on_Time(who)
This allows you to write loops.  Each iteration of the loop is another
callback.  This keeps the other scripts from hanging while the loop is 
going
on.

--> Can you explain further please ? What do you mean by "Each iteration of 
the loop is another
callback."
I thought that each script function (on_xxx) would never contain any loop 
to avoid blocking the game. As I don't want to use any kind of 
multithreading (too hard for me).
Please explain, I think I'm missing something !!

Pathfinding callbacks: on_GoalSuccess(who), on_GoalFail(who)
This calls the object back when the path-finding engine stops moving it.

Animation callbacks: on_AnimationFinished(who)
This calls the object when its one-time animation is finished.  This is
important if you want to string a series of animated behaviors together.

--> Okay... I thought it was useless but that could be a good idea

Input callbacks: on_KeyDown, on_MouseMove, etc.
This lets objects track user input.  If you have NPCs which can have dialog
with the user, you'll need some way for the NPC to get input.

--> Honnestly I would prefer to avoid handling direcly the input of the 
user... (not yet defined how the dialog will be handled)

About implementing callbacks... work out a way for each callback to carry
extra data from the object.  For example, suppose you would normally
register a pathing callback with:

    WalkTo( who, goal_x, goal_y )

Allow the caller to attach optional extra data to the callback with:

    WalkTo( who, goal_x, goal_y, EXTRA_DATA )

Then when the callback occurs:

    on_GoalSuccess( who, EXTRA_DATA )

The object's data is passed back.  There are millions of situations where
this comes in handy, and it can simplify your code.

--> Yes good idea too !

For the rest of your NPC programming, take a look at finite state machines.
The behavior of your NPCs can be modelled as FSMs, where each state
transition is triggered by one of the on_Events.  Lua's tables and
function-objects make it a good language for implementing this.

--> I've tried to find information about FSM but never found a document 
that was really easy to understand...

Regards,
ashley

Reply | Threaded
Open this post in threaded view
|

RE: LUA and AI

Vincent Penquerc'h-2
> Input callbacks: on_KeyDown, on_MouseMove, etc.
> This lets objects track user input.  If you have NPCs which can 
> have dialog
> with the user, you'll need some way for the NPC to get input.
> 
> --> Honnestly I would prefer to avoid handling direcly the input of the 
> user... (not yet defined how the dialog will be handled)

About this one, I do think it's way to lowlevel.
I thought I'd add my point here, because I've just worked on a dialog
system using Lua:
The entire dialog is written in C++.
The only hooks to Lua are an "onsay" trigger:
  character:onsay(who_told_me_that,what_that_person_told_me)
which allows the dialog to send what the player typed to the NPC
and a say method:
  say(who_says_that,who_is_told_that,what_is_said)
which is a C routine registered to Lua.
This allows complex dialogs very easily: since the onsay trigger
looks up the what_that_person_told_me word (I use keyword based
conversation) in a table, and the relevant field can be either
a string (the NPC's answer) or a Lua function (which can say
different things based on the game state).

I have more conplicated stuff to allow a NPC to provide predefined
answers to a question (basically yes/no questions, but can be any),
but the main stuff boils down to these two points of contact.
I'd like to hear if you come up with something different.

-- 
Lyrian 

Reply | Threaded
Open this post in threaded view
|

RE: LUA and AI

Ashley Fryer-2
In reply to this post by Christophe Gimenez
> From: Christophe Gimenez
> Sent: Tuesday, March 28, 2000 1:27 AM
>
> Time-based callbacks:  on_Time(who)
> This allows you to write loops.  Each iteration of the loop is another
> callback.  This keeps the other scripts from hanging while the loop is
> going
> on.
>
> --> Can you explain further please ? What do you mean by "Each
> iteration of
> the loop is another
> callback."

If you want to write a loop like this:

while condition do
   foo()
end


Then you can implement it as a timer callback like this:

function on_Timer()
   foo()
   if condition then
       SetTimer( interval, on_Timer )
   end
end

on_Timer()


Each iteration of the original "while" loop is replaced by a callback to
on_Timer.  My example assumes that SetTimer causes only one callback, so you
have to call SetTimer once for each iteration.  It's not hard to implement
this for other timer semantics though.


> Input callbacks: on_KeyDown, on_MouseMove, etc.
>
> --> Honnestly I would prefer to avoid handling direcly the input of the
> user... (not yet defined how the dialog will be handled)

This brings up a recurring issue with Lua development.  What's the best
place to draw the line between Lua and C code?  On the one hand, you want
the flexibility of Lua, on the other you want the speed and power of C.

I have found it helpful to start by writing low-level Lua interfaces, and
then supplement them with higher-level interfaces as need dictates.  This
way you always have maximum control and flexibility in Lua, and you only pay
for the power of C when you require it.

Regardless, I agree with you in this situation.  I ended up adding
higher-level APIs:

   on_PlaceAction( actor, to_place )
   on_ObjectAction( actor, to_object )

However, I kept the low-level mouse and key APIs and I sometimes use them
during testing and development.


> --> I've tried to find information about FSM but never found a document
> that was really easy to understand...

http://www.google.com/search?q=%22finite+state+machine%22+ai+game

A few of the links on the first page looked helpful, perhaps they are new to
you.

Regards,
ashley