Homework 28 — due Friday December 7 by end of class
- Implement five functions for module support.py. The module supports the initializing and updating of a 15 tile game. The functions are:
inbounds()
slide_left()
slide_right()
slide_up()
slide_down()
Descriptions of the functions are available at the end of the module functions section.
Discussion
- The image needs to be divided into 4 x 4 equal-sized tiles with the lower-righthand corner tile missing.
- Because the image width and height are not necessarily multples of 4 in length, the right and bottoms might need to be pared.
- The sixteen tiles will be labeled using their row and columns indices:
canonical_ordering = [
( 0, 0 ), ( 1, 0 ), ( 2, 0 ), ( 3, 0 ),
( 0, 1 ), ( 1, 1 ), ( 2, 1 ), ( 3, 1 ),
( 0, 2 ), ( 1, 2 ), ( 2, 2 ), ( 3, 2 ),
( 0, 3 ), ( 1, 3 ), ( 2, 3 ), ( 3, 3 ) ]
- A random ordering of the grid locations is alse needed.
ordering = canonical_ordering[ : ]
random.shuffle( ordering )
random_ordering = ordering
- One data structure will be maintained
BOARD
— the current image of the 15 puzzle
- For every board tile there is a left, right, top, and bottom line surrounding it.
Module functions
Function initialize_globals( img )
- Initializes the global variables to appropriate values based on image
img
global LINE_WIDTH, GRID_COLOR, TILE_DIMENSIONS, BOARD, BLACK_TILE, BLACK_TILE_SPOT