
Classic Nintendo Games Are NP-Hard (2012) - dsr12
https://jeremykun.com/2012/03/22/nintendo-np-hard/
======
0xcde4c3db
> Note that Mario cannot win if he falls from the top ledge (since must always
> remain large, he can’t fit through a one-tile-high entryway).

I'm pretty sure this is inaccurate with respect to the actual mechanics of
Super Mario Bros, although the technique needed might not work with the
particular layout shown. As I recall, it's possible to build a bit of momentum
and crouch into a one-block gap, then turn around and stand to have the
collision push Mario through the gap. A similar technique combined with
another quirk of the engine (it's possible to very briefly land on the seam
between two blocks in a vertical wall) is used for the Minus World glitch.

~~~
sli
You are correct, and it doesn't even require a one block gap. Simply clipping
the corner of a block can allow a player to clip through as well, which is how
you access world -1. That particular glitch can be exploited at either the
very top of the 1-2 pipe, or at the open edge of that same pipe that Mario
would normally enter. Every video one can find about world -1 will exhibit
this glitch.

The article is really only technically correct, as those are glitches and
certainly not intended, but in actual practice, yeah, it's not totally
correct.

------
tinco
Do they show that the games are NP hard, or that it is possible to construct
puzzles using the rules of the games that are NP hard?

~~~
icen
The games themselves are fixed size. They can't be NP-hard, since NP-hardness
is a property of difficulty with respect to input size.

They show that you can generalise them and build levels that are NP-hard: for
example, in the case of Pokemon, they build systems requiring that the player
have a specific team (one that is very unlikely to ever actually be used).

------
ot
Note, this is from 2012. The original paper authors followed up with similar
proof for other games:
[https://arxiv.org/abs/1203.1895](https://arxiv.org/abs/1203.1895) .

------
djsumdog
Here is an actual implementation of trying to implement a general AI to play
all NES games. It's pretty interesting, but his approach does involve the
algorithm having access to the raw NES memory map:

[https://www.youtube.com/watch?v=xOCurBYI_gY](https://www.youtube.com/watch?v=xOCurBYI_gY)

------
ggggtez
As per usual, the comments here have a loose understanding of NP-Hardness.
Anyone discussing limited space to store the levels, simply doesn't understand
what NP-Hard means. A problem can still be NP Hard even if your input size is
small.

~~~
MichaelBurge
If the input size is bounded, then the problem H can't be NP-hard unless P =
NP.

Proof: A decision problem H is NP-hard when for every problem L in NP, there
is a polynomial-time reduction R from L to H.

By assumption, H has finitely many instances, so precalculate a binary lookup
table T. Accessing a lookup table takes time polynomial in L's instance size,
namely O(1).

The algorithm "T . R" is then a polynomial-time algorithm for H, so P = NP.

~~~
ggggtez
Creating the look up table took non-polynomial time. Go back to school.

~~~
MichaelBurge
It's irrelevant how long the lookup table took to create: P = NP if such an
algorithm exists, regardless of how difficult it is for humans to find the
algorithm.

------
cynicaldevil
I don't understand this, AFAIK a problem is NP-Hard or NP-Complete (or P) in
_general_, that is, over all instances. But not so for a specific instance.
Wouldn't these games count as just one specific instance of the problem?

~~~
ggggtez
The papers actually say "The rulesets allow the creation of levels which can
encode an NP Hard problem". That just means if you know the answer, it's fast
to show it, but finding the answer takes a lot of time.

Usually this boils down to creating AND/OR gates using level tiles, and
combining them together to form arbitrary computational problems. Usually
3-SAT, because it's straight forward to encode in logic gates.

------
GlitchMr
I wonder if this actually proves that Super Mario Bros. is actually NP-Hard.

The thing is, breaking bricks with Koopa shells was actually introduced in
Super Mario Bros. 3. Before that, bricks could only be broken with big Mario.

------
yters
Can a deep learning system play these particular NP-Hard games well?

~~~
petters
No, they are far too complex.

~~~
etatoby
Can we define human-level intelligence, which is the stated end goal of AI, as
the ability to find more or less approximate solutions to NP-hard problems, as
well as undecidable problems (we solve the halting problem every day as part
of our job) in polynomial time?

~~~
petters
No, humans are pretty terrible at approximating e.g. TSP or max-cut.

I don't think it is a good definition of intelligence.

~~~
yters
Surprisingly, humans are actually pretty good at TSP, achieving better
efficiencies than state of the art appriximization algorithms.

------
LearnerHerzog
What does NP stand for?

~~~
cpburns2009
"NP" stands for "nondeterministic polynomial time". See:
[https://en.wikipedia.org/wiki/NP_%28complexity%29](https://en.wikipedia.org/wiki/NP_%28complexity%29)

(Not that I have the requisite knowledge to understand it).

~~~
dclowd9901
I'll treat this like an interview question, and anyone can correct me if I'm
wrong: My understanding of it is that it means it's impossible to predict the
best solution without brute forcing all possible combinations of action... am
I close there?

~~~
TheDong
I wouldn't count that as close for numerous reasons. If this were an interview
question, I would expect discussion of NP-complete vs NP-hard at the very
least.

> it's impossible to predict the best solution without brute forcing all
> possible combinations of action

That's not true; all possible combinations are not required to be checked;
frequently a greedy algorithm can eliminate the majority of possibilities
without actually checking them.

"Impossible" is also a very strong word.

Furthermore, there are plenty of problems where we currently can't solve them
without bruteforce ("impossible" to do so), but we don't know if they're NP-
complete/even in the NP-class.

However, the really important detail you're missing which makes your answer
completely wrong is the verification of the proof.

If a problem is of NP Complexity, than it must be computationally easy to
determine that an answer is correct in polynomial time.

Your answer simply stated that a solution could be found by brute-forcing, not
that the answer is easy to verify once found, and not that said brute-forcing
must not be in non-polynomial time.

By missing those two details, your answer is so far off the mark I'd recommend
passing in an interview based on that alone.

~~~
nitrogen
_...your answer is so far off the mark I 'd recommend passing in an interview
based on that alone._

What kind of work do you do that requires regular detailed analysis of the
complexity class of algorithms?

It's been my experience that it's enough for an engineer to be able to say,
"This algorithm will (not) run in an acceptable time for our expected input
sizes," and that the precise definitions of NP complete and NP hard are best
forgotten and looked up on Wikipedia when needed.

------
rootw0rm
A good read for learning fun and practical examples of how to define problems
for a solver. I never learned terribly advanced math because it bores me, but
papers like these are more accessible and help me get into the mathematician's
mindset.

