Lab A.1: Unit testing
In this exercise we will introduce the unittest module, develop a data model for our game and start creating tests for the core logic.
In this set of exercises, we will build a python/tkinter implementation of the puzzle game known as 2048.
For research purposes, it may help to play a few rounds online.
This is a fairly complex project, so we will take our time. In each exercise we will add more functionality and capability to our code, gradually building in complexity.
The game consists of a 4 × 4 grid of tiles. Tiles are empty by default, but can contain numbers. The game starts with two randomly selected tiles set to the number 2.
The rules of the 2048 game are fairly simple:
Don’t worry if this doesn’t make complete sense right now. The details of the rules will become clear as we implement the necessary algorithms.
In this exercise we will introduce the unittest module, develop a data model for our game and start creating tests for the core logic.
OK, so we have a function that will stack the elements to the left. The next thing we will create is a function that will take the stacked elements and merge any pairs from right to left.
In this exercise we expand our toolkit to work with a fill 4×4 grid enabling moves in all directions.
In this exercise we create a rough draft of a working game and (hopefully) by the end of this session we will have our first (very basic) playable version.
In this exercise we will convert our basic playable system into a fully working implementation of the 2048 game.
In this exercise, we will add a scoring mechanism and print the score at each step when we print the grid.
In this exercise we will finally start building a GUI version of our 2048 game.
In this exercise we will make our 2048 GUI more attractive using better colours. We will also implement "game over" and "well done" messages and allow the user to restart.