Homework 28 — due Friday December 7 by end of class


Descriptions of the functions are available at the end of the module functions section.

15 tile game of mandrill


Discussion

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 ) ]

ordering = canonical_ordering[ : ]

random.shuffle( ordering )

random_ordering = ordering


Module functions

Function initialize_globals( img )

global LINE_WIDTH, GRID_COLOR, TILE_DIMENSIONS, BOARD, BLACK_TILE, BLACK_TILE_SPOT

LINE_WIDTH = 4

GRID_COLOR = 'SteelBlue'

TILE_DIMENSIONS = ( img.width // 4, img.height // 4 )

BLACK_TILE = Image.new( 'RGB', TILE_DIMENSIONS, 'Black' )

BLACK_TILE_SPOT = ( 3, 3 )

BOARD = Image.new( 'RGB', ( img.width + 5*LINE_WIDTH, img.height + 5*LINE_WIDTH ), GRID_COLOR )


Function crop( img )


Function translate_spot_into_board_coordinate( g_spot )


Function translate_spot_into_image_coordinate( g_spot )


Function overlay( tile, g_spot )


Function get_image_tile( img, g_spot )

15 tile game of mandrill


Function initialize_board( img )

15 tile game of mandrill


Function scramble_board( img )

15 tile game of mandrill


Function setup( img )


Function get_board_tile( g_spot )

15 tile game of mandrill


Function inbounds( spot )


Function slide_black_tile_left()

If instead the leftward spot is out of bounds, no action is taken.


Function slide_black_tile_right()


Function slide_black_tile_down()


Function slide_black_tile_up()

 


 

 

 
   
   
   
 
  © 2019 Jim Cohoon   Resources from previous semesters are available.