Homework 7
Due Date Tue 10/27 Thurs 10/29 at 9:00pm (Week 7)
Purpose To make Sokoban into a playable game
Finger Exercises
Exercise 1 none yet
Graded Exercises
In this assignment, you’ll add enough behavior to Sokoban to make it a playable game. Plus, you’ll add a new extension to the game so far.
Exercise 2 There are a few rules of player motion:
A player can move at most one cell in any of the four cardinal directions (up, down, left, right), and cannot move on a diagonal.
A player cannot walk onto or through walls.
A player can stand on a target, and crates and trophies can be moved onto or off of targets.
If a player is adjacent to a crate or a trophy, and tries to move to that square, the player will push the item out of the way. (For example, if the player is to the left of a crate, and tries to move right, then the player will push the crate one cell to the right, and then move into the space formerly occupied by the crate. The same is true in the other directions.) But...
If a player is adjacent to a crate or a trophy, and that item is adjacent to another item (or a wall), then neither the item nor the player can move. Think of it as, the player is strong enough to push one item, but two items in a row are too heavy for the player to move.
There is no way for a player to “pull” an item (though that would be a fun extension of the game!) —
players can only push items around the board. In fact, determining if a level is winnable is proven to be an extremely challenging problem, and as far as Computer Science knows, cannot be solved any more cleverly than by brute-force trying every single player motion...
As before, the game ends when the player has won the level. You do not have to determine if the board is no longer winnable!
Here’s a fun introductory level to play, to get you started:
Exercise 3 Here we get a bit sneaky. We’ll add a new kind of tile: a hole:
Things can fall into a hole, and if something falls into a hole, it fills the hole, and both the thing and the hole vanish, leaving normal floor. If the player falls in a hole, the game ends. If a trophy falls in a hole, the trophy is lost forever.
Enhance your data definitions from the previous part to incorporate these new holes. In a comment, explain:
What changes did you have to make to your data definitions from the previous assignment, and why?
Had you known in the prior assignment that holes would be arriving now, would you have designed your data differently?
If we were to enhance the game with new kinds of tiles in the next assignment, would your revised data definitions accommodate those changes more easily?
Exercise 4 Enhance your rules of motion to account for holes, so that when an item is pushed into a hole (or the player falls in!), the item and the hole disappear. Enhance your stop-when condition so that the game ends when either the level is won or the player falls into a hole and vanishes.
Here’s a simple level with holes, to get you started: