Slashdot Mirror


Pac-Man's Ghost Behavior Algorithms

An anonymous reader writes "This article has a very interesting description of the algorithms behind the ghosts in Pac-Man. I had no idea about most of this information, but that's probably because it's difficult to study the ghosts when I die every 30 seconds. Quoting: 'The ghosts are always in one of three possible modes: Chase, Scatter, or Frightened. The "normal" mode with the ghosts pursuing Pac-Man is Chase, and this is the one that they spend most of their time in. While in Chase mode, all of the ghosts use Pac-Man's position as a factor in selecting their target tile, though it is more significant to some ghosts than others. In Scatter mode, each ghost has a fixed target tile, each of which is located just outside a different corner of the maze. This causes the four ghosts to disperse to the corners whenever they are in this mode. Frightened mode is unique because the ghosts do not have a specific target tile while in this mode. Instead, they pseudorandomly decide which turns to make at every intersection.'"

20 of 194 comments (clear)

  1. Programming lesson by MrEricSir · · Score: 4, Insightful

    Take note CS professors: writing a Pac Man ghost algorithm would be an awesome exercise.

    --
    There's no -1 for "I don't get it."
    1. Re:Programming lesson by Rickz0rz · · Score: 5, Interesting

      Or half of the class writes ghost algorithms while the other half writes an algorithm controlling pac-man himself, and then the algorithms are pitted against each other!

    2. Re:Programming lesson by Monkeedude1212 · · Score: 3, Funny

      Then you'll get one kid who goes "Aww man. I totally thought this was Ms Pacman! I built it with no sense of direction whatsoever!"

    3. Re:Programming lesson by camperdave · · Score: 3, Informative

      A.K. Dewdney came up with a similar idea back in 1984. It's called corewars.

      --
      When our name is on the back of your car, we're behind you all the way!
    4. Re:Programming lesson by CharlyFoxtrot · · Score: 3, Funny

      Don't be sexist. Chicks hate that.

      --
      If all else fails, immortality can always be assured by spectacular error.
    5. Re:Programming lesson by seeker_1us · · Score: 4, Funny

      Ms. Pacman might not have a sense of direction. Mr. Pacman also has no sense of direction but he won't pull over to ask for help.

    6. Re:Programming lesson by Monkeedude1212 · · Score: 3, Interesting

      It's been scientifically proven that statistically men have better 3D perceptualization than women - yes some women are better at it than men, but when you plot it all out you get the regular bell curves, and men typically have higher preforming scores.

      So it's not like jokes revolving around a woman's ability to park a car, or judging how far away an object is, or any of the things that seem to be related to navigation - they do have SOME foundation to it. (if you don't believe me, Google "Women's Depth Perception")

      Much in the same way that colourblindness is strictly a male thing - if a woman is colourblind, it typically means that some dominant male gene actually took control when their eyes developed, which is quite rare in women. But also in Women its rare that they sometimes get a 4th "cone" in their eye that helps identifying in colours. This is why women tend to be better at items like interior design and Fashion, so the jokes about how "Men can't dress themselves" also have a good foundation. Like before, "some men are better than women at that sort of stuff" - but statistically speaking, this is a good strong point for women.

      So - now that the science is out of the way - what does this have to do with Offensive jokes? That's the thing, they are just jokes. I mean in it in a light tone and while some might take it as derogatory, there are any number of things someone could make fun of me for (as you might have pointed out, my apparent lack of tact and manners!).

      It boils down to this: do I value a good joke over someone elses potential feelings? Personally, I do enjoy a good joke. I think that the enjoyment it brings to me and others outweighs the possible negative feelings that a small contingent might actually feel - after all not ALL women are offended by such jokes.

      A wise man once said... well I can't remember the exact words, but it was something along the lines of "Wisdom starts with humility". If you can't laugh at yourself than thats something you should work on. Recognising your shortfalls is the first step to overcoming them.

      Now - the biggest problem I have with people is when they can't seperate Discrimination, prejudice, or harassment from humour. Like when you're at an Open source conference, and you're a women, like the article you linked. Guys taking upskirt photos of women? Yeah sexual harassment. Ignoring females because they are believed to be non-technical? Yeah discrimination. A picture of a girl in a Bikini during a slide show to say "That was just to get your attention" - Thats humour! It's meant in light fun, I bet if you had enough girls around you'd find them chuckling at the idea as well.

      Point is - people need to lighten up. If more people could understand the difference between humour and harassment - the world would be a much better, and funnier place.

    7. Re:Programming lesson by vux984 · · Score: 4, Interesting

      Take note CS professors: writing a Pac Man ghost algorithm would be an awesome exercise.

      I wrote a PacMan in GWBasic when I was around 13 or so.

      The Ghost algorithm was one of the more interesting problems. The chase rules were simple... at each intersection the ghost chose to move towards pac-man, with the one caveat that it wasn't allowed to simply reverse direction. There was also a smallish random chance that the ghost would go a different direction if available.

      This made them mostly but not entirely predictable, and also helped break them up when multiple ghosts ended up in the same place behind pac-man. And was the only way they used the left-right 'teleporter'

      It worked well enough and by fine tuning the random chance of going in a random direction I was able to get a pretty satisfactory game.

      The algorithm was actually based more on my observations of lode-runner than of PacMan. (I desperately wanted to be able to write a lode-runner type game, but I was self-taught... and didnt' under stand data modelling. My pacman sprites navigated the maze by acutually looking a the pixel colors around them... white was a wall.

      My next project was tetris a couple years later, in pascal, with the same sort of inspect the pixels to see if a row was complete, and to stop falling, see if rotations were allowed, etc.

      I remember having the data model epipaphany when I was trying to write a variable width font word processing thing (again in basic), and I couldn't for the life of me figure out how to support 'backspace'; looking backwards at the screen and comparing the pixels with the bitmaps for the different letters was simply a mess...hmmm... instead of simply drawing the letters as I type and moving the cursor forwards what if I put the letters I typed into a string as well... ooooooooooh.

      A real personal Eureka moment there.

    8. Re:Programming lesson by masterzora · · Score: 3, Interesting

      It's been scientifically proven that statistically men have better 3D perceptualization than women - yes some women are better at it than men, but when you plot it all out you get the regular bell curves, and men typically have higher preforming scores.

      Really now? Can you link me to a few unbiased studies the topic with statistically significant sample sizes and shows results of men having, not only higher scores, but statistically significantly higher scores? I assume, of course, that you also have available the justification for why we can trust the tests to be testing purely for 3d perceptualisation, without testing for additional unrelated factors (such as how well you can decipher difficult instructions, a common additional factor in such tests). And I also trust that these studies have properly isolated for sex, ensuring that additional factors such as training and practice in related skills or a lifetime of "you can do anything" vs. "oh, you're just a girl" have no bearing on the final results?

      I'll be rather impressed if you can show me any such study. Now, I'll be the first to admit that not all people are created equal and that it is quite possible that people of different sexes and genders and races and sexual orientations have some amount of differences. However, I think you'll find that most of these studies in these topics are entirely inconclusive after you consider all of the factors surrounding them.

      It's also worth noting the striking parallels to the number of 19th century studies "proving" that black people were strictly inferior to white people. Confirmation bias can prove anything, as it turns out.

      --
      Remember, open source is free as in speech, not free as in bear.
    9. Re:Programming lesson by fishexe · · Score: 3, Informative

      It's awful that some people have gone so far off the deep end that simple jokes cannot be told without questioning their intentions.

      I don't think anyone was questioning the intentions. They were questioning the effects that such jokes have on the culture, particularly when they are so one-sidedly against women all the time. It's great that you're an equal-opportunity offender and I salute that, but the FOSS community as a whole is not. Even if the individual jokes themselves are all meant in good fun, taken together they create a boys'-club atmosphere that is not healthy to the growth of the community.

      On the other hand, folks are overly sensitive about some things. No one granted anyone the 'unalienable right' to not be offended. Some shit offends me too, but I get over it.

      I would re-read the link notionalTenacity posted. It isn't about safeguarding the right not to be offended, because of course no such right exists. It's about creating an environment that encourages all to participate, which is not something we have a "right" to but would be a very smart thing for the FOSS community to foster.

      Have you tried getting over it and trying to have a sense of humor? Not about things like the dude sticking his hand down the chick's pants....that's messed up and he should at least have the hell beaten out of him a few good times for it. About things like "hur hur, women ain't got no direction smarts!"

      You don't think the two are related? Really, would a man really try to stick his hand down a woman's pants at a conference where people didn't make repeated jokes about the entire female sex and there weren't pictures of women in bikinis in the presentations? One sexist joke is harmless, if it's the only one, but that kind of pervasive behavior creates an environment where men literally think, "these women are here to pleasure me, not to participate in tech talk", and that mindset leads directly to the odd one attempting the ol' scoop-n-grab.

      --
      "I don't care about the Constitution!" --Bill O'Reilly, November 17, 2009
  2. Re:Always fascinating. by DIplomatic · · Score: 5, Insightful

    A 30-year-old game featured AI more sophisticated than what you'll find in most games today.

    I'm not sure "deciding whether to turn right or left at the fork in a 2D maze" can really compare to the ridiculously complex AI behavior in many games today. Team combat, terrain navigation, etc. Advance-to-cover squad-based tactical combat is hardly If PAC_MAN_INVINCIBLE == FALSE; Chase().

  3. Re:Always fascinating. by Monkeedude1212 · · Score: 4, Insightful

    A 30-year-old game featured AI more sophisticated than what you'll find in most games today.

    In defense of games today, things where a whole lot easier when you were on a strictly 2D, non-altering, fully 100% visible plane, and where an AI that knows your exact position regardless of things like noise and line of sight wasn't considered unfair, and where the only abilities an AI had to worry about were "Move My XY coordinates to = Player XY Coordinates" -

    Well I think you're getting the picture...

  4. It appears their web server by RapidDemon · · Score: 5, Funny

    is currently in frightened mode

  5. Re:Always fascinating. by Anonymous Coward · · Score: 4, Informative

    I read somewhere If pac-man leaves tile A entering tile B on the same clock pulse as a ghost leaving tile B enters tile A, the machine will switch their positions on that pulse; they never occupy the same tile.

  6. Breaking news!!!! by mrsam · · Score: 5, Informative

    Yawn... This stuff that already been posted on the Pacman Dossier for years. Not really "news for nerds".

    Now, what would really be "news for nerds" is the analysis of the ghosts' behavior in Google Pacman, which is very similar, but subtly different.

    Of course, since Google Pacman's source is available, this can theoretically be deduced straight from the source, but it's more fun to figure it out by trial and error. Great timekiller. There are definitely notable differences -- like certain directions the ghosts will never turn to if they enter the intersection from one direction, but will if they enter the same intersection from the opposite direction.

  7. Re:Always fascinating. by nedlohs · · Score: 4, Insightful

    More sophisticated?

    They are constrainted by the paths and when they have to make a choice they pick the one that gives the shortest straight line distance to their destination.

    In other words they are retarded, which is good because there are four of them and they'd box the player in in about 10 seconds if they weren't.

  8. Interesting but from my memory by al0ha · · Score: 4, Interesting

    based on being really good at the original pacman, achieving a high score was simply a matter of learning patterns, so they must not really be referring to the original pacman here because I think that algorithm must have been pretty simple. To be a great player on the original pacmac you run pacman through the same pattern every time in every level you've learned, hitting the energizer pellets precisely when you know you can always run the same pattern and eat the four ghosts as the flee. Always the exact same pattern for each level until you finally reach a level where you have to learn the pattern. It was really crazy playing because you could do all the levels you'd memorized pretty much with your eyes closed, so when you got really good; it took a frigging long time to get to a level you did not know.

    --
    Did you ever wake up in the morning, with a Zombie Woof behind your eyes? -- FZ
    1. Re:Interesting but from my memory by VortexCortex · · Score: 5, Informative

      Following exact patterns work because that generates the same exact pseudo-random number pool that the ghosts use to pick directions.

  9. Re:Always fascinating. by fishbowl · · Score: 4, Insightful

    >Well, the behavior is complex in today's games, but the algorithms are not.

    Study up on the path-finding, grouping, and line-of-sight algorithms in "today's games", before you lodge this kind of insult at their developers please.

    --
    -fb Everything not expressly forbidden is now mandatory.
  10. Re:Always fascinating. by MMORG · · Score: 5, Insightful

    In other words they are retarded, which is good because there are four of them and they'd box the player in in about 10 seconds if they weren't.

    Yes. There's this persistent myth that smart game AI is hard to build. It's not. A really smart, impossible-to-beat game AI is easy to build (for most types of games). What's hard to build is a sort-of-smart-but-often-fallible AI that's just competent enough that it makes you feel like you're accomplishing something worthwhile when you finally beat it. For extra bonus hardness points you can try building an AI that makes the same kind of sub-optimal choices that a human would make so that it feels "alive". That's hard to do.

    Game AIs have all kinds of advantages that make it easy (again, for most types of games) to build them to be unbeatable. They have always have instant reaction time, they can consider a large number of disparate data streams simultaneously, they always have perfect knowledge of their environment, they can have vast libraries of pre-computed decision trees, and their accuracy in moving, aiming, etc is limited only by the precision of floating-point data types. (An aside: the reason why real-world robotics is so hard is largely because real-world robots have really terrible knowledge of their environment, unlike game AIs.) The trick to writing a top-quality game AI is to figure out how to degrade and handicap all of those advantages in ways that leave them beatable while not leaving them looking stupid.