Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 help me with AI for Pacman
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Vertico




PostPosted: Mon Apr 18, 2005 3:21 pm   Post subject: help me with AI for Pacman

i have the game pretty much done but for the AI. i mena its very eazy to get around the AI i have now becuz they dont actualy chase you. All they do it randomly move around until they hit a wall. then they randomly pick another direction and keep going.

I cant think of a way to get them to chase you around the screen with out getting stuck in the walls.

Any ideas Question
Sponsor
Sponsor
Sponsor
sponsor
Bored




PostPosted: Mon Apr 18, 2005 3:40 pm   Post subject: (No subject)

Have them check where you are as compared to there position. So if your to there right they'll travel in that direction if they can.
code:

if p1XPos > cpu1XPos then
    direction := "up"
elsif .......
end if
if direction = "up" then
    .......
elsif.......
end if
Vertico




PostPosted: Mon Apr 18, 2005 4:19 pm   Post subject: (No subject)

that doesnt work becuz it will keep going up or down depending on if im above it or below it.

also it gets stuck against the walls cuz it keeps trying to go in that direction
jamonathin




PostPosted: Mon Apr 18, 2005 8:48 pm   Post subject: (No subject)

have each computer have a boolean variable for up/down/left/right. You'll have to do this for however many comps you have, so put it into an array.

code:
if y > compy then
up(comp) := true
else
up(comp) :=false
end if
%Repeat for left / right / down

Now, use whatdotcolor. We'll know what needs to be done, but make sure you are always running those if statements, because obviously the human player moves.
So . . .
code:
if up = true and whatdotcolor(compx,compy + height) = good then
compy += difference
end if
% Now repeat this for Left / Right / Down

Try this out, and if it doesn't work, send me your code and I'll help you fix it up.
Note: use a forloop to check the if statements.
code:
for i : 1 .. comp#
if whatever then
fart(i):=true
end if
end for


EDIT: Now if the player is directly ontop of the computer, keep checking the whatdotcolors, and pick a direction the comp can go (left/right), and once the whatdotcolor for up is ok, then get rid of the side movements, and have him haul his ass up. And use the same concept for sideways and downwards.
Martin




PostPosted: Mon Apr 18, 2005 9:18 pm   Post subject: (No subject)

I've posted a bunch of stuff about pacman AI. Search the forums.
Vertico




PostPosted: Tue Apr 19, 2005 4:44 pm   Post subject: (No subject)

i have tryed what you said jamonathin and it works, .... but it doesnt do both. i mean

if i start off to the left of the monster then it trys to go left. or if i start on its right it comes to the right. but it doesnt go up or down. i think maby it has something to do with the for loop u were talking about, but i dont know where or how to put it in.

also i did look in the help fourm and older messages about the same thing but none truly answered my question. i want this game to be like the real pacman. with decent AI, not just something that wonders around but will chase u and not get stuck. Also so it doesnt stop and wait for you 2 move to decide if it should go left/right/up/down.
Martin




PostPosted: Tue Apr 19, 2005 7:50 pm   Post subject: (No subject)

First ghost - Finds the shortest path to pacman
Second ghost - Finds the next shortest path to pacman
Third ghost - Tries to block off the teleporter.
Fourth ghost - Wanders.

For pathfinding, search google for the A-star algorithm, which is a quick algorithm for generating the shortest path.
StarGateSG-1




PostPosted: Wed Apr 20, 2005 7:34 am   Post subject: (No subject)

Use whatadotcolor to check for collosion and then move in a random direction!
Sponsor
Sponsor
Sponsor
sponsor
Vertico




PostPosted: Wed Apr 20, 2005 1:59 pm   Post subject: (No subject)

thz martin, ill look that up.

P.S. lol stargate did u not read what i typed above.
Drakain Zeil




PostPosted: Wed Apr 20, 2005 6:50 pm   Post subject: (No subject)

Build a file map, if the XY position's value is equal to a specific number then this governs all movements.

Ie.

00000
01020
03040
00000

Lets say that's your MOVEMENT map layer. (Infact, this is all you need for AI, since it can't break movement rules you set in place, it MUST follow these, wall checks are not needed now).

So, You tell the computer to deal with 1 as move down, 2 as move left, 3 as move right, 4 as move up, then you can even do things like 5 is randomly up or down, etc etc.

Make a movement map, stick it on, and good game.
jamonathin




PostPosted: Wed Apr 20, 2005 7:47 pm   Post subject: (No subject)

I say go with martin's idea for the AI. Plus, you could change difficulty if not all of the ghosts are chasing. As the levels progress, have more ghosts following.
Vertico




PostPosted: Wed Apr 20, 2005 8:10 pm   Post subject: (No subject)

ya i haven't gotten time to look up what he said. ill do that tomorrow.

and i dont know what ur talking about zeil, can u plz expand on what ur talking about. maby "dumb" it down for me.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: