Argh...AI is the toughest thing I've have seen in programming! I read a article about it http://ai-depot.com/FiniteStateMachines/ . Yet I still don't understand how to put this in blitzmax code.
AI..
BlitzMax Forums/BlitzMax Programming/AI.. There's nothing to it, mate. Start simple. Here's a simple one that should make a dot 'walk' left and right on the screen, turninng at each end. Don't have max here so may have a couple of bugs.
The heart of the machine is a select statement that executes the right code for the current state. In this example if the state is STATE_GO_RIGHT, we send our dot one pixel to the right and look to see if it got to the right edge of the screen. When it does, it flips the state to STATE_GO_LEFT which will start it walking to the left. The current state is just stored as an integer - declaring consts with names makes the code easier to read.
I know this behaviour wont seem very 'intelligent' but anything more complicated really just builds on this simple principle.
The heart of the machine is a select statement that executes the right code for the current state. In this example if the state is STATE_GO_RIGHT, we send our dot one pixel to the right and look to see if it got to the right edge of the screen. When it does, it flips the state to STATE_GO_LEFT which will start it walking to the left. The current state is just stored as an integer - declaring consts with names makes the code easier to read.
const STATE_GO_RIGHT=0 const STATE_GO_LEFT=1 current_state=STATE_GO_RIGHT x=0 graphics 800,600,32,60 repeat cls select current_state case STATE_GO_RIGHT x=x+1 if x=800 current_state=STATE_GO_LEFT case STATE_GO_LEFT x=x-1 if x=0 current_state=STATE_GO_RIGHT end select plot x,100 flip until keyhit(KEY_ESCAPE)
I know this behaviour wont seem very 'intelligent' but anything more complicated really just builds on this simple principle.
this might help and the download still works (good ole Morduun) with BB code which should be easy to read.
If you're into AI then check 'Programming Game AI by Example' by Mat Buckland which includes a great example of an FSM.
If you're into AI then check 'Programming Game AI by Example' by Mat Buckland which includes a great example of an FSM.
thank you tonyg! Yes blitzbasic is very similar to blitzmax and it's easy to convert it myself =P.
Programming Game AI by Example
Funny you should mention that one, I'm waiting for Mr Mailman to turn up any minute now with my copy of it. :)
It looks like an excellent book and it got some nice reviews at amazon.com.