yet again i found myself fighting against thinking about the data arrangement in code. i managed to realize i was doing it, and stopped. this is going to be an uphill battle.
1:16am [[ pathfinding ]]
pacman eats a power-pill.
result: sound is played. it should be only one sound that will play for as long as a ghost would stay in scared state. perhaps it should be used as the time length definition.
time to look at pathfinding. i heard someone mention something about graphs or something and i have no idea what thats all about. so instead, i'll make another method. for one thing, ghosts cannot go back to the tile they were on last. that means the only decisions they have to make are at intersections of 3 or 4 directions. let's look at how each ghost will decide which direction to take at an intersection.
i'm going to reference http://www.everything2.com/index.pl?node_id=499157 again for this.
the orange ghost, clyde, is random. when he hits an intersection he picks a direction randomly (but not the one he came from). this guy's easy.
the red ghost, blinky, is the shortest-route ghost. we need to figure out a way for him to find the shortest route from an intersection to pacman. [researching pathfinding algos] i'm only finding stuff on A* here. i don't really want to learn A*. instead, i just thought up a simpler way to do it. lets first imagine a vector from blinky going towards pacman. we know which directions along the x and y the vector will travel. these will be the set of directions we'll choose from to start. if either of the two directions is where we came from, we pick the other one. if the remaining route isn't available, we have to pick another route at random. if both routes are available, we pick randomly from them. that should work pretty well.
the blue ghost, inky, is a combination of clyde and blinky. if the distance to pacman is short, he'll act like blinky; otherwise he'll just move about randomly like blinky.
the pink ghost, pinky, is the oddball to me. he's supposed to act like blinky, but he's supposed to make 'opposite' turns.. well, that would make him move away from pacman with the algo presented above. [thinking] how about every other intersection, he'll act like blinky. every intersection in between he'll do things in the opposite direction. that might do the job. [thinking] perhaps another method could involve blinky's location relative to pac. if both directions are available to move in (as in blinky's method) and blinky falls along one, then the other is picked? that seems like it would be more likely to do pincer attacks that way. also, no reverse directioning crap. i like that better.
it looks like i need to explain blinky a bit more. i need to explain how we choose the direction he'll take. we need to first assume that an intersection has to have 3 or 4 exits. one of those exits will not be considered, as it is where we came from, reducing us to 2 or 3 choices. pacman can be chased directly in 1 or 2 of those directions. if the 1 or 2 direct chase routes are all unavailable, we have to pick from what's left.
this problem needs to be reduced in its complexity somehow. i want to make an ordered collection of possible routes and remove routes that we can't use. the top ranking routes are the one or two that would move us directly towards pacman. in the case where there's two, we randomly choose which of the two is ranked at #1. the other is then #2. all other directions are added in random order after. now we discard the route that we came from, and then the routes which are walled off. now we pick whichever is the most top-ranked.
blinky tries to find the "best" route to pacman:
method: is pacman above or below? yes: randomly add this direction to top-ranking collection, and randomly add the other direction to the non-ranked collection. no: add both directions randomly to the non-ranked collection. do the same for left/right. append non-ranked collection to top-ranking collection. step through entire collection and remove illegal directions. pick the first one remaining.
we might wind up taking a completely random direction to get to him, but it'll do its best at every intersection. pinky is going to have to be a bit more specialized, as his algo relies on blinky as well. we're going to go all the way through blinky's algo, and add a step just before we pick the first one remaining. if any of the directions remaining in the collection is the same as the one blinky's currently travelling in, throw it out if there are any others in the collection. then pick the first one remaining.
in alot of cases, this will cause the pincer effect i want. in some cases it'll make pinky look retarded. i don't really like that solution.
i think i need a third collection, containing the directions to go toward blinky. whichever distance along each axis is longer is the direction we want to use. no, this doesn't look right either. damn you pinky!
... how about if any of the directions remaining before we choose is in the direction pinky would head in to get to blinky, we throw them out unless there are no other directions to choose from. nope..
lets look at blinky again. we're choosing to randomly order the top-ranking choices, but what if we did it ordered? then pinky could just order in reverse and we'd have a solution. thats all we really want. ok, so how will we order? whichever axis has the shorter distance to pacman is ranked higher for blinky, and lower for pinky? whichever way we choose it shouldn't really make a difference i don't think. so that works out. lets redo blinky.
blinky tries to find the "best" route to pacman:
method: is pacman above or below? yes: add this direction to top-ranking collection ordering by distance to pacman along this axis, and randomly add the other direction to the non-ranked collection. no: add both directions randomly to the non-ranked collection. do the same for left/right. append non-ranked collection to top-ranking collection. step through entire collection and remove illegal directions. pick the first one remaining.
pinky tries to find the "best" route to pacman:
method: is pacman above or below? yes: add this direction to top-ranking collection INVERSELY ordering by distance to pacman along this axis, and randomly add the other direction to the non-ranked collection. no: add both directions randomly to the non-ranked collection. do the same for left/right. append non-ranked collection to top-ranking collection. step through entire collection and remove illegal directions. pick the first one remaining.
eesh. that was a pain.
4:43am [[ extra rules ]]
apparently blinky is supposed to speed up when there's a certain number of pellets left. torn right from the site i'm using, here is a table showing when blinky speeds up:
Level Pellets left
the other ghosts don't change speed at all (except for when they're in scare mode).
something else i wasn't aware of, but is part of the rules, is that every once in a while, the ghosts will enter 'scatter' mode and will beeline for their corner before going back to their normal chase ai. again taken from the site:
"The ghost will enter scatter mode four times for each life on each level. As they exit the ghost house, you can easily see they begin play in scatter mode. Blinky heads for the top right corner, Pinky for the top left, Inky for the bottom right, and Clyde for the bottom left. When the ghosts enter scatter mode is determined by a timer. Generally the first two scatters are the longest in duration, and the third and fourth are about 2/3 as long. Beware Blinky: he can still pursue Pac-Man in scatter mode."
it might be a good idea to generalize the blinky direct-route method for use for scattering and returning to the ghost house.
there's still alot to go over, like the pacman/ghost interaction, the bonus fruit, the tunnel, and ghost house stuff.
i had forgotten to mention yesterday that when the ghost is in its scare state, it moves at a slower speed - 1/2 or 2/3 or something.
well, lets go over the pacman-ghost collision situations. when a ghost collides with pacman during hunt mode, pacman dies. whe a ghost collides with pacman during scare mode, the ghost changes to eye mode and immediately sets a direct path to the ghost house. the ghost regains its speed for the return trip - i beleive eye mode is even faster than normal speed. for every successful ghost-eat, you gain 200, 400, 800 and finally 1600 points. when you eat a power pill, the ghost-score multiplier is reset back to 1.
when pacman dies, the ghosts are reset to their positions at the start of the level, as is pacman. if it hasn't yet been eaten, the fruit is removed from the board and its timer begins again.
the tunnel is pretty simple. if you go completely off the screen, you're wrapped around to the other side, off-screen, and continue back onto the map. the ghosts won't likely be using it; on a rare occasion the two dumb ghosts will.
it looks like we only have the bonus fruit and ghost house stuff left. i need to find out how much the pellets and power pill are worth, as well as how many points you need to get a new life. i'm not sure if there's anything else to worry about after that. we should probably go over the scatter mode in more detail as well.
7:37pm [[ bonus fruits ]]
gotta remember to talk about game/level startup and gameover.
lets get the bonus fruit done and out of the way. from a new level start or new life restart, a timer begins. after the timer runs out, the bonus fruit appears just under the ghost house. the timer begins and runs for the same length, after which the fruit will disappear. this loops forever. however, if pacman eats the fruit, it will not appear again until the next level begins. torn right from http://www.everything2.com/index.pl?node_id=499157, here is a table of the fruits that appear each level, and their point value:
Level Prize Point Value
1 Cherry 100
2 Strawberry 300
3-4 Orange 500
5-6 Apple 700
7-8 Grenade 1000
9-10 Spaceship 2000
11-12 Bell 3000
13+ Key 5000
pacman eats the bonus fruit.
test: bonus fruit collision rect touches pacman ghost-collision rect, and bonus fruit in show state.
result: fruit not available until next level. score increased by point value of fruit. sound played.