Archived

This topic is now archived and is closed to further replies.

Anidem

Visual Basic State Machines and other AI

Recommended Posts

A Finite State Machine in its simplest form is just a big series of if-then statements, which can be efficiently implemented as a switch statement!

There are lots of other ways to make a FSM though. I suggest you read the articles and resources seciton above and search google... there''s heaps of info out there!

Cheers,

Timkin

Share this post


Link to post
Share on other sites
Ok, so if say I have a unit that has a vision ammount of X.
If a enemy unit comes into a circle with a diameter of x a "Trigger would be set" a the begging of a loop? Then Later on in the loop the Variable would be checked for states like this
if state = MY_CONST_ALERT_STATE Then ''Do killing.
A FSM is as easy as this????

Share this post


Link to post
Share on other sites
You can remove a superfluous post by selecting edit at the right hand end of the blue bar over the post, then selecting the check box at the top of the modifications page that says "delete post". I could do this for you, but you wouldn''t see how easy it is to do!

As for your FSM question, yes, it''s that easy... although you will want to design your FSM (initially) so that it can only be in one state at any given time.

A more advanced FSM would be a layered-FSM model, where for instance, the NPC could be in conversation mode while killing one of your friends! More often than not though, this sort of layered FSM is used to create complex behaviours from a finite set of simpler behaviours, in the same way that behaviour-based robots came about.

Cheers,

Timkin

Share this post


Link to post
Share on other sites
''A Finite State Machine in its simplest form is just a big series of if-then statements, which can be efficiently implemented as a switch statement!"


Why would you use a bunch of If-Then statements? VB supports switch(select case) statements.

Share this post


Link to post
Share on other sites
He was refering to concept, not syntax. And the if-then statments may very well refer to a number of different stimuli (i.e. input variables) whereas a switch (or case statement) would only be responding to one or a boolean series of them.

Dave Mark - President and Lead Designer
Intrinsic Algorithm -
"Reducing the world to mathematical equations!"
RIPPL Sports - NFL Statistical Analysis and Prediction System

Share this post


Link to post
Share on other sites
quote:
Original post by DivemasterDave
''A Finite State Machine in its simplest form is just a big series of if-then statements, which can be efficiently implemented as a switch statement!"

Why would you use a bunch of If-Then statements? VB supports switch(select case) statements.

a switch statement is just a better looking shortcut for a series of if-then-elseif statements... i''m sure that Timkin knows this and was trying to explain it in a simple way... note the "simplest form" phrase in that quote!
he also mentioned that a switch statement is a way to efficiently implement it.
sorry to have so much fun pointing out your dumbness, but it''s all right in the quote that YOU quoted! heh heh...

Share this post


Link to post
Share on other sites
Thanks for the responses to clear up the misunderstanding. Just to expand on what I said a little more...

A Finite State Machine is also known as a stimulus-response system, or sometimes a stimulus-response agent, since agents are just entities that perceive and act.

The simplest way to write down a stimulus-response agent is to list all of the stimuli that the agent will react to and the action they''ll take in that situation. Therefore, you get a list of rules of the form if condition i then action j.

This is a finite state machine in its simplest form. Obviously though, if your programming in a language that efficiently implements nested if-then-else statements, then you''d use the efficient method... which is what I suggested above. In some languages, that''s a switch statement.

Just one final point... if you look under the hood of your compiler, the switch statement gets compiled into the same structure that the nested if-then-else statement is compiled to... so they''re actually the same thing.

Cheers,

Timkin

Share this post


Link to post
Share on other sites
quote:
Original post by Timkin
Just one final point... if you look under the hood of your compiler, the switch statement gets compiled into the same structure that the nested if-then-else statement is compiled to... so they're actually the same thing.



Muaa... Not so sure about that. In C++, I heard switch statements could be converted into look-up tables for efficiency (that's why they only allow integer values).

I don't know about VB though. Anyway, this is OT

Cédric



[edited by - cedricl on July 18, 2002 10:13:45 AM]

Share this post


Link to post
Share on other sites