Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / I need some feedback on my ai i made for pacman.

Author
Message
darkvee
19
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 21st Nov 2008 00:52
Hi this is Vee
I think my ai is good enough for Pacman, but I need your opinions on thanks.
here is link
http://files.filefront.com/Vees+Artificial+Intelligedzip/;12412784;/fileinfo.html

Vee
Tinyschu
19
Years of Service
User Offline
Joined: 31st Dec 2005
Location: Toxin Games Studio
Posted: 21st Nov 2008 01:53
Think it is pretty good. There is only one minor problem and that is there are some that will just go back and foreth on the top row, but other than that I think it is pretty close to Pacman AI. Good job!

darkvee
19
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 23rd Nov 2008 07:29
Hi Tinyschu
Thanks for reviewing it for me
Thanks man I am very glad its good enough.
Now I need some more people to rate it.

Vee
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Nov 2008 11:45
Apart from the ghosts changing direction all the time, it's pretty good - they should only change direction at a corner/junction.

pollywog
18
Years of Service
User Offline
Joined: 18th Jan 2007
Location:
Posted: 24th Nov 2008 18:56
I don't know if this will be of any use to you or not but
I was working on a pac-man type game for our kids at church.
I made a series of waypoints at each corner/junction and set them to invisible. (I included all my source code as an attachment I have the waypoints set to visible in the code) by the way there is a really good pac-man and ghosts available for free at
http://reinerstileset.4players.de/monstersE.html


type waypointtype `this type is used for pathfinding for the ghosts
spritenum as integer
x as integer
y as integer
AllowedToMoveNorth as boolean
AllowedToMoveEast as boolean
AllowedToMoveSouth as boolean
AllowedToMoveWest as boolean
endtype

here is the code where I placed them
`***********************Create Waypoints**************************************************
function createwaypoints()
for i = 1 to NumOfWaypoints
Waypoint(i).spritenum = i + 450
next i

waypoint(1).x = 20: waypoint(1).y = 30
waypoint(1).AllowedToMoveNorth = FALSE : waypoint(1).AllowedToMoveEast = TRUE
waypoint(1).AllowedToMoveSouth = TRUE : waypoint(1).AllowedToMoveWest = FALSE

waypoint(2).x = 130: waypoint(2).y = 30
waypoint(2).AllowedToMoveNorth = FALSE : waypoint(2).AllowedToMoveEast = TRUE
waypoint(2).AllowedToMoveSouth = TRUE : waypoint(2).AllowedToMoveWest = TRUE

waypoint(3).x = 270 : waypoint(3).y = 30
waypoint(3).AllowedToMoveNorth = FALSE : waypoint(3).AllowedToMoveEast = FALSE
waypoint(3).AllowedToMoveSouth = TRUE : waypoint(3).AllowedToMoveWest = TRUE

waypoint(4).x = 340 : waypoint(4).y = 30
waypoint(4).AllowedToMoveNorth = FALSE : waypoint(4).AllowedToMoveEast = TRUE
waypoint(4).AllowedToMoveSouth = TRUE : waypoint(4).AllowedToMoveWest = FALSE

waypoint(5).x = 485 : waypoint(5).y = 30
waypoint(5).AllowedToMoveNorth = FALSE : waypoint(5).AllowedToMoveEast = TRUE
waypoint(5).AllowedToMoveSouth = TRUE : waypoint(5).AllowedToMoveWest = TRUE

waypoint(6).x = 600 : waypoint(6).y = 30
waypoint(6).AllowedToMoveNorth = FALSE : waypoint(6).AllowedToMoveEast = FALSE
waypoint(6).AllowedToMoveSouth = TRUE : waypoint(6).AllowedToMoveWest = TRUE
`**************************************************************************************

finally I pick the direction the ghost should move when it hits a waypoint.

`***************************PickDirection(i,j)*******************************************
` g is the index of the ghost w is the index of the waypoint
function PickDirection(g,w)
ghost(g).WantsToGoNorth = FALSE : ghost(g).WantsToGoSouth = FALSE
ghost(g).WantsToGoEast = FALSE : ghost(g).WantsToGoWest = FALSE
if ghost(g).isScared = false
if pacman.yposition > ghostmiddle(g).yposition then ghost(g).WantsToGoSouth = True
if pacman.yposition < ghostmiddle(g).yposition then ghost(g).WantsToGoNorth = True
if pacman.xposition > ghostmiddle(g).xposition then ghost(g).WantsToGoEast = True
if pacman.xposition < ghostmiddle(g).xposition then ghost(g).WantsToGoWest = True
else
if pacman.yposition > ghostmiddle(g).yposition then ghost(g).WantsToGoNorth = True
if pacman.yposition < ghostmiddle(g).yposition then ghost(g).WantsToGoSouth = True
if pacman.xposition > ghostmiddle(g).xposition then ghost(g).WantsToGoWest = True
if pacman.xposition < ghostmiddle(g).xposition then ghost(g).WantsToGoEast = True
endif


do
PickaDirection = rnd(3) + 1
percent2 = rnd(99) + 1
`check north
if PickaDirection = NORTH and waypoint(w).AllowedToMoveNorth and (percent2 < 5 or ghost(g).WantsToGoNorth)
ghost(g).direction = North
exit
endif
`check east
if PickaDirection = EAST and waypoint(w).AllowedToMoveEast and (percent2 < 5 or ghost(g).WantsToGoEast)
ghost(g).direction = East
exit
endif
`check south
if PickaDirection = SOUTH and waypoint(w).AllowedToMoveSouth and (percent2 < 5 or ghost(g).WantsToGoSouth)
ghost(g).direction = South
exit
endif
if PickaDirection = WEST and waypoint(w).AllowedToMoveWest and (percent2 < 5 or ghost(g).WantsToGoWest)
ghost(g).direction = West
exit
endif
loop
endfunction

Attachments

Login to view attachments
darkvee
19
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 26th Nov 2008 23:14
Hi thanks everyone
IanM, thanks for taking a look at it and rating it.
Pollywog, so I just need to make a waypoint system that I, place a waypoint at each intersection, and make the ghost choose a random direction?

Vee
zenassem
22
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 27th Nov 2008 00:24 Edited at: 27th Nov 2008 00:28
There were some things I didn't find right about it. Including the above mentioned issues.

The Ai doesn't seem to really be doing a good job of randomly searching the maze when pacaman is not in their sight. At least not any that I could see. They all seemed to be moving back and forth, and only changed their state if they saw me.

And when they followed me, they followed me too precisely. There was no way to shake them off or lose them around corners, except if they bounced off a maze wall. And they never tried to go a different direction in hopes of cutting me off, if they bounced off a wall they just went back to their back and forth state.

Pacman's AI used a behavioral state machine. And each ghost had their own personality traits, and manners in which they chased pacman. So you never wound up with all 4 ghosts following your exact path for too long. And they tried to collapse in on you from different directions.

"When I look at that square... I wish FPSC noobs would stay on their side of the forums and stop polluting these boards." - Benjamin
pollywog
18
Years of Service
User Offline
Joined: 18th Jan 2007
Location:
Posted: 28th Nov 2008 15:14
for the waypoint system you do place on at each intersection but the ghosts don't chase you randomly.

1) compare pack mans position to the ghosts position and assign some variables. Lets say pac man is above and to the left of the ghost then ghostWantsToGoNorth and ghostWantsToGoWest are true and the others are false.

2) when you create the waypoints assign which directions the ghosts are allowed to go. so for this example lets say the waypoint is at the bottom of the maze and there is an obstacle to left so
waypoint.allowedToGoSouth = false and waypoint.allowedToGoWest = false. the other two directions are true.

3) ok now enter an infinite loop that you can only break out of when the ghost picks a direction
do
4) pick to random variables one is for direction and one is just a random number between 1 and 100 to add some randomization to the ghosts.

5) go through four series of if statements checking directions and exit if it is true otherwise go back to the top of the loop and try again.
so lets go through our example the ghost wants to go north or west and the waypoint allows him to go North and East.
the statement PickaDirection = rnd(3) + 1 came up with 1 lets say that we assigned 1 to be North.
and percent2 = rnd(99) + 1 came up to be 4.

the first if statement checks north
`check north
if PickaDirection = NORTH and waypoint(w).AllowedToMoveNorth and (percent2 < 5 or ghost(g).WantsToGoNorth)
ghost(g).direction = North
exit
endif

so lets go through it. the pick direction did = North so we are cool there. The waypoint is allowing the ghost to go north so we are good there. and the ghost wants to go north is also true. great so we assign the ghosts direction as North and he travels north until he hits the next waypoint. Also notice that even if the ghost didn't want to go north he would have because of the statement percent2 < 5 our percent 2 was less than 5 so 5% of the time the ghost is going to go the wrong way (not towards packman).

whats nice about this system is that when you eat the powerups you can assighn a variable to the ghosts I think mine is ghost.GhostIsScared = true. and just set the way the ghost wants to go opposite of what it was before you start picking a direction.
So in our case the ghost wanted to go North and West but if the ghost is scared we change that to ghost wants to go South and East because instead of chasing pac man he is trying to get away.

hope this was useful

Login to post a reply

Server time is: 2025-06-17 06:52:31
Your offset time is: 2025-06-17 06:52:31