Sokoban
Overview
The main idea of Sokoban is a small grid board, containing walls, boxes, storage locations and a single player. The player moves around the board pushing boxes around until they manage to get all boxes stored in one of the storage locations! Feel free to check out the wikipedia entry for Sokoban too.
For this assignment, you will be building both a level generator for the game, as well as the mechanics to play your created levels!
Getting Started
- Create a new folder for your assignment. Here is an example:
mkdir ass1 cd ass1
- Fetch the starter code using the command below. Alternatively download the starter code here.
1091 fetch-activity cs_sokoban
- Check that everything works by running the autotest.
1091 autotest cs_sokoban
(These should fail initially. If you want to exit running the autotest midway, press [ctrl-c]
.)
Initial Code and Data Structures
The starter code for this assignment includes some functions and defined types:
- A
print_board(...)
function:- This prints out the current state of the board, allowing the user to play the game.
- This ensures that the board will be consistent between you and the autotest.
- A
init_board(...)
function:- This sets up the board with default values.
- A
struct tile
struct:- Each square of the board (aka the 2D array) holds a
struct tile
. This tells us information about what is at that location in the board. - Note that the player location is stored separately to the contents of the board.
- Each square of the board (aka the 2D array) holds a
- A
enum base
enum:- This is used within
struct tile
. Every position on the board must be exactly 1 of these values (NONE
,WALL
, orSTORAGE
).
- This is used within
Reference Implementation
To help you understand how the assignment works, we have written a reference implementation for you to run. You can run it via the command 1091 cs_sokoban
.
1091 cs_sokoban === Level Setup === ...
FAQ
Stages
We have broken the assignment spec down into incremental stages:
- Stage 1: Level Builder - adding boxes, walls, and storage locations.
- Stage 2: Player Movement - adding player starting location, player movement and move counter.
- Stage 3: Core Game Mechanics - moving boxes, win condition, and reset level.
- Stage 4: Advanced Game Mechanics - undo command, pushing multiple boxes, and linking boxes.
- Extension (no marks): Adding graphics, multiple levels per game, and storing levels in text files.
Your Tasks
This assignment consists of four stages. Each stage builds on the work of the previous stage, and each stage has a higher complexity than its predecessor. You should complete the stages in order.
Stage 1
In Stage 1, you will set up the level builder for the Sokoban game. It includes asking the user for commands to place walls, boxes, and storage locations.
There is a reference implementation that you can play by running the command 1091 cs_sokoban
in the terminal.
Here is an example of input for a finished stage 1 that you can try within the reference implementation.
1091 cs_sokoban w 0 0 s 1 1 s 10 10 b 1 0 b 1 1 W 0 0 9 0 [ctrl-d]
(note: the lowercase w
and capital W
are different commands)
Stage 1.1: Setting up level builder
To create a level builder, we need to give the user the ability to add items onto the board via commands until they decide to start playing the game. In this substage you will create a command loop that lets players add WALL
or STORAGE
to the board.
In this substage, you will need to do the following:
- Print out
=== Level Setup ===\n
. - Setup a loop for reading in commands.
- Given the command:
w [row] [col]
a wall will be placed at position[row][col]
. - Given the command:
s [row] [col]
a storage location will be placed at position[row][col]
. - Before reading in the next command, print out the board with the provided
print_board()
function. - The loop should stop when the user inputs
[ctrl-d]
.
Don't worry about error checking for this, we will cover that in a future stage :)
Clarifications
- If a wall gets placed on a storage location, or vice versa, override the value.
- We will only test valid
row
andcol
values within the map during this stage. - We will only test valid commands.
Examples:
Autotest
Stage 1.2: Array bounds checking
In stage 1.1, we didn't check if the given values are outside of the bounds of our array/board. Currently our program will crash in these cases, so let's fix that now!
In this substage, you will need to do the following:
- When the user enters the
w
ors
command, check thatrow
andcol
are within the bounds of the board. If either one is out of bounds, print outLocation out of bounds
and don't modify the board.
Clarifications
row
andcol
will always be integer values.
Examples
Autotest
Stage 1.3: Add boxes
Add functionality for boxes to be added to the board. Although boxes can exist in the same tile as a storage location, we should never have a box and a wall at the same position.
In this substage, you will need to do the following:
- Given the command
b [row] [col]
, add a box at that location.- If there is a storage location there, we will end up with both a storage location AND a box.
- If there is a wall there, change the base from
WALL
toNONE
and add in the box.
- Check that
row
andcol
are within the bounds, else, printLocation out of bounds
. - Edit your
w
so that if someone places a wall where a box already exists, it removes the box.
Examples
Autotest
Stage 1.4: Add lines of walls
Add the capital W
commmand to add lines of walls.
In this substage, you will need to the following:
- Given the command
W [start_row] [start_col] [end_row] [end_col]
, add a line of walls from[start_row][start_col]
to[end_row][end_col]
. - If both start and end locations are out of bounds, print
Location out of bounds
. - If only part of the line is out of bounds, add in the valid positions (ignore the out of bounds values) and don't print an error message.
Clarifications
- We will only ask for values that form horizontal or vertical lines. We will never ask for a diagonal line.
- We will only test values when
start_row
<=end_row
andstart_col
<=end_col
Examples
Autotest
Testing and Submission
Are you finished with this stage? If so, you should make sure to do the following:
- Run
1091 style
, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style! - Autotest for this stage of the assignment by running the
autotest-stage
command as shown below. - Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1091 style cs_sokoban.c 1091 autotest-stage 01 cs_sokoban give dp1091 ass1_cs_sokoban cs_sokoban.c
Assessment
Assignment Conditions
Joint work is not permitted on this assignment.
This is an individual assignment.
The work you submit must be entirely your own work. Submission of any work even partly written by any other person is not permitted.
Except, you may use small amounts (< 10 lines) of general purpose code (not specific to the assignment) obtained from a site such as Stack Overflow or other publicly available resources. You should attribute clearly the source of this code in an accompanying comment.
Assignment submissions will be examined, both automatically and manually for work written by others.
Do not request help from anyone other than the teaching staff of DPST1091, e.g. in the course forum & help sessions.
Do not post your assignment code to the course forum - the teaching staff can view assignment code you have recently autotested or submitted with give.
Rationale: this assignment is designed to develop the individual skills needed to produce an entire working program. Using code written by or taken from other people will stop you learning these skills. Other CSE courses focus on the skill needed for work in a team.
The use of code-synthesis tools, such as GitHub Copilot, is not permitted on this assignment.
Rationale: this assignment is intended to develop your understanding of basic concepts. Using synthesis tools will stop you learning these fundamental concepts.
Sharing, publishing, distributing your assignment work is not permitted.
Do not provide or show your assignment work to any other person other than the teaching staff of DPST1091. For example, do not message your work to friends.
Do not publish your assignment code via the internet. For example, do not place your assignment in a public GitHub repository.
Rationale: by publishing or sharing your work you are facilitating other students using your work which is not permitted. If they submit your work, you may become involved in an academic integrity investigation.
Sharing, publishing, distributing your assignment work after the completion of DPST1091 is not permitted.
For example, do not place your assignment in a public GitHub repository after DPST1091 is over.
Rationale: DPST1091 sometimes reuses assignment themes using similar concepts and content. Students in future terms find your code and use it which is not permitted and you may become involved in an academic integrity investigation.
Violation of the above conditions may result in an academic integrity investigation with possible penalties, up to and including a mark of 0 in DPST1091 and exclusion from UNSW.
Relevant scholarship authorities will be informed if students holding scholarships are involved in an incident of plagiarism or other misconduct. If you knowingly provide or show your assignment work to another person for any reason, and work derived from it is submitted you may be penalised, even if the work was submitted without your knowledge or consent. This may apply even if your work is submitted by a third party unknown to you.
Note, you will not be penalised if your work is taken without your consent or knowledge.
For more information, read the UNSW Student Code, or contact the course account. The following penalties apply to your total mark for plagiarism:
0 for the assignment | Knowingly providing your work to anyone and it is subsequently submitted (by anyone). |
0 for the assignment | Submitting any other person's work. This includes joint work. |
0 FL for DPST1091 | Paying another person to complete work. Submitting another person's work without their consent. |