Introduction: The Puzzle
EECS281Games™ is developing a new puzzle game that they want to bring to the market in the next few weeks. They’ve already built the engine and designed thousands of levels, but they realized that they’re not sure how to solve many of them! What’s worse, they think some of them are unsolvable!
You are tasked with developing a C++ program that will take as input a sample map and some command-line flags indicating how your program will behave. You will process the map, check that the input is valid, then output information about the puzzle’s solvability and a description of the puzzle’s solution (if it has any).
The game is played on a grid, filled with open space and walls that block player movement. Here is a small sample input that your program could receive:
2 4 7
// A simple example puzzle
// 2 colors (A, B)
// 4x7 grid @..A..b
.a.#B## ####...
?..B.^^
The goal of the game is for the player to get from their starting location (marked with @) to the target (marked with ?), by pressing buttons (a, b, ..., z and ^) that open and close doors (A, B, ..., Z) that stand in their way.
The player’s available moves are to travel one tile north, east, south, or west (up, right, down, or left) as long as there’s no wall (#) or closed door (A, B, ..., Z when closed) in their way. The player cannot move diagonally, or step off of the grid (you can imagine the specified map is surrounded by impassable walls).
The valid map symbols:
The maps aren’t just simple mazes -- they include special puzzle elements called “buttons” and “doors”. When the player moves onto an active button (e.g. b), it gets triggered:
When the player moves onto an active trap (^), it gets triggered:
2 4 7
// A simple example puzzle
// 2 colors (A, B)
// 4x7 grid @..A..b
.a.#B## ####...
?..B.^^
With the game’s rules in mind, let’s see how the above puzzle can be solved:
Your program will attempt to find a solution to the puzzle, and present it as output. The exact details of this process will be described in the next section, but it won’t make sense unless you read this section first. Our goal is to take a map as input and find a sequence of moves (moving north, east, south, and west, or triggering buttons/traps) that bring us to the target, or confirm that this isn’t possible. There’s no obvious strategy to solving these puzzles- we have to make a lot of decisions and the “best” decision in each case is not obvious or clear.
So instead of trying to cleverly reason about how to best solve these puzzles, we’ll just try to make every possible move and see where that gets us. This is possible because of a few observations relating to the player’s state.
The player has a position in the grid (row, col) (the top left corner is position (0, 0) and the bottom right is (height-1, width-1)). The player’s initial position is wherever the @ symbol is in the input grid. In addition, there is an active button color: the color of the last trap/button pressed. The initial color is ^, since all doors start closed.
The player’s complete state is the combination of their color and position (row and column).
In other words, you can think of the player as being inside of a 3D maze, instead of a 2D maze. The number of “rooms” in this maze is equal to the number of colors + 1. Room 0 is the ^ room. Room 1 is where you go after pressing button a; room 1 has no A walls. Room 2 is where you go after pressing button b, etc. Room 0 has no traps; the traps exist in all other rooms. Think about saving memory here; see the “Tips” section later on.
The player’s state tells us everything about where they are and whether they can win.
First, how the player got to their state S doesn’t affect whether or how they can win; only the state S itself (and the map) does. If you know how to get from state S to the target, then any method to get from the start to state S will work.
Secondly, there are at most (number of colors) * width * height possible states. Together, these two observations lead to the following strategy:
In more detail:
current_state. Add them to reachable_collection, but only if they have never been added before.
Based on the observations above, once we’ve completed this process, we will have either found the target, or every state that can possibly be reached will have been in the reachable_collection at some point. Thus, we can use it to decide whether or not the puzzle is solvable.
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of