Class 39 — December 3

Introduce the 15 puzzle problem

The 15 puzzle — Needs problem solving by us — Let the fun begin


15 tile game of mandrill 15 tile game of mandrill 15 tile game of mandrill


Look both ways


Download


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

ordering = canonical_ordering[ : ]

random.shuffle( ordering )

random_ordering = ordering


Module functions

Function initialize_globals( img )


Function cleanup( img )

15 tile game of mandrill


Function initialize_board( img )

15 tile game of mandrill


Function scramble_board( img )

15 tile game of mandrill


Function translate_spot_into_board_coordinate( g_spot )


Function translate_spot_into_image_coordinate( g_spot )


Function overlay( tile, g_spot )

  • Gets the translation of g_spot into a board coordinate
  • Pastes tile onto the board at the appropiate

Function get_image_tile( img, g_spot )

15 tile game of mandrill


Function get_board_tile( g_spot )

15 tile game of mandrill


Function setup( img )


Function inbounds( spot )


Function slide_left()

  • Overlays the tile on the black tile spot
  • Overlays the black tile on the freed-up spot
  • The location of the black tile is updated

Function slide_right()


Function slide_down()


Function slide_up()


 


 

 

 
   
   
   
 
  © 2019 Jim Cohoon   Resources from previous semesters are available.