How hard are computer games? Graham Cormode, DIMACS

Similar documents
The Hardness of the Lemmings Game, or Oh no, more NP-Completeness Proofs

arxiv: v1 [cs.gt] 29 Feb 2012

Lecture 20 November 13, 2014

More NP Complete Games Richard Carini and Connor Lemp February 17, 2015

Super Mario. Martin Ivanov ETH Zürich 5/27/2015 1

Lecture 16 Scribe Notes

Contents. MA 327/ECO 327 Introduction to Game Theory Fall 2017 Notes. 1 Wednesday, August Friday, August Monday, August 28 6

STRATEGY AND COMPLEXITY OF THE GAME OF SQUARES

arxiv:cs/ v2 [cs.cc] 27 Jul 2001

Computational aspects of two-player zero-sum games Course notes for Computational Game Theory Section 3 Fall 2010

The Computational Complexity of Angry Birds and Similar Physics-Simulation Games

Lecture 19 November 6, 2014

Easy Games and Hard Games

5.4 Imperfect, Real-Time Decisions

Lumines is NP-complete

HIROIMONO is N P-complete

Week 1. 1 What Is Combinatorics?

EXPLORING TIC-TAC-TOE VARIANTS

depth parallel time width hardware number of gates computational work sequential time Theorem: For all, CRAM AC AC ThC NC L NL sac AC ThC NC sac

Sequential games. We may play the dating game as a sequential game. In this case, one player, say Connie, makes a choice before the other.

Plan. Related courses. A Take-Away Game. Mathematical Games , (21-801) - Mathematical Games Look for it in Spring 11

Computational complexity of two-dimensional platform games

Tiling Problems. This document supersedes the earlier notes posted about the tiling problem. 1 An Undecidable Problem about Tilings of the Plane

CMPUT 396 Tic-Tac-Toe Game

2048 IS (PSPACE) HARD, BUT SOMETIMES EASY

Quantified Boolean Formulas: Call the Plumber!

Scrabble is PSPACE-Complete

Problem Set 4 Due: Wednesday, November 12th, 2014

Adversary Search. Ref: Chapter 5

Game Theory and Algorithms Lecture 19: Nim & Impartial Combinatorial Games

Advanced Automata Theory 4 Games

Generalized Amazons is PSPACE Complete

arxiv: v1 [cs.cc] 2 Dec 2014

COMP9414: Artificial Intelligence Problem Solving and Search

Senior Math Circles February 10, 2010 Game Theory II

arxiv: v1 [cs.cc] 12 Dec 2017

Tetsuo JAIST EikD Erik D. Martin L. MIT

arxiv: v2 [cs.cc] 29 Dec 2017

Game Theory Lecturer: Ji Liu Thanks for Jerry Zhu's slides

Three of these grids share a property that the other three do not. Can you find such a property? + mod

Mind Ninja The Game of Boundless Forms

37 Game Theory. Bebe b1 b2 b3. a Abe a a A Two-Person Zero-Sum Game

Tetris is Hard, Even to Approximate

CS 188: Artificial Intelligence Spring 2007

arxiv: v1 [cs.cc] 21 Jun 2017

Section Summary. Finite Probability Probabilities of Complements and Unions of Events Probabilistic Reasoning

Tutorial 1. (ii) There are finite many possible positions. (iii) The players take turns to make moves.

Lumines Strategies. Greg Aloupis, Jean Cardinal, Sébastien Collette, and Stefan Langerman

Game Theory and Randomized Algorithms

The Complexity of Escaping Labyrinths and Enchanted Forests

NCSS Statistical Software

Taking Sudoku Seriously

arxiv: v1 [cs.cc] 7 Mar 2012

CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

Introduction Solvability Rules Computer Solution Implementation. Connect Four. March 9, Connect Four 1

arxiv: v1 [cs.cc] 28 Jun 2015

You ve seen them played in coffee shops, on planes, and

1. Simultaneous games All players move at same time. Represent with a game table. We ll stick to 2 players, generally A and B or Row and Col.

Hanabi is NP-complete, Even for Cheaters who Look at Their Cards,,

Graphs of Tilings. Patrick Callahan, University of California Office of the President, Oakland, CA

Problem ID: coolestskiroute

Variations on Instant Insanity

1 Introduction. 2 An Easy Start. KenKen. Charlotte Teachers Institute, 2015

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Algorithms and Game Theory Date: 12/4/14


Playing Games. Henry Z. Lo. June 23, We consider writing AI to play games with the following properties:

Tic-Tac-Toe on graphs

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Algorithmic Game Theory Date: 12/6/18

arxiv: v2 [cs.cc] 20 Nov 2018

Topics to be covered

QUICKSTART COURSE - MODULE 7 PART 3

MITOCW watch?v=x-ik9yafapo

28,800 Extremely Magic 5 5 Squares Arthur Holshouser. Harold Reiter.

Tac Due: Sep. 26, 2012

Realizing Strategies for winning games. Senior Project Presented by Tiffany Johnson Math 498 Fall 1999

Combined Games. Block, Alexander Huang, Boao. icamp Summer Research Program University of California, Irvine Irvine, CA

Tutorial: Creating maze games

DVA325 Formal Languages, Automata and Models of Computation (FABER)

Permutations. = f 1 f = I A

Ian Stewart. 8 Whitefield Close Westwood Heath Coventry CV4 8GY UK

On the fairness and complexity of generalized k-in-a-row games

CONCEPTS EXPLAINED CONCEPTS (IN ORDER)

Solutions to Exercises Chapter 6: Latin squares and SDRs

Introduction to Auction Theory: Or How it Sometimes

Stanford University CS261: Optimization Handout 9 Luca Trevisan February 1, 2011

Game Maker Tutorial Creating Maze Games Written by Mark Overmars

Coin Cappers. Tic Tac Toe

Formidable Fourteen Puzzle = 6. Boxing Match Example. Part II - Sums of Games. Sums of Games. Example Contd. Mathematical Games II Sums of Games

Game-playing AIs: Games and Adversarial Search I AIMA

Techniques for Generating Sudoku Instances

ActivArena TEMPLATES TEACHER NOTES FOR ACTIVARENA RESOURCES BLANK WORKING SPACE SPLIT (WITH TITLE SPACE) About this template

MITOCW watch?v=7d73e1dih0w

Taffy Tangle. cpsc 231 assignment #5. Due Dates

Table of Contents. Table of Contents 1

class TicTacToe: def init (self): # board is a list of 10 strings representing the board(ignore index 0) self.board = [" "]*10 self.

Weighted Polya Theorem. Solitaire

Register Allocation by Puzzle Solving

Logical Agents (AIMA - Chapter 7)

11/18/2015. Outline. Logical Agents. The Wumpus World. 1. Automating Hunt the Wumpus : A different kind of problem

Exercises for Introduction to Game Theory SOLUTIONS

Transcription:

How hard are computer games? Graham Cormode, DIMACS graham@dimacs.rutgers.edu 1

Introduction Computer scientists have been playing computer games for a long time Think of a game as a sequence of Levels, where each level has some objective that must be carried out to complete the level Given a Game and a Level, what is the complexity of finding a solution to the level? Depends on : How many players? Predictable or random? How much information does player have? 2

2 Player Game Puzzle Just a puzzle... "Toe-Tac-Tic": the first player to make three in a row loses. O X Is this game a win for the first player, a draw, a win for the second player? X 3

A different 2 player game Start with S = {1,2,3,4,5,6,7,8,9} Players take turns to remove an item from S and add it to their set. Winner is first who has a subset of size 3 that adds to 15 Is this game a win for the first player, a draw, a win for the second player? Eg. A takes 5, B takes 6, A 8, B 2, A 4, B 7 B wins: 6 + 2 + 7 = 15 4

Related Areas 2 or more players, complete information, no randomness -- Game Theory, Nim games, Min-max theorem, Nash equilibrium etc... Very many players, partial information, some randomness -- Economics! Insider trading, Auction theory, mechanism design, internet protocols... 1 Player, complete information, no randomness -- Computer Games (today's topic). 5

Outline Some prior work on computer games Some work in progress: Lemmings Hardness of Lemmings Hardness under restrictions Under what restictions is Lemmings not hard? 6

1 Player Computer Games Mostly, these are puzzle games: each level is a configuration of pieces that the player can manipulate or interact with, in order to reach some solution. The computer enforces the rules, but is not a player: no monsters to shoot Maybe there is a time limit 7

Example 1: Minesweeper A board with mines hidden locate the mines but don't click on one! Question: Given a Minesweeper configuration (board with labels and counts) is it consistent? That is, is there some arrangement of mines that would give rise to that configuration? 8

Minesweeper The problem is NP-hard [Kaye, 2000] Easy to check if a proposed layout of mines is consistent with the input Can encode Satisfiability problems by connecting up 'gadgets' (logic gates) made out of mines. Wires with phase change 9

Example 2: Tetris 10 How to formalize Tetris? Problem instance Complete information (1) Current board configuration (2) List of all future pieces. Decision problem: can all blocks be cleared? Generalization of the game: We must allow arbitrary sized playing area.

Tetris is Hard Again, the problem is NP-Hard [Demaine, Hohenberger, Lieben-Nowell, 2003] This time, transform from a bin packing problem: initial configuration represents a set of bins, the game pieces in order encode a set of integers in unary. Show that the game board can be cleared if and only if there is a solution to the bin packing problem. 11

Example 3: Sokoban Push blocks into storage locations Decision problem: Is there a strategy that stores all blocks? In NP: can check the proposed solution (assumes solution is polynomial in the level size) Not only is Sokoban NP-Hard, it is P-Space complete: can emulate a finite tape Turing Machine 12

Emacs is NP-Hard All three of these games are in Emacs: M-x tetris M-x sokoban M-x xmine Therefore, we conclude that Emacs is NP-hard. Since many students use Emacs to write their theses in, we must conclude that this is also a hard task, as proved by the students who spend most of their time playing computer games... 13

New Stuff I've been looking at the computer game 'Lemmings' Lemmings is quite complicated to describe to someone who hasn't played before, will attempt to give a cut-down description. The world is made up with of three kinds of stuff: steel, earth, and air. 14

Lemmings Lemmings are stupid creatures... they keep walking in one direction until they hit a wall and turn round or fall down a hole... Lemmings die if they fall too far, else they keep going The player can give certain skills to individual Lemmings that change how they proceed. The skills are permanent (stay with lemming forever), temporary (stop under certain conditions), plus two that don't fit into either category... 15

Skills The Lemming Skills are: Floater (permanent): Lemming can fall any distance Climber (permanent): Lemming can scale walls Digger (temp): Lemming digs down through earth Miner (temp): Lemming digs diagonally Basher (temp): Lemming digs horizontally Builder (temp): Lemming builds a small bridge Blocker (other): Lemming stops & blocks others Bomber (other): Lemming explodes & damages earth 16

The Lemmings Problem 17 Formalize: L (a level of lemmings) is a tuple with these entries: limit: the time limit save: the number of lemmings to save lems: the number of lemmings at the start start: initial position of the lemmings width, height: size of the level grid: description of the game board exit: location of the exit skills: 8-vector listing available quantity of each skill Problem: given L, is there a strategy that gets at least save lemmings to the exit?

18 Example Level

Outline of Hardness Proof Show that Lemmings is hard by encoding instance of 3-Sat (m clauses, n variables). Will show that the level is solvable iff the instance is satisfiable First need to show that the problem is in NP 19

Lemmings is in NP Informally, the computer game shows Lemmings is in NP: the player provides the "certificate", and computer checks it. Formally, write down a strategy (step-by-step description of what to do) then check this certificate in poly-time: each move is valid, enough are saved. Detail: want the strategy to be poly in input size. Fix by insisting that time limit is bounded by poly in grid size then check each step in poly time. 20

Encoding 3Sat Use a bunch of gadgets, then 'wire' these together to make the encoding. Use one lemming to represent each clause, and another lemming for each variable. Clause lemming chooses one of the literals in the clause. Only reaches exit if that literal is satisfied. Variable lemming sets its variable to true or false. 21

Clause Gadget (X v Y v Z) X Y Z Three ways out, one for each literal in the clause Only way out is for the Lemming inside to dig out. 22

Variable Gadget 23 Only way out is for Lemming to bash one door, build a bridge over one of the gaps.

Variable Gadget 24 Only way out is for Lemming to bash one door, build a bridge over one of the gaps.

Wiring Junction forces lemming out to the right Wire lets paths cross We will restrict number of skills availble so there are none spare to change paths 25

Putting it together Build a "routing grid": put a bunch of clause gadgets at the top, and a bunch of variable gadgets at the bottom right leading to the exit. Inside the grid, have one column for each clause literal (3m columns in total), and one row for each variable and its negation (2n rows). Put a junction in position [3i + j, 2k] if j'th literal in i'th clause is x k Put a junction in position [3i + j, 2k+1] if j'th literal in i'th clause is ~x k 26

Example (~V 1 v V 2 v ~V 3 )? (~V 2 v V 3 v V 4 )? (V 1 v ~V 2 v ~V 4 )? (~V 1 v ~V 3 v ~V 4 ) 27 V 1 V 2 V 3 V 4

Detail of Example 28 C 1 = (~V 1 v V 2 v ~V 3 )

More Detail v 3 ~v 3 v 4 ~v 4 29

Proving the theorem To prove the theorem requires some case analysis and arguments. Need to argue that every solution to the lemmings level is a satisfying assignment to the 3SAT instance and vice-versa No details here, it's mostly straightforward... So Lemmings is NP-Hard Since the certificate can be checked in poly-time: Lemmings is NP-Complete 30

Other variations OK, so we know Lemmings is NP-Complete, is that it? In the transformation, we used only temporary skills (bashers, diggers and builders) -- what about Lemmings with other skills? In fact, if we only have permanent skills, then the problem is decidable in polynomial time. 31

Decidable Lemmings Model the game board as a graph, G. Each location is represented by 4x2 nodes: 4 corresponding to a lemming with no skills, with climbing, with floating, and with both. 2 corresponding to facing left or facing right For each node, we know what node the lemming will go to. (Special node for dead ). We can also put edges corresponding to giving a lemming a certain skill. 32

A Simple Graph Problem Since the board does not change during play (no temporary skills to change the board), G is static, the problem reduces to reachability problems on G Still a little fiddly, since we have to choose how best to allocate the skills we do have. Remove all lemmings that reach the exit unaided. Then see how many exit with only climbing or only floating. 33 Then (after some calculations) see how many of the remainder make it out if given both skills.

Back To Hardness OK, now we know that Lemmings is NP-Hard, and under restrictions, it is decidable. Are we done now? Not quite: the hardness proof is a little unsatisfying since it needs lot of entrances, and lots of Lemmings. What if there is only one Lemming? Is the game still NP-Hard? 34

Hardness of 1-Lemmings Recent result (with Mike Paterson): yes, 1-Lemmings is also NP-Hard. (This supersedes the previous hardness result, but it's more detailed and requires more gadgets). This shows it's hard to approximate the number of Lemmings that can be saved, up to any factor. 35

Main Gadget The main new gadget is the one-way: if the Lemming has come down this gadget, then it cannot later go across it. First, the Lemming is sent down vertically through all one-ways corresponding to a variable. Then it must go left to right through clauses. 36

Wiring We also need to loop the lemming back to the top after each vertical descent (setting a variable), and from left to right after each horizontal crossing (satisfying a clause) This requires some extra pieces of wiring, but nothing too difficult To ease presentation, represent with icons: One way wire Clause Junction 37

Example 2 38 (~V 1 v V 2 v ~V 3 )? (~V 2 v V 3 v V 4 )? (V 1 v ~V 2 v ~V 4 )? (~V 1 v ~V 3 v ~V 4 )

39 Close up of Example

1-Lemmings is NP-Hard As before, must argue that every path to the exit corresponds to a satisfying assignment to 3SAT and vice-versa Some details left to fill in, but the main idea is there So, Lemmings is NP-Hard with 1 Lemming Hence, hard to approximate how many lemmings can be saved on any level 40

Conclusions Now we know why Lemmings was so tough... In the real game, most levels are not so repetitive But, levels with only floaters and climbers are usually easier. Is there something deeper here: are most 'good' puzzle games NP-hard? Are there many good puzzles that are known to be in P? (eg sliding block puzzles, 14-15) 41

Open Problems 42 Is Lemmings P-Space Complete? Can it encode Turing machines? (details: need to encode bits - might be able to do this using bridges, which can be destroyed). Are there weaker restrictions under which it is in P? What about other games? Solitaire, FreeCell, Doom, etc.? Is your favorite game NP-Hard? Or weaker: does it encode CFG languages? Does it make sense to talk about the complexity of certain games?

Answer to puzzle 1 In "toe-tac-tic" the first player can always force a draw. She takes the center square, and then her tactic is to "mirror" every move the second player makes. Then the only way she would make a line is if the second player already has. 43

Answer to puzzle 2 Write S as a magic square. Every subset of S that sums to 15 is a row in the magic square. Each player taking an item from S = putting a marker on that number 6 1 8 7 5 3 2 9 4 Game is won when they have three in a row. So game is equivalent (isomorphic) to Tic-Tac-Toe 44

Super Mario? ######################################################################### # RSG-SMB-TAB-1.1 # ########################################################################## How to Win "Super Mario Bros" Nintendo Entertainment System WORLD 1 - LEVEL 1 +----------------------------------+ Key: < = Left > = Right ^ ^ = Up < > O O v = Down v select start B A B = B button A = A button +----------------------------------+ < ------------------------------------------------------------------------ > OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO ^ ------------------------------------------------------------------------ v ------------------------------------------------------------------------ B --------------------------OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO A ------------------------------------------------------------------------ 45 < ------------------------------------------------------------------------ > OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO ^ ------------------------------------------------------------------------ v ------------------------------------------------------------------------ B OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO A ------------------------------------------------------------------------