CSSE7030Assignment 2Semester 1, 2023CSSE1001/CSSE7030
1 Introduction
Sokoban is a simple game in which a player tries to push crates onto goal locations in a grid. In assignment 2,you will create a slightly modified text-based version of Sokoban, in which the player may also need to collectpotions in order to be able to push all crates to goal locations within an allocated number of moves. Yourimplementation will follow the Apple Model-View Controller (MVC) structure mentioned in lectures.You are required to implement a collection of classes and methods as specified in Section 5 of this document.Your program’s output must match the expected output exactly; minor differences in output (such as whitespaceor casing) will cause tests to fail, resulting in zero marks for those tests. Any changes to this document will belisted in a changelog on Blackboard, and summarized on theEdstem megathread.
2 Getting Started
Download a2.zip from Blackboard — this archive contains the necessary files to start this assignment. Onceextracted, the a2.zip archive will provide the following files / directories:a2.pyThe game engine. This is the only file you submit and modify. Do not makechangestoanyother files.a2_support.pyClasses, functions, andconstants to assist you in some parts of theassignment.maze_filesA collection of files to be used to initialize games.game_examplesA foldercontaining example output from running a full solution to the assignment.
3 Terminology & Gameplay
In Fancy Sokoban, a player appears in a grid, which is made up of tiles. Tiles may be a wall, floor, or goal.There are a number of movable entities that exist on the grid. The player (as a moveable object on the grid) isthemself an entity. Other entities include crates and various types of potions. The objective of the game isfor the player to push the crates onto the goal locations such thatevery goal tile is filled (covered by a crate).Every game has exactly as many crates as it has goals.The player has a limited number of moves available, and starts with an initial strength. Crates also have astrength value, which represents the strength required to push them.A player cannot move through a wall or through a crate. A crate cannot move through a wall or through anyother entity (including other crates). Potions are collectable entities that can be applied to increase a player’sstrength and/or number of moves remaining, thereby allowing them to complete games they may otherwise beunable to complete.At the beginning of the game, the initial game state is shown (including the grid with all entities, and playerstatistics). The user (person controlling the player)isthenrepeatedly prompted for a move. Valid moves andtheir corresponding behaviours are shown in Table 1. If a user enters anything other than these valid commandsat the move prompt, the text‘Invalid move.’should be displayed,then the game state should be displayedand the user should bereprompted for another move.Move name Behaviour
‘a’The player attempts to move left one square.
‘w’The player attempts to move up one square.
‘s’The player attempts to move down one square.
‘d’The player attempts to move right one square.
‘q’The player quits the game. The program should terminategracefully.
• Won by placing all crates on goals (or equivalently, having all goals be filled)
• Lost by running out of moves
• Quit by entering‘q’at the move prompt.
You do not need to handle informing the user if the game hasbecomeunwinnable; you may assume they willhave to quit to end the game in this case.
4 Class overview and relationships
You are required to implement a number of classes in this assignment. The class diagram in Figure 1 providesan overview of all of the classes you must implement in your assignment, and the basic relationships betweenthem. The details of these classes and theirmethods are described in depth in Section 5.You should develop the classes in the order in which they are described in Section 5, and test each one (includingon Gradescope) before moving on to the next class. Functionality marks are awarded for each class (and each
method) that work correctly. You can pass the assignment, and indeed do quite well, without implementingevery class. Conversely, you will do very poorly on the assignment if you submit an attempt at every class,where no classes work according to the description. Someclasses require significantly more time to implementthan others. For example, Tile and its subclasses will likely be substantially shorter than SokobanModel. Themarks allocated to each class are not necessarily an indication of their difficulty or the time required to completethem.
• Orange classes are classes that are provided to you in the support file.
• Green classes are abstract classes. However, you are not required to enforce the abstract nature of thegreen classes in their implementation. The purpose of this distinction is to indicate to you that you shouldonly ever instantiate the blue and orange classes in your program (though you should instantiate the greenclasses to test them before beginning work on their subclasses).
• Hollow-arrowheads indicate inheritance (i.e. the“is-a”relationship).
• Dotted arrows indicates composition (i.e. the“has-a”relationship). An arrow marked with 1-1 denotesthat each instance of the class at the base of the arrow contains exactly one instance of the class at thehead of the arrow. An arrow marked with 1-n denotes that each instance of the class at the base of thearrow may contain many instances of the class at the head of the arrow.
5 Implementation
This section outlines the classes, methods, and functions that you are required to implement as part of yourassignment. It is recommended that you implement the classes in the order in which they are described. Ensureeach class behaves as per the examples (and where possible, the Gradescope tests) before moving on to the nextclass.Goal is a type of tile that represents a goal location for a crate. Goal tiles are non-blocking, and the type
is represented by‘G’. Goal tiles can either be filled (e.g. contain a crate) or unfilled (e.g. empty, with roomfor one crate). Goal tiles start unfilled, and become filled throughout gameplay as the player pushes cratesonto them. If a goal tile is unfilled, the str and repr methods return‘G’. However, when a goal tilebecomes filled, the str and repr methods should instead return‘X’to denote that this goal tile isfilled. In addition to the regular Tile methods that the Goal must support, this class should also implement
the following methods:is_filled(self) -> bool (method)Returns True only when the goal is filled.fill(self) -> None (method)Sets this goal to be filled.Examples
>>> goal = Goal()
>>> goal.is_blocking()
False
>>> goal.get_type()
4
'G'
>>> str(goal)
'G'
>>> goal
G
>>> goal.is_filled()
False
>>> goal.fill()
>>> goal.is_filled()
True
>>> goal.get_type()
'G'
>>> str(goal)
'X'
>>> goal
X
6.Marking Breakdown
Your total grade for this assessment piece will be a combination of your functionality and style marks. For thisassignment, functionality and style have equal weighting, meaning you should be devoting at least as much timetowards proper styling of your code as you do trying to make it functional.6.2 Functionality MarkingYour program’s functionality will be marked out of a total of 6 marks. As in assignment 1, your assignmentwill be put through a series of tests and your functionality mark will be proportional to the number of testsyou pass. You will be given a subset of the functionality tests before the due date for the assignment. You mayreceive partial marks within each class for partially working methods, or for implementing only a few classes.Note that you do not need to implement the model and controller classes in order to earn a passing grade forthis assignment, provided that your attempts at earlier sectionsoftheassignment are functional, well-designed,and well-styled.You need to perform your own testing of your program to make surethatit meets all specifications given inthe assignment. Only relying on the provided tests is likely to result in your program failing in some cases andyou losing some functionality marks. Note: Functionality tests are automated, so outputs need to match exactly
what is expected.Your program must run in the Python interpreter (the IDLE environment). Partial solutions will be marked,but if there are errors in your code that cause the interpreter to fail to execute your program, you will get zerofor functionality marks. If there is a part of your code that causes the interpreter to fail, comment out the codeso that the remainder can run. Your program must run using the Python 3.11 interpreter. If it runs in anotherenvironment (e.g. Python 3.10 or PyCharm) but not in the Python 3.11 interpreter, you will get zero for thefunctionality mark.needed. Attributes should be declared clearly within the init method. Class variables are
avoided, except where they simplify program logic. Global variablesshould not be used.– Control Structures: Logic is structured simply and clearly through good use of control structures
(e.g. loops and conditional statements).6.4 Documentation RequirementsThere are a significant number of classes and contained methods you have to implement for this assignment.For each one, you must provide documentation in the form of a docstring. The onlyexception is for overriddenmethods on subclasses, as python docstrings are inherited.6.5 Assignment SubmissionThis assignment follows the same assignment submission policy as assignment 1. Please refer to the assignment1 task sheet. You must submit your assignment as a single Python file called a2.py (use this name – all lower
case), and nothing else. Your submission will be automatically run to determine the functionality mark. If yousubmit a file with a different name, the tests will fail and youwillget zero for functionality. Do not submit thea2_support.py file, or any other files. Do not submit any sort of archive file (e.g. zip, rar, 7z, etc.).6.6 PlagiarismThis assignment follows the same plagiarism policy as assignment 1. Please refer to the assignment 1 task