Homework 30 — due Friday April 6 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_black_tile_left()
slide_black_tile_right()
slide_black_tile_up()
slide_black_tile_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 fifteen non-missing tiles will be labeled using their row and columns indices:
standard_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 ), ] # only 15 tiles
- A random ordering of the grid locations is alse needed.
random_ordering = standard_ordering[ : ] # make a copy of the standard
random.shuffle( random_ordering ) # and shuffle it
- 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