Java program demonstrating Mario, Zelda, and Pokemon to be NP-hard. Also includes algorithms for planarity testing, planar embedding, and graph drawing.
This is a Java program that implements reductions demonstrating that certain
problems are hard. Specifically, it demonstrates that Mario, Zelda,
Pokémon, Push-1, and PushPush are NP-hard using reductions from 3-SAT.
This program also implements algorithms that are actually useful, including
planarity testing, planar embedding, and graph drawing algorithms. It is tested
in Java 7.0, but I think it probably works in Java 5.0 and higher.
This project includes implementations of the following algorithms, each of which
takes linear time assuming constant amortized HashMap
/ HashSet
performance:
It also includes the following features:
This program demonstrates that the original Super Mario Bros., the original
Legend of Zelda, all versions of Pokémon, and the Push-1 and PushPush
games are NP-hard using reductions from 3-SAT. In each case, the problem is
whether it is possible to get from here to there. For an explanation of the
term “NP-hard”, see the Wikipedia article on P vs.
NP. Basically, any program
that determines whether it is possible to beat a level in one of the
aforementioned games must take a long time to run, in a certain formal sense.
(This is assuming the unproven but widely believed claim that P ≠ NP.) For a
definition of 3-SAT, see
src/com/github/btrekkie/reductions/bool/ThreeSat.java.
For a demonstration of the Mario reduction, run the following UNIX commands from
the root project directory:
- mkdir bin
- javac -sourcepath src `find . -name "*.java" | grep -v Test` -d bin
- java -cp bin com.github.btrekkie.reductions.mario.MarioProblem
A window displaying a Mario level should appear. The level takes a while to
render. For faster results, click the “+” button 15 to 20 times. To see
demonstrations of the Zelda, Pokémon, or Push-1 / PushPush reductions,
change mario.MarioProblem
in the last command to zelda.ZeldaProblem
,pokemon.PokemonProblem
, or push1.Push1Problem
respectively.
Pokémon problems feature strong trainers, who always defeat the player,
and weak trainers, who never defeat the player. The sight lines of the strong
trainers are show in blue, and the sight lines of the weak trainers are shown in
red.
The gadgets and reduction structure are taken from Aloupis, Demaine, Guo,
Viglietta (2012): Classic Nintendo Games are (Computationally)
Hard and Demaine, Demaine, and O’Rourke
(2000): PushPush and Push-1 are NP-hard in
2D. See those papers for a more
detailed description of what is going on in the stages this program produces.
See https://btrekkie.github.io/reductions/index.html for API documentation.