# [Tutor] making a number slide game

Dragonfirebane at aol.com Dragonfirebane at aol.com
Sat Aug 14 02:28:56 CEST 2004

```Hello all,

I'm trying to make a non-GUI (for now) Python representation of the handheld
tile-sliding game where there are numbered tiles from 1 to 15 in a 4 x 4
square with one empty square, the point of the game being to arrange them in order
from 1 to 15. I remember a while ago (June 2004) there was a post regarding
using sentinels to define the border of a minesweeper field
(http://mail.python.org/pipermail/tutor/2004-June/029990.html), but i didn't quite understand it
at the time and the archives only show it as a text file. I'd be grateful if
anyone'd be willing to help me out by explaining sentinels to define the edge of
a field (so that the program can check where in the field the empty space is,
and if the collected user move is next to the space w/o getting an
IndexError). The following is my code, which works up to the first move, as i have not
yet programmed the rest and don't know where to start.

####
import random
numbers = []
play = True
for i in range(1, 16):
numbers.append('%02d' % i)
while play:
ranum = random.sample(numbers, 15)
ranum.append('  ')
posit =
['1A','2A','3A','4A','1B','2B','3B','4B','1C','2C','3C','4C','1D','2D','3D','4D']
posum = dict(zip(posit, ranum))
rposm = dict(zip(ranum, posit))
field = """-------------------------------------
|        |        |        |        |
|   %s   |   %s   |   %s   |   %s   |
|        |        |        |        |
-------------------------------------
|        |        |        |        |
|   %s   |   %s   |   %s   |   %s   |
|        |        |        |        |
-------------------------------------
|        |        |        |        |
|   %s   |   %s   |   %s   |   %s   |
|        |        |        |        |
-------------------------------------
|        |        |        |        |
|   %s   |   %s   |   %s   |   %s   |
|        |        |        |        |
-------------------------------------""" % (posum['1A'], posum['2A'],
posum['3A'], posum['4A'], posum['1B'], posum['2B'], posum['3B'], posum['4B'],
posum['1C'], posum['2C'], posum['3C'], posum['4C'], posum['1D'], posum['2D'],
posum['3D'], posum['4D'])
print field
move = raw_input("Enter number of tile you wish to move: ")
if move not in (posum['4C'], posum['3D']):
move = raw_input("Please select a tile bordering the blank space: ")
else:
pass
if move == posum['4C']:
posum['4D'] = posum['4C']
posum['4C'] = '  '
if move == posum['3D']:
posum['4D'] = posum['3D']
posum['3D'] = ' '
field = """-------------------------------------
|        |        |        |        |
|   %s   |   %s   |   %s   |   %s   |
|        |        |        |        |
-------------------------------------
|        |        |        |        |
|   %s   |   %s   |   %s   |   %s   |
|        |        |        |        |
-------------------------------------
|        |        |        |        |
|   %s   |   %s   |   %s   |   %s   |
|        |        |        |        |
-------------------------------------
|        |        |        |        |
|   %s   |   %s   |   %s   |   %s   |
|        |        |        |        |
-------------------------------------""" % (posum['1A'], posum['2A'],
posum['3A'], posum['4A'], posum['1B'], posum['2B'], posum['3B'], posum['4B'],
posum['1C'], posum['2C'], posum['3C'], posum['4C'], posum['1D'], posum['2D'],
posum['3D'], posum['4D'])
print field
play = False ##until i program past the first move, so that the loop
won't continue in the first move forever
###