Post subject: Computational complexity of classic video games
Blue_Streak
He/Him
Joined: 5/5/2007
Posts: 12
Location: Mesa, Arizona, USA
A fascinating new paper describes the difficulty of Mario, Donkey Kong, Zelda, Metroid, and Pokémon games from the perspective of their computational complexity: http://arxiv.org/abs/1203.1895. The primary conclusion of the paper is that the intended set of gameplay mechanics in these games places them in the class NP-hard. Without getting into the details of what this means, it is a technical way of saying that, based on very general principles, there is probably no algorithm that can efficiently find the optimal solution to these games (where "probably" refers to the prevailing opinion of computer scientists on important open questions that impact this result, such as P versus NP). This has important implications for the future of TASes, where ultimately some algorithm must exist that solves these games optimally. In the introduction, the authors even mention tool-assisted speedruns as the motivation for this study. There are of course various caveats impacting this result in favor of easier solutions, one being that a proof of P = NP would make the efficient solution of these games far more likely. Another is the fact not all NP-hard problems are unrealistic to solve, it's just that the solution time becomes more and more sensitive to the size of the problem. Thus, while the existence of block puzzles in Zelda forces a certain level of complexity upon the algorithms required to solve the game optimally, some block puzzles are far easier to solve than others in terms of the number of possible moves and configurations. It may be that those actually implemented in the games are simple enough that they can still be solved exactly without taking a million years of computer-time. A third caveat is that there are still open questions about quantum computers. While the computational power of quantum mechanics as currently formulated is known, it may be that a complete theory of quantum gravity requires a modification to quantum mechanics that increases its computational power. Such a possibility also would make the efficient solution of these games more plausible, although it would also require us to have quantum computers in the first place. A final caveat is that this result doesn't account for the multitude of broken game mechanics that are known to exist (glitches, sequence breaks, etc.). So the problem of determining perfect play within the intended mechanics is almost certainly harder than one that allows various puzzles to be skipped, although finding the set of all possible glitches is another challenge in itself. Given the exponential growth of computing power, along with various open theoretical questions, and the fact that games can be broken in many ways not intended, there are reasons to believe that there is a path towards the ultimate optimization. It would be a fascinating exercise to analyze even small sections of the existing level design to see if one can prove that a certain combination of moves (and even button presses) is optimal.
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
The idea basically is that there is no single algorithm much better than brute force to beat these games as a whole. Of course portions of a game could likely have algorithms better than brute force to optimize for some specific goal.
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
Post subject: Re: Computational complexity of classic video games
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
Blue Streak wrote:
Given the exponential growth of computing power
I'm not so sure that computing power is growing so "exponentially", but even if it did, it wouldn't really be of so much help to us. Here's some math: To brute-force a game like SMB, you have to test all possible combinations of buttons on all frames. Since a SMB completion is roughly 5 minutes long, that would be about 18000 frames. If we consider only the 6 main buttons of the controller, that would mean that all combinations of 6 buttons would have to be tested on each frame. Each button represents one bit of information. Each time you add one bit to test, the amount of combinations to test doubles. The total amount of bits to test on a 5-minute run is about 108000, and hence the total amount of combinations to test is about 2108000. We don't need to calculate that number in this hypothetical situation because, as hypothesized, computing power grows "exponentially". Let's assume that computing power doubles each year (which is a ridiculously optimistic estimation, but let's assume that for simplicity). That means that we would have to wait almost 108000 years before brute-forcing the 5-minute run becomes feasible. (Not exactly that much, because it becomes feasible a few dozens of years earlier. Some pruning algorithms may shave off a few years more. It makes no difference to us, though.)
Patashu
He/Him
Joined: 10/2/2005
Posts: 4045
Just because a problem is NP (or harder) doesn't mean that the problem is intractible to solve, or even to get close to a good answer. Sudoku is NP-complete - but your computer can solve sudokus in the blink of an eye, because they are so small. On the other hand, TASing almost any game is an incredibly hard complexity class - yet TASes are frequently made, because the TASer merely has to do as well as previous work on the game, not perfectly. The constructions featured in the paper are pretty amusing :)
My Chiptune music, made in Famitracker: http://soundcloud.com/patashu My twitch. I stream mostly shmups & rhythm games http://twitch.tv/patashu My youtube, again shmups and rhythm games and misc stuff: http://youtube.com/user/patashu
Joined: 10/20/2006
Posts: 1248
I still believe that an intelligently learning bot which watches the RAM, forms hypotheses about how the different addresses interact and looks for ways on how it can influence them and verifies them by experiment/ trial and error, would ultimately be able to find pretty good solutions once it has learned enough about the game. It would be insanely hard to code and would still need to run for a very long time. It'd like to avoid situations where an earlier RAM structure of relevant addresses would have to repeat and it can't stop that from happening anymore, which is basically a death or game over.
Joined: 10/24/2005
Posts: 1080
Location: San Jose
I think most of us have understood the fact that brute forcing is not feasible within our lifetime... But I wondering about smart pruning. Let's stop thinking about input. Let's switch our usage paradigm - look at the ROM disassembly itself. I wonder if there's a way to intelligently analyze the ROM contents (both the state transitioning of the ROM as well as the memory contents) to pre-determine if a certain sequence will lead to an bad-route (without actually running the emulator)? Would it be possible to generate all sets of the "state of the game" with a indicator of if the route will be good, undetermined, or bad? Of course this should be on a game-by-game basis. I know this sounds impossible in our lifespan as well, but I can't wrap my head on if this would be more computationally complex than simple brute force?
<agill> banana banana banana terracotta pie! <Shinryuu> ho-la terracotta barba-ra anal-o~
Patashu
He/Him
Joined: 10/2/2005
Posts: 4045
DK64_MASTER wrote:
I think most of us have understood the fact that brute forcing is not feasible within our lifetime... But I wondering about smart pruning. Let's stop thinking about input. Let's switch our usage paradigm - look at the ROM disassembly itself. I wonder if there's a way to intelligently analyze the ROM contents (both the state transitioning of the ROM as well as the memory contents) to pre-determine if a certain sequence will lead to an bad-route (without actually running the emulator)? Would it be possible to generate all sets of the "state of the game" with a indicator of if the route will be good, undetermined, or bad? Of course this should be on a game-by-game basis. I know this sounds impossible in our lifespan as well, but I can't wrap my head on if this would be more computationally complex than simple brute force?
This algorithm has already been invented! It's called 'the human brain after learning how to TAS' ;)
My Chiptune music, made in Famitracker: http://soundcloud.com/patashu My twitch. I stream mostly shmups & rhythm games http://twitch.tv/patashu My youtube, again shmups and rhythm games and misc stuff: http://youtube.com/user/patashu
Post subject: Re: Computational complexity of classic video games
Blue_Streak
He/Him
Joined: 5/5/2007
Posts: 12
Location: Mesa, Arizona, USA
Warp wrote:
Blue Streak wrote:
Given the exponential growth of computing power
I'm not so sure that computing power is growing so "exponentially", but even if it did, it wouldn't really be of so much help to us.
For what it's worth, calculations per second per $1000 has experienced exponential growth over the past century according to one of Ray Kurzweil's graphs: http://www.singularity.com/charts/page70.html. True brute-forcing is probably going to be infeasible, but we can simplify the problem by considering it as a set of smaller identical problems. Taking, for example, thirty frames, one could compute which combination of button presses starts Mario at rest and moves him the largest number of pixels to the right in that amount of time. In principle one could build a library of such smaller movement optimization problems (a database of position and momentum changes) and chain them together as needed throughout the route, rather than solving the same problem each time Mario is in that situation. Mathematically this would be trading time for space since you'd need to store more data, but that might be an acceptable tradeoff in general since it's cheaper to search a database for the aforementioned sequence than calculate it from scratch each time. Search times often scale logarithmically in size, and polynomically at worst. Certainly none of this would be easy to do, but TASing has been around long enough that the trial and error methods of human players yield highly diminished returns for many classic games (improvements now often consist of a handful of frames). This is could be an opportunity to enter a new, smarter era of TASing by having individuals or small teams program optimization algorithms for games rather than endlessly rerecord frames. It might also yield a plethora of new glitches since it would be an exhaustive exploration of the game mechanics.
Joined: 7/2/2007
Posts: 3960
The problem with compartmentalizing is that many TASes require you to perform suboptimally in the short term in exchange for better optimality in the long term. A bot that only ever sees 30 (or 60, or 1000) frames into the future can't do that. Not to mention that even if you only have four inputs, 30 frames is over 1 quintillion states. If you could process a billion states per second then it would take you 36 years to process one 30-frame section.
Pyrel - an open-source rewrite of the Angband roguelike game in Python.
Patashu
He/Him
Joined: 10/2/2005
Posts: 4045
Also, many goals can not be realized as trivial increments of identical subgoals. In super mario bros if you run right, avoid death and grab the flagpole/axe you'll beat every level...until you get to the first castle that loops you forever if you don't take the correct path. Or 8-4, where you have to take a certain path through the pipes to reach Bowser.
My Chiptune music, made in Famitracker: http://soundcloud.com/patashu My twitch. I stream mostly shmups & rhythm games http://twitch.tv/patashu My youtube, again shmups and rhythm games and misc stuff: http://youtube.com/user/patashu
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
DK64_MASTER wrote:
I wonder if there's a way to intelligently analyze the ROM contents (both the state transitioning of the ROM as well as the memory contents) to pre-determine if a certain sequence will lead to an bad-route (without actually running the emulator)?
Sounds to me eerily similar to the so-called halting problem. If that's so, then no dice.
Patashu
He/Him
Joined: 10/2/2005
Posts: 4045
Warp wrote:
DK64_MASTER wrote:
I wonder if there's a way to intelligently analyze the ROM contents (both the state transitioning of the ROM as well as the memory contents) to pre-determine if a certain sequence will lead to an bad-route (without actually running the emulator)?
Sounds to me eerily similar to the so-called halting problem. If that's so, then no dice.
The halting problem is only unsolvable on turing machines (machines with unlimited storage space).
My Chiptune music, made in Famitracker: http://soundcloud.com/patashu My twitch. I stream mostly shmups & rhythm games http://twitch.tv/patashu My youtube, again shmups and rhythm games and misc stuff: http://youtube.com/user/patashu
Editor, Player (44)
Joined: 7/11/2010
Posts: 1029
But what this paper is saying is that it isn't solvable, with current techniques, in a reasonable amount of time. (It's clearly possible to brute-force the fastest route; just that's far too slow.) In other words, this is a complexity problem, not a solvability problem. Incidentally, I was looking at the contents of the paper itself, and there are a couple factual problems: - Not all Metroid games (e.g. Metroid Prime 3) have situations in which you don't have the Springball, thus the proof breaks down there; - The proof for Pokémon-with-only-trainers falls down in the battle mechanics (not only is it possible to get an endless battle in every single generation, but in Generation I, the accuracy bug makes it hard to set up an unwinnable encounter, given that the player's team will eventually level up to 100). There's also a really simple proof that Ocarina of Time and Majora's Mask are NP-hard; you can encode the Travelling Salesman Problem in the games directly, using an event that kills you or makes the game unwinnable after a certain amount of time (think Fire Temple), a set of Small Keys with carefully calculated paths between them (which could be as simple or as convoluted as required to make them take a set amount of time to traverse), and a series of locked doors before the goal. The paper also seems to miss the result that Sokoban is PSPACE-complete, which allows for a very simple PSPACE-completeness proof for Pokémon Red/Blue (Strength puzzles are Sokoban-like apart from the victory condition, and Red/Blue's Victory Road has pressure plates that boulders can be placed on that let you match the victory condition too). This also made me start thinking about other games. A game with multiple sorts of keys-that-are-usable-once, locks-that-match-a-specific-sort-of-key-and-are-removed-by-it, and one-way corridors, is NP-hard by the same construction if it has at least 5 sorts of keys, and an inventory size of at least 2 (it could be unlimited). This allows for both pretty much all text adventure games, and also games along the lines of Pokémon Ranger.
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
Patashu wrote:
The halting problem is only unsolvable on turing machines (machines with unlimited storage space).
That's like saying that all algorithms are O(1) in practice because they will always be run in limited environments and thus will always end in at most a given amount of steps. Even though algorithms are always run in limited environments, there's a strong correlation between their theoretical difficulty and their practical difficulty. If the halting problem is unsolvable in an unlimited environment, it means that it's practically unsolvable in a limited environment as well, unless that limitation is ridiculously small (such as a few tens of bytes of RAM).
Post subject: Academic Paper: Classic Nintendo Games are (NP-)Hard
Joined: 8/2/2011
Posts: 39
Hi! Long time lurker here! I recently read this paper: http://arxiv.org/abs/1203.1895 and it talks about TAS quite a bit and optimizing! Fun stuff to read, and even gets into a few analyses of how to optimally play games that have been done on this site. ETA: Whoops, sorry, next time i'll search.
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
The paper was published in the beginning of march, we don't need someone every two weeks bringing it up like it's news.
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.