-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaze.py
More file actions
94 lines (82 loc) · 2.52 KB
/
maze.py
File metadata and controls
94 lines (82 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import tkinter as tk
import tkinter.simpledialog
import D_star as DS
board = [ [None]*7 for _ in range(6) ]
press = 0
counter = 0
obstacles = []
root = tk.Tk()
def on_Return(event):
global press
global r
press += 1
if press == 1:
r = DS.DStar(goal, start, 7, 6, obstacles)
print("Running...")
path = r.initPlan()
for elem in path:
color = "blue"
event.widget.config(bg=color)
board[elem[0]][elem[1]] = color
gameframe.destroy()
redraw()
press += 1
if press == 4:
for i in range(6):
for j in range(7):
if board[i][j] == "blue":
color = "grey"
event.widget.config(bg=color)
board[i][j] = color
path = r.run2()
for e in path:
color = "blue"
event.widget.config(bg=color)
board[e[0]][e[1]] = color
gameframe.destroy()
redraw()
def on_click(i,j,event):
global counter
global goal
global start
global obstacles
if press == 0 and board[i][j] == None:
if counter == 0:
color = "green"
start = (i, j)
elif counter == 1:
color = "red"
goal = (i, j)
else:
color = "black"
obstacles.append((i, j))
counter += 1
event.widget.config(bg=color)
board[i][j] = color
gameframe.destroy()
redraw()
elif press == 2 and (board[i][j] == None or board[i][j] == "blue"):
color = "black"
obstacles.append((i, j))
event.widget.config(bg=color)
board[i][j] = color
gameframe.destroy()
redraw()
def redraw():
global gameframe
gameframe = tk.Frame(root)
gameframe.pack()
for i,row in enumerate(board):
for j,column in enumerate(row):
name = str(i)+str(j)
L = tk.Label(gameframe,text=' ',bg= "grey" if board[i][j] == None else board[i][j])
L.grid(row=i,column=j,padx='1',pady='1')
L.bind('<Button-1>',lambda e,i=i,j=j:on_click(i,j,e))
tk.messagebox.showinfo("Instructions", "Click: \n"
"1) Start \n"
"2) End \n"
"3) Click as many times for obstacles \n"
"4) Hit return when done adding obstacles to run D* star")
redraw()
root.bind('<Return>', lambda e: on_Return(e))
root.mainloop()