Post subject: Pac-Man Challenge
Player (121)
Joined: 2/11/2007
Posts: 1522
I'm not suggesting that a full on movie of Pac-Man would be interesting, but recently I've been fascinated with finding the fastest route for the first level. Here's my first stab; I'm positive it can be beaten: http://dehacked.2y.net/microstorage.php/info/5237/alden-PacMan1stlevelfast.fcm I used the tengen nes version, and my criteria for "finishing" the level (and stopping the movie) was when memory address 6A is 0 (that's the number of "dots" that are still on the board). I'd be interested to see what anyone else can come up with. Feel free to show me movies from different versions/systems! Edit: I already beat my first upload by 15 frames, updated microstorage link.
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Skilled player (1826)
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Here's my (unoptimized) attempt. I actually made it months ago, just for fun. It's 133 frames faster: http://dehacked.2y.net/microstorage.php/info/5242/pac-man-randil-level1.fcm In order to find the fastest route, one would probably need to go through a lot of mathematical analyses. This is clearly an optimization problem, and even though it's quite hard for a human to find the fastest way, perhaps one of you programmers out there could write a program that finds the fastest way in Pac-man? ;) Anyway, I'll see if I'm motivated to do some more testing on this. It's not the most fascinating game out there, but hey, it's Pac-man. :)
Player (89)
Joined: 11/14/2005
Posts: 1058
Location: United States
This is an incredibly intriguing idea. Though I suspect a huge problem would be the goal of the run. Shortest movie avi or shortest input length. One way to significantly shorten the input length would be to set pac-man up on one of the long vertical paths when the only remaining pellets are on that path, then simply terminate the input. Pac would continue to eat all the pellets on that path even though no more input is being given.
They're off to find the hero of the day...
Tub
Joined: 6/25/2005
Posts: 1377
It's similar to a known and solvable problem from graph theory, and if you wish I'll try to write a small program that determines the optimal path. Such a program wouldn't be able to consider ghost movement of course. How difficult is it to manipulate their movement? A perfect path is worthless if there are ghosts in your way.. (although most levels will have multiple optimal paths to choose) The biggest problem is probably getting the level data. Unless someone knows how the levels are encoded in the rom that will require some manual processing. If someone can dig up ascii-art-maps from a guide that'd be perfect. If everything else fails I might be able to extract the map data from screenshots, but that's error-prone and a pita to program well. Are there 255 different levels or are they looping faster?
m00
Chamale
He/Him
Player (182)
Joined: 10/20/2006
Posts: 1353
Location: Canada
I've heard the ghosts always move in the same pattern, but maybe that's only in the arcade version.
Player (121)
Joined: 2/11/2007
Posts: 1522
Randil, thanks for the better movie! I've been hacking away but still can't beat you ;) Hero, Randil's movie lends itself to the "Shortest input" test as with a minor adjustment he leaves a very long chain of uneaten dots... But I'm personally more interested in terms of "avi" time. I think the fcm should be ended once the memory value for the number of dots left is 0 (that's 6A) since this seems to be the easiest quantifiable way to tell when the level is over. Tub, yes this reminded me of graph theory as well, but I'm not hardcore enough to tackle this programming wise. I'd be delighted if you'd try. I'd be happy to help "map" the level too... And yeah, in this version it's the same map over and over again, the ghosts just get faster (and you get different bonus fruits ;) Ghosts do seem to move in this version depending on how pacman moves so they should be somewhat manipulable. I'll do some more testing tonight. Thanks everyone!
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Player (121)
Joined: 2/11/2007
Posts: 1522
Here's a proof of concept for a "fastest input" style movie: http://dehacked.2y.net/microstorage.php/info/5253/PACMANrandileditforfewestinput.fcm I slightly modified Randil's movie, and if you watch you will see that it stops input far before the level is beaten. The last input is 99 frames faster... but by the # of dots left == 0 test, it is 94 frames slower. I have started trying to map the locations of and time-in-transit between dots, but it's not as straightforward as I thought though. Will keep you all posted.
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Skilled player (1826)
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
I spent some time finding out the length of each path. I even drew a map in Paint. :) Here it is: http://i19.tinypic.com/2m2huza.jpg Using this, it should be possible to write a program that finds out the optimal path. The black lines are the corridors and the numbers are the distance in pixels.
Player (121)
Joined: 2/11/2007
Posts: 1522
Cool map Randil! Now if I remember graph problems correctly, you need to define Vertices and Edges (or as I like to call them Nodes and Paths). Each Vertice is connected to 0 or more other Vertices with an Edge. You can assign each edge a value (distance). The trick then is to find the sequence of visiting a set of vertices or traversing a set of edges such that the sum of the values of each edge is minimized. So in this case, using this map, you would assign each intersection to a Vertice, and then each path between intersections as an Edge joining the Vertices. The Edge would be given the pixel distance as it's value. You'd also have to define which Edges need to be traversed -- some of the paths in the map do not have dots to be eaten so do not need to be traversed to clear the level. This does not precisely model the game though. Pretty close, but I think it could be refined more, and if we want "frame perfection" I think it should be more detailed. One thing that would not be modeled correctly is when when you do a 180 turn like in Randil's movie. You do not have to go all the way to the intersection before turning around, so the distance would be slightly less than what this model would say. Also, I think "distance" value in the edges should be measured in terms of frames rather than pixels. From what I've observed, the number of frames between eating dots actually varies, usually 11 or 12 frames (can be as low as 6 though!). I have not tested it extensively though and can't say if the number of frames between dots is constant going left/right, or doing it at a different time. If it is constant each dot would be a Vertice and the edges would have the distance in frames. Still not perfect, and doesn't really solve the 180 turn around problem either, since the dots are not at one position on the board: pacman's position when the dot is "eaten" is not the same when coming from the right and left, so in the model it would have account for where it is coming from. Let me try to clarify with a diagram:
1  2  3
o--o--o
So in moving from 1 to 2 to 3, the time from eating 2 to 3 would be longer than if you move from 3 to 2 back to 3, because the "eating" gets registered from the left side of the dot rather than the right side. Do you think this is relevant, or am I missing something that makes this simpler than I think? Am glad other people are interested in this problem!
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
JXQ
Experienced player (761)
Joined: 5/6/2005
Posts: 3132
This would be one hell of a graph theory problem. I just noticed that if you come to a solution, try it, and a ghost messes you up, you could always try its reflection along the vertical axis in the middle.
<Swordless> Go hug a tree, you vegetarian (I bet you really are one)
Player (121)
Joined: 2/11/2007
Posts: 1522
I'll retract most of what I wrote on my last post. The time it takes in frames to move between any two given dots is very variable. It usually is different if you go from A to B and then B to A. It is also different if you start on a different frame of the movie. So for simplicity's sake Randil's map should make a good basis for a program. I'd maybe consider trying to account for the 180 turn situation I describe above, but overall maybe that won't matter too much?
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Skilled player (1826)
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Here's a summary I've made of (considerably small) factors to take into account: (alden already mentioned some of them) *Does it waste any time making a 90 degree turn? If Pac-man stops for, say, 1 frame when doing this, it may have to be considered. *As alden pointed out, it's possible to enter a corridor, eat only a few of the dots, then make a 180 degree turn and exit. See my .fcm for reference. In fact, it would probably be better to have all the dots as nodes in the graph, and solve the problem after that. *Pacman's speed varies. Alden tangented on this when you said that the time it took between eating dots varied. From what I've observed, Pac-Man stops for 1 frame now and then. I don't know exactly how it works, but it's something like walk for 7 frames, stop for 1 frame, and repeat. *Alden said that eating gets registered from the left, so if the ghost's don't interfere much, it would be better to eat the map's last dot from the right, saving a few frames. :) Some of these are probably too small to even take into account. I think the best way would be to first find the solution to the graph I posted before, and then perhaps include some of these things. Any thoughts?
Player (89)
Joined: 11/14/2005
Posts: 1058
Location: United States
I have managed to complete the first level about 30 frames faster than Randil. There is probably even more room for improvement left. http://dehacked.2y.net/microstorage.php/info/5285/pac-man-hotd-level1.fcm Here is a map I whipped up real quick: http://server6.theimagehosting.com/image.php?img=Untitled-8.39b.gif Red = path with pellets on it Green = power ball Orange = path without pellets on it
They're off to find the hero of the day...
Tub
Joined: 6/25/2005
Posts: 1377
From what I've observed, Pac-Man stops for 1 frame now and then.
is that standard lag, or are the ghosts moving while pac man stops? If it is just lag, it may be possible to just ignore it. as alden correctly pointed out, this is not quite the standard graph problem but an evil (yet possible) incarnation of it. The important parts are the 3-way-junctions because that's usually where decisions take place. If I didn't fail to count there's 20 of them. That's not few, but not too many either and it might be possible to just brute force the thing. I don't have a running FCEU, but I'll start digging code sometime next week.
m00
Player (121)
Joined: 2/11/2007
Posts: 1522
Nice movie Hero! I liked the close calls with the ghosts. I didn't mean to imply that eating a dot is faster from one particular side, though that may be true. What I was trying to say is that the dots take up more than one "position" memory wise, and that from the left pacman would eat it once he gets to say, 65, whereas from the right he would eat it at 68 (not actual numbers, I don't have a real example off the top of my head.) Better diagram: 000---------000---------000 each 000 is a dot. If he eats all three he goes the whole way. If he starts on the left, then eats the middle, then turns around and heads back to where the first one was, he doesn't have to go all the way through the middle dot before turning around so it is slightly faster. (of course this is backtracking so should be avoided as much as possible) On another note, I did more testing on speed. I measured the number of frames it took to eat a bunch of dots and divided, rendering an average of 9.75 frames per dot. (turning corners actually seems faster??) There are 192 dots. If you imagine a "perfect" board where there are no ghosts and it's just one long corridor so you don't need to backtrack, it would take about 1872 frames to eat them all. Add in the approximately 264 frames before he can start moving and that's 2136... only 3 seconds faster than Hero's 2340. So we're darn close already.
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Mitjitsu
He/Him
Banned User
Joined: 4/24/2006
Posts: 2997
IIRC from messing around on the arcade emus it seems the ghosts move about randomly until there actually in PAC MANS line of view view. I wouldn't object to see a fixed number of levels that are in a multiple of x^2 say 16,32.
Player (89)
Joined: 11/14/2005
Posts: 1058
Location: United States
hey alden, do you know if it is required to collect the big power balls in order to complete the level?
They're off to find the hero of the day...
Player (121)
Joined: 2/11/2007
Posts: 1522
Yeah, you do need to get them. Bummer huh. And even though they are bigger pixel wise they are the same memory wise so it doesn't save time to save one til last ;)
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Active player (406)
Joined: 3/22/2006
Posts: 708
Great :/ The version I have must be the wrong one. It's definitely the Tengen Pacman, but it desyncs with the movies you have here. Is there more than one Tengen rom? Mine is "U Tengen [!]"
Player (121)
Joined: 2/11/2007
Posts: 1522
Mine's just called PACMAN.NES Don't know if there are different versions. I forgot about this thread! I guess we'll crown Hero of the Day as king of Pac-Man for now (as well as Donkey Kong, Metroid, etc.)
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Player (89)
Joined: 11/14/2005
Posts: 1058
Location: United States
haha, thanks alden :) Though I am confident my run could be beaten by a few frames. I would love to see a program that could map the fastest route.
They're off to find the hero of the day...
Skilled player (1826)
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
After having a lesson in school about network optimization, I got some motivation to try to beat Hero's attempt, and managed to do so by 92 frames. Here's the movie if anyone's interested. :)
Player (121)
Joined: 2/11/2007
Posts: 1522
Randil, this is why you're my hero :) That was an interesting strategy, I'd love to hear more about how you came up with it, especially if it was really a result of network optimization ...
hero of the day wrote:
I am confident my run could be beaten by a few frames
A second and a half!!! Sincerely, Gushing Fanboy
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Skilled player (1826)
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Actually, the improvement didn't have anything to do with network optimization! :) Network optimization only motivated me to try to improve the current record. The trick is quite trivial once you understand how it works. It abuses the hitboxes' of the dots: Each dot is inside a 16*16 pixels square. You only have to move 4-5 pixels into this square in order to pick it up. By turning in and out of corridors, I only have to move 8 pixels to pick up a dot - if I pick it up when I move through the corridor later on, I'd have to move through the previous dot's hitbox first, that's 16 pixels, which is a bit longer. Perhaps a bit confusing, but once I get home I could wip up some frame numers to clear things up a bit.
Player (121)
Joined: 2/11/2007
Posts: 1522
That makes sense and kind of what it looked like you were doing when I was watching -- though I didn't realize why. That sort of does have a bit to do with network optimization insofar as it is traversing a set of vertices and edges in an efficient manner, because in this "network", where A B and C are any three consecutive dots (vertices), A->B->C is longer than A->B->A. (If I interpreted your post correctly ;)
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs