Public Group

#### Archived

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

# Problems with AI Patterns :/

This topic is 5231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Heya! I''m programming AI for a sidescrolling game at digipen but I''m having some problem with pattern execution :/. I''ve been reading in patterns from text files into structures that are stored in vecotrs. I''ve tried out 2 types of patterns: 1. Waypoints where the enemy calculates vectors to reach and 2. Direct commands (1 would equal x=1 y+0) I''ve had better luck with the commands but am still having a few problems. I guess I''d just like to know how you guys handle AI Patterns (no hard coding them though). Any input would be greatly appreciated! Thanks, Ben

##### Share on other sites

[edited by - ETFBlade on January 23, 2004 5:49:10 PM]

##### Share on other sites
what do you mean by AI Patterns? is it a book? do you mean you are just having problem with your AI and controlling character behavior?

what does this mean: "Direct commands (1 would equal x=1 y+0)"? what is x? what is y?

are you trying to read in scripts for your AI instead of coding the behavior and then needing to compile it? it think probably this is most likely what you are talking about. There are plenty of tutorials on this site for writing an in game scripting language. you could do something like that and write you AI scripts in that language. We have a hard-coded state machine for the AI behavior and you can write scripts that put the AI into different states under different conditions. Another way to do is by using some kind of hard-coded behavioral paradigm and using your scripts to give different things different "weights" in that AI's psyche. So for instance, with the same system you could have coward AIs, tough-guy AIs, etc.

so, anyway, please clarify what you are asking, and also try reading the AI section in the articles and resources area of this site. it may give you some ideas. it might also help to run to a bookstore and take a peek at a copy of AI Game Programming Wisdom. it's a really good book and even just reading it at a bookstore will help you get ideas.

-me

[edited by - Palidine on January 23, 2004 5:49:14 PM]

##### Share on other sites
Hehe, sorry

Anyways, I''m not really worried about AI as much as I am with enemy patterns (I guess the title was misleading :/ ). I''m looking for a way to pre-define movement patterns for my enemies. I said that I''ve tried reading in waypoints form a file (offset from the enemy''s local x,y coords) and also directions. The latter method is used by using a switch statement to check for movement flags. Thus, 1-3 could be read in from a text file. The 1 would stand for "move right" and thus the enemy''s x coordinate value would increase by 1 for 3 gameloops (that''s what the 3 in 1-3 is for).

I was just wondering how other people stored and executed movement patterns... not really interested in scripting or anything yet :/

Thanks

##### Share on other sites
gottit

So if you want good pathfinding and easily defined unit movements check out waypoints and read up on the A* algorithm for pathfinding. you can set your waypoints beforehand (like your read from file scenario) or you can have the waypoints/paths be essentially be computed at run-time by having the A* search through all your tiles/polys/whatever. the A* will make efficient use of your waypoints provided you set up the appropriate heuristic.

with waypoints it''s important to remember to have actual paths encoded within them. such as each node is only connected to a few other nodes and not to every other node. i.e. if your unit is at 1, it must understand that it must travel through 2,3&4 before getting to 5. otherwise your waypoints aren''t a path, you''ll always just travel in a straight line to your destination which will make things wacky and get your units stuck.

so yeah, look up A*. learn it, love it. there are lots of variations beyond the basic algorithm once you get it working, to make your units move much more realistically and actually do things like react to your presence.

-me

##### Share on other sites
Awesome! Actually, I've seen A* around before and I do want to learn it.... but right now I'm doing a yoshi's island style game... and I think something simpler might be easier to work with... I guess I'm still confused about storing the patterns. Right now, I have the instruction structure which looks as follows:

struct mvNode{char mvFlag; //movement instruction (1= move left)int duration; // # of game loops that the flag is executed for};typedef vector<mvNode> pattern;

and inside my enemy class:

vector<pattern> pList;vector<mvNode> currPat;

The pList is filled with patterns applicable for the current enemyType out of a text file. Then, every time a pattern finishes, currPat is cleared and replaced with a random pattern (after checking for collision and whatnot)....

This is giving me some problems and there has got to be a better way to do it .... hehe...

[edited by - chippolot on January 23, 2004 6:23:32 PM]

[edited by - chippolot on January 23, 2004 6:24:57 PM]

##### Share on other sites
a better way to do it would be:

//just here for completeness. just a cordinate in your worldstruct Coord {    float x, y, x;};//the waypoint structstruct Waypoint {    //the waypoint's position    Cord pos;    //information about other waypoints reachable from this one    unsigned int numConnectedTo;    Waypoint * connectedTo;};

now basically to get your character from point A to point B, you run an A* over your network of waypoints starting the search at the waypoint closest to point A (assuming that A is reachable from your position...but add this wrinkle later).

movement should not be handled by the waypoint system. basically you are queuing move orders in your unit. go to 1 then 2 then 3. the actual movement should be handled internal to your unit. i.e:
move at my movement speed in the direction of my next waypoint.
when i get there, move to the next waypoint
repeat until i'm at my last waypoint.

make sense?

[EDIT: to get started, forget about the A* part and just construct a simple linear waypoint list. have each waypoint connect to only one other waypoint. place you enemy at one end and and get it to go to the other end. this will force you to develop your movement system so that an AI can have a goal position and be able to move itself there which is your first hurdle. when you get this working, try making the waypoints be a curve or something cooler so you can get a sense of accomplishment. then look up A* and hook it into your linear waypoint system and get that to work. then slowly make the waypoint system be more complex, have it be a Y, then and X then more complicated. when you get to the end you'll have a decent AI navigation system]

-me

[edited by - Palidine on January 23, 2004 6:43:14 PM]

##### Share on other sites
I think Ben isnt talking about pathfinding, but means a linear path for a enemy to follow.
Like in space invaders at certain times the alien craft would swoop down following a path.

If that is what you mean, then you seem to have the basic idea right. You could change the details like use link lists instead of a vector if you wanted but the basic idea is the same.
I would include a x and y value in your struct instead of a direction then each step you would add these to the enemy currect location (x,y).

Struct mvNode{
int x,y,duration;
};

so to move right would have be: x=1,y=0
to move left would be :x=-1,y=0

Still I''m not sure exactly what you are having problems with?
If they wont follow the path then without seeing more of your code, I cant really say where you are going wrong.
If you want to just include the waypoints then you just need to work out the direction vector for them to follow and for how long to follow it.
Say a waypoint was (+10,+20) then each step it would move (+1,+2) and move for 10 steps.
For most games its not really any different from using x=1,y=2,duration=10 in the above struct except you use one less int but have to work out the values yourself.

To decide on which pattern to follow there are lots of methods you could use, this is moving more into AI then the pattern following.
Maybe include a difficult level for each pattern and if you have some pattern which are for attack and some which are move for defense then include a value to show this. Then each enemy could have a state which would decide if it should use a attacking or defense pattern and which level of pattern to use.
You could also make the patterns into groups so when you have say 4 enemy craft they could pick a group and each follow a different one of the patterns in that group to attack from diffent directions.

I hope I understood what you meant and that the above is a little bit of help.

• 22
• 10
• 19
• 14
• 20