Question: w - move the sprite up s - move the sprite down a - move the sprite left d - move the sprite right q

w - move the sprite up
s - move the sprite down
a - move the sprite left
d - move the sprite right
q - quit the game
space - reset the board
These controls are also outlined in the provided game_settings.py file.
The sprite (i) can move in empty spaces on the board but cannot pass through walls (+). It can push a single box (!) into an empty or target (o) space but cannot push more than one at a time. In other words, boxes cannot be pushed into other boxes or walls. Pushing the box right:
++++++++
+.+
+ i ! o +
+! o +
++
++++++++
results in this board:
++++++++
+.+
+ i ! o +
+! o +
++
++++++++
When the box is pushed onto a target, it is converted from a non-statisfied box (!) into a satisfied box (.). Moving the sprite right once more, does exactly that:
++++++++
+.+
+ i .+
+! o +
++
++++++++
Note that satisfied boxes (.) can be moved off the target and convert back into non-statisfied boxes (!). Additionally, when the sprite stands on a target space, its string is changed to indicate a target is below (I):
++++++++
+.+
+ I !+
+! o +
++
++++++++
Once the sprite moves off the target, both spaces revert back (I to i and o):
++++++++
+. i +
+ o !+
+! o +
++
++++++++
The game ends when a win is detected, or the user quits the program
Quitting prints the message: "Goodbye"
Winning prints the message: "You Win!"
General Structure of the Program
When boiled down, most simple games have the same repeated set of actions:
the program provides information about the current game state to the player
the user takes action through input
the program reacts
the program identifies the input
the program updates the game state
repeat forever, or until the user wins or loses
This loop is often referred to as the game loop, and is where the bulk of the game's code lives. Generally, there are things the program must do before the game starts and after it ends:
Preparation; initialize counter variables and copies of important information
Game Loop
Exit Protocol
main.py
This file is where you will write Sokoban.
game_settings.py
This is a read-only file that provides global variables for the different space types (sprite, empty space, box, etc.), valid user controls, and the game board. To pass all test cases, ensure you use these variables throughout your code, as some test cases will change their values and will expect your code to adapt. Your program should be using the board that is given in this file. More information on the TEST_CASE_15_BOARD will be given later on in the write-up.
Quick Tips
Do not use exit() or quit() as doing so will make test cases 15 & 16 fail whether your game works properly or not.
Do not use the following if statement in your main.py module:
if __name__=="__main__":
Suggestions
Things to consider before developing your program:
How can you easily find or track the sprite location to avoid repetitive searches?
Can you do the same for tracking the win condition?
Can you generalize your logic so that regardless of the direction of the movement, the code is the same?
What do you need to reset the game? HINT: take a look at the copy/deepcopy functions on your reference sheet.
Sample Game:
++++++++
+.+
+ i ! o +
+! o +
++
++++++++
d (Player moves right)
++++++++
+.+
+ i ! o +
+! o +
++
++++++++
d
++++++++
+.+
+ i ! o +
+! o +
++
++++++++
d (Player pushes the box onto the target, converting the BOX_NS into BOX_S)
++++++++
+.+
+ i .+
+! o +
++
++++++++
d (Player pushes the box off the target, converting BOX_S to BOX_NS, and steps onto the target, converting SPRITE into SPRITE_T)
++++++++
+.+
+ I !+
+! o +
++
++++++++
(Player resets the game)
++++++++
+.+
+ i ! o +
+! o +
++
++++++++
d
++++++++
+.+
+ i ! o +
+! o +
++
++++++++
d
++++++++
+.+
+ i ! o +
+! o +
++
++++++++
w
++++++++
+. i +
+! o +
+! o +
++
++++++++
d
++++++++
+. i +
+! o +
+! o +
++
++++++++<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!