Homework 9
Due Date Thu 11/12 at 9:00pm (Week 9)
Purpose To enhance Sokoban with new features
Graded Exercises
In the previous part of Sokoban, you implemented player and item movement rules, added pit-traps, and extended the game-over check to account for losing the player down a pit. In this week’s exciting conclusion, you’ll add a new floor tile, and add a way to fix mistakes.
Exercise 1 You and your partner have two distinct implementations of Sokoban so far. Combine the best aspects of both of them: choose the cleaner data definitions, cleaner functions, more thorough testing, etc., and produce a new implementation of Sokoban part 2 that is better than either of your original starting points. Incorporate any feedback you received from your graders on the prior parts: if we noted that something is a poor implementation choice, you should fix it. Since this is the final part of this project, you will be graded cumulatively on all of it: prior mistakes can be penalized again.
Once you’ve merged your code and cleaned up any prior issues, you can add three new features:
Exercise 2 We add a new kind of tile: ice:
Ice tiles have no traction: if a player steps onto one, they will slide in that direction until they collide with an immovable item, or until they land on a non-ice tile. If, while colliding, they crash into a movable item, then the movable item starts sliding too. Here’s a tiny demo level to get you started, and the results of the player moving right twice:
And here’s a more fun introductory level to try
We are deliberately not specifying every possible behavior here, or every possible interaction of items, ice, player motion, and immovable things. Here are a few scenarios worth considering, and worth making a deliberate design choice for (there are several others worth considering as well!):
In the sample level, what if the trophy started on the ice?
Two adjacent movable objects on the ground are considered too heavy to move. But what if one or both of them are already on ice?
As a comic possibility: suppose you had a “slip-n-slide” of an ice runway followed immediately by a pit trap. Consider various combinations of items already on the ice, and decide their behavior.
Come up with small tutorial levels (i.e., test cases) to demonstrate the behaviors you decide upon. Be thorough. Leave comments in your code, near where you define the data for each level, that explain what scenario you want to test and why it’s interesting.
Keeping score:
Exercise 3 Add a step counter to keep track of the number of steps a player has made. Show the score somewhere on-screen. Lower scores are better!
Fixing mistakes:
Exercise 4 It’s far too easy to mistype and cause the player to take one too many steps, such that the game is no longer playable. Add an undo feature, that lets the player type "U" in order to rewind the game by one step. (Note that this should increase the player’s score! Undoing a bad move should not also rewind their score to something better.) Make sure that the game does not crash if the player tries to undo when there are not currently any moves to undo.
Have fun!
You might find some levels at
https://www.sokobanonline.com/play/lessons/ to be fun —