@@ -18,7 +18,7 @@ def refreshMap():
1818 grid .create_rectangle (x * CELL_SIZE , y * CELL_SIZE , (x + 1 )* CELL_SIZE , (y + 1 )* CELL_SIZE , fill = 'black' )
1919
2020def create_path ():
21- startButton .config (state = DISABLED )
21+ startButton .config (state = DISABLED )
2222 global CELL_SIZE
2323 refreshMap ()
2424 pos1 = (random .randint (0 ,15 ), random .randint (0 ,15 ))
@@ -28,7 +28,7 @@ def create_path():
2828 while pos2 == pos1 or pos2 in OBSTACLES :
2929 pos2 = (random .randint (0 ,15 ), random .randint (0 ,15 ))
3030
31- print ("path between" , pos1 , pos2 , "length : " , end = "" )
31+ print ("path between" , pos1 , pos2 , "length : " , end = "" )
3232 x1 , y1 = pos1
3333 x2 , y2 = pos2
3434
@@ -42,19 +42,17 @@ def create_path():
4242 root .update ()
4343 time .sleep (TIME )
4444 grid .create_rectangle (x * CELL_SIZE , y * CELL_SIZE , (x + 1 )* CELL_SIZE , (y + 1 )* CELL_SIZE , fill = '#bbbbdd' )
45- root .update ()
4645 if path != - 1 :
4746 print (len (path ))
48- for cell in path :
47+ for cell in path [: - 1 ] :
4948 x , y = cell
5049 grid .create_rectangle (x * CELL_SIZE , y * CELL_SIZE , (x + 1 )* CELL_SIZE , (y + 1 )* CELL_SIZE , fill = 'blue' )
5150 else :
5251 print ("NO PATH" )
53- grid .create_rectangle (x2 * CELL_SIZE , y2 * CELL_SIZE , (x2 + 1 )* CELL_SIZE , (y2 + 1 )* CELL_SIZE , fill = 'red' )
5452 startButton .config (state = NORMAL )
5553
5654root = Tk ()
57- grid = Canvas (root , width = 16 * CELL_SIZE , height = 16 * CELL_SIZE , bg = 'white' )
55+ grid = Canvas (root , width = 16 * CELL_SIZE , height = 16 * CELL_SIZE , bg = 'white' )
5856grid .pack ()
5957OBSTACLES = []
6058for x in range (16 ):
@@ -66,6 +64,6 @@ def create_path():
6664 OBSTACLES .append ((x , y ))
6765 grid .create_rectangle (x * CELL_SIZE , y * CELL_SIZE , (x + 1 )* CELL_SIZE , (y + 1 )* CELL_SIZE , fill = 'black' )
6866
69- startButton = Button (root , text = 'start' , command = create_path )
67+ startButton = Button (root , text = 'start' , command = create_path )
7068startButton .pack ()
7169root .mainloop ()
0 commit comments