Easy Games and Hard Games Igor Minevich April 30, 2014
Outline 1 Lights Out Puzzle 2 NP Completeness 3 Sokoban 4 Timeline 5 Mancala
Original Lights Out Puzzle There is an m n grid of lamps that can be on or off. Clicking a lamp switches the state of it and the lamps adjacent to it (vertically and horizontally). Starting with all lamps on (or some subset of lamps on), the goal is to switch them all off.
Generalized Lights Out Puzzle There is an undirected graph with vertices that are black or white. Click a vertex makes it and all its adjacent vertices switch color. Goal: starting with all vertices black, make all vertices white.
Mathematical Interpretation The vertices are elements of a vector with entries in F 2. Black = 0; White = 1. Let A be the adjacency matrix of the graph (A ij = 1 vertex i is adjacent to vertex j). A is symmetric, and its diagonal entries are all 1. We want a vector x such that A x = 1, the all-1 s vector.
My Theorem Theorem Let A be a symmetric matrix over F 2. Then the vector d composed of the diagonal entries of A is in the range of A. Proof We want to show d Range(A) = Range(A T ) = Nul(A). Thus we want to show d x = 0 if A x = 0. WLOG x = (1,..., 1, 0,..., 0) T where the first k elements are 1 (otherwise, permute corresponding rows and columns of A). Computation shows d x = k i=1 A ii = 0.
Computation If A is N N and A(1,..., 1, 0,..., 0) T = 0 then for all j = 1,..., N k 1 A jk = A jj + Therefore, i=1 i j A ji k 1 k 1 A kk = A kj = j=1 j=1 k 1 k 1 k 1 k 1 = A jj + A ji = A jj + 2 j=1 Therefore, j=1 i=1 i j j=1 k A jj = 0 j=1 A jk k 1 j>i 1 A ji k 1 = j=1 A jj
The Theorem is Sharp Other Fields A = ( 1 2 2 4 ) B = ( 1 θ θ θ 2 A shows the theorem does not hold in any characteristic p 2, and B shows it does not hold in F 2 2, hence in any F 2 n. Here, θ is a generator for the multiplicative group of F 2 2. Not Symmetric The theorem is not true if the matrix is not symmetric: e.g. ( ) 1 0 C = 1 0 )
Solving the Lights Out Puzzle Just write down the adjacency matrix A and solve A x = 1. Gaussian elimination takes O(n 3 ) operations if A is n n. If we work with even a 4 4 grid, then n = 16; computation is already difficult for a human. For a standard computer, even n = 1000 is easily doable. Strategy for the grid version: start with an arbitrary combination on the bottom row and then work upwards. Try all combos until you get one that works.
Classes of Problems P ( polynomial time ) is the class of problems (involving a variable n of inputs) which can be solved in polynomial time (in terms of n). NP ( nondeterministic polynomial time ) is the class of problems whose solution is verifiable in polynomial time. NP-hard is the class of problems that are at least as hard as the hardest NP problems, i.e. a problem p is NP-hard iff any NP problem can be reduced to p in polynomial time. NP-complete = NP NP-hard P vs. NP problem: Does P = NP?
Some NP-Complete Problems Hamiltonian Path Problem Subset Sum Problem Generalized Sudoku (n 2 n 2 board with n n blocks) Bejeweled Kakuro Battleship Puzzle
Sokoban Sokoban means warehouse worker in Japanese. Setup: there is a warehouse (a rectangular grid) with boxes, walls, storage locations, and a worker (these are all 1 1). Goal: the worker needs to push all the boxes into storage locations. Rules: The worker cannot move a wall, and he cannot push more than one box at a time.
PSPACE Completeness PSPACE is the class of all problems that can be solved using polynomial space. PSPACE-complete is the class of problems p in PSPACE such that any PSPACE problem can be reduced to p in polynomial time. Sokoban is PSPACE-complete, hence much harder than an NP-complete problem.
Mahjong The usual solitaire game is PSPACE-complete (the goal is to determine the play which is likeliest to yield a win). If peeking under the tiles is allowed, Mahjong is NP-complete.
Start of Timeline 3000 BC: Earliest game similar to checkers found 500 BC: Mahjong invented by Confucius (according to myth) 700 AD: Earliest instance of Mancala-like game found 1971: P vs. NP introduced by Stephen Cook 1979: Sudoku was probably invented by Howard Garns from Connersville, IN 1981: Sokoban created
End of Timeline 1983: Vulcan Electronics released XL-25, later known as Lights Out (Tiger Toys in 1995) 1994: I was introduced to Sokoban 1997: Sokoban proven PSPACE-complete by Joseph Culberson 2012: I proved my theorem. Last Wednesday: I defended my thesis!
Rules The board consists of two rows of holes with marbles in them and also two score-keeping holes called kallahah on the sides. Players start with 4 (or 5 or 6, etc.) marbles in each hole. They take turns sowing by taking all the marbles in one of the holes on their side and distributing them counterclockwise to the other holes, excluding the opponent s kallahah. If the last sown marble lands in an empty hole on the player s side, the player captures it and all the marbles in the opposite hole on the opponent s side. If the last sown marble lands in the player s kallahah, the player goes again. If a player cannot move because he has no marbles left, the opponent captures all the marbles on his side and the game ends.
Analysis As far as I know, generalizations such as n 2 boards or starting with n marbles in each hole have not been considered. It is difficult enough to analyze the usual game. One way to analyze positions is to disregard the captured marbles, using induction.
Oware Captures are different: if the last marble sown ends on the opponent s side and as a result the tally for that hole is 2 or 3, the player captures those 2 or 3 marbles. In case of a capture, one goes clockwise backwards and applies the same procedure: if the tally had increased to 2 or 3, then those marbles are captured. Game cycles can occur in Oware (same position happens more than once). The game-tree complexity of Oware is much larger.
Other Rules The player must make sure the opponent has marbles to play with, if possible. The player cannot capture all of the opponent s pieces. Ethiopian rules: a player cannot sow from a hole that only has one marble, but he can sow in either direction.