Code Crusher

Author: Ben Stephenson (ben.stephenson@ucalgary.ca)

Description:

This assignment asks students to implement portions of a computer-science themed variation of Candy Crush called Code Crusher. It is a match-three puzzle game where the player can swap adjacent elements on the board to form a line (horizontal or vertical) of three (or more) identical elements. When such a line is formed, the elements are eliminated (crushed) from the game board, and pieces above them fall to occupy the now empty spaces. Each completed line earns points, with more points awarded for constructing longer lines or multiple lines in the same turn. The goal of the game is to earn the required number of points before running out of turns. All of the user interface / animation code and graphics are provided to the students. The functions that the students write implement the game logic.

The actual student handout from fall 2017: PDF Word

Metadata

Summary The Code Crusher assignment has students implement the game logic for a computer science themed match three game similar to Candy Crush. The starting materials provide a polished game interface that is platform independent. Students end up with a fully functional game once they complete the game logic functions.
Audience I have used this assignment as the third of four assignments in a programming intensive CS1 course that takes an objects-late approach. It can be used whenever students are being introduced to functions and 2D lists.
Difficulty Students found this assignment to be moderately difficult because it was the first assignment where they were required to write their own functions and it was their first assignment involving lists. I gave the students between 2 and 3 weeks to complete the assignment and my impression was that this was appropriate.
Topics The assignment focuses on functions and 2D lists. Students also need to write loops and if statements which I assume they are comfortable with from prior assignments that focused on such.
Strengths Students that complete the assignment end up with a fully functional game. The provided code includes a polished user interface, including animation, which allows students to create something that looks much like the games that most students play. Students also learn the importance of writing functions to a specification because many of the functions that they write are called by the provided code. As a result, their functions must take the parameters described by the specification and return the specified result in order for their game to work correctly.
Weaknesses This assignment has students add to a substantial existing code base. The provided code runs a collection of test cases over the students' functions before the game starts so that the students are forced to correct most bugs before attempting to play the game but this does not guarantee that the student's functions are correct. While our code tries to respond to incorrect behavior in the student written code without crashing, it does not always succeed at this.

Adding to a substantial code base can be intimidating for some students.

Dependencies The user interface is built using our SimpleGraphics module, which is a wrapper for Python's standard TKInter graphics module (and is included in the materials we have provided). The provided code executes successfully with Python 3 on Windows, MacOS and Linux.
Variants We chose to provide students with the code needed to remove the game pieces when a match is made because there are actually many different cases that need to be considered for lines of 4 pieces, and lines, L-shaped groups and T-shaped groups of 5 pieces. The provided code could be reworked so that students are required to write this code to make the assignment more difficult. Similarly, students could be asked to write other provided game logic functions like determining how many blank spaces there are below a piece, how many non-blank spaces there are above a piece, etc.

Candy Crush includes many elements that are not included in our game that make the gameplay more interesting (and the game more complex to implement). One could introduce any number of these elements to increase the difficulty of the assignment, or to vary exactly what students need to do to complete it from term to term. Examples of variations that could be implemented include:

  • A different special piece could be when a line of 4 identical pieces is formed. In Candy Crush this piece clears one row or one column in the board. Adding such a piece would provide additional opportunities for students to write functions that manipulate a 2D list.
  • Block spaces could be added to the board. This would make the gameplay more interesting, and would also increase the complexity of the functions which cause the pieces to fall down into cleared space.
  • Pieces that are "locked" and must be "released" before they can be cleared by subsequent moves.
  • Pieces that alternate between two different symbols on even and odd turns.
  • Conveyor belts that move the pieces sitting on them each turn.

Starter and Completed Code:

Students were provided with this starter code: code_crusher_start.py. They also need SimpleGraphics.py and the images used by the interface which can be found in sprites.gif.

My solution can be found here: code_crusher_complete.py. To run my solution place it, SimpleGraphics.py and sprites.gif in the same folder and run it with Python 3.x.

Game Images