-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.py
87 lines (61 loc) · 1.94 KB
/
Test.py
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
from Tree import Node
from queue import Queue
import re
marios = Node(5)
marios.AddChild(marios)
fileName = input("Dose onoma xarti: ")
#marios.PrintMap(fileName+".txt")
marios.ProcessMap(fileName)
a = {Node([2,5]),Node([2,3])}
print(Node([2,1]) in a)
#print(Node(2) in a.queue())
#με λένε μάριος
def RemoveDictonaryKey(d, key):
r = dict(d)
del r[key]
return r
def CreatePath(state,meta,goal):
print("Inside create path")
#print(meta)
actionList = list()
while meta[state] is not None:
#print(state.data,meta[state].data)
state = meta[state]
actionList.append(state.data)
actionList.reverse()
return actionList
def BreadthFirstSearch():
dataTable,mapPoints = marios.CreateMapDataTable(fileName)
openSet = Queue()
openSetCopy = {}
visitedNodes = set()
root,goal = Node(mapPoints['p']),mapPoints['g']
meta = {}
meta[root] = (None)
openSet.put(root)
openSetCopy[root] = None
while not openSet.empty():
subRoot = openSet.get()
openSetCopy = RemoveDictonaryKey(openSetCopy,subRoot)
if(subRoot.data==goal):
#return CreatePath()
#for i,x in meta.items():
# print(i.data,x.data)
#print(mapPoints['g'],"yolo")
#print(goal,"patatatata")
print(root.data)
print(goal)
t = CreatePath(subRoot,meta,Node(goal))
t.append(goal);
marios.PrintFinishedMap(dataTable,t)
return t
for (action,child) in marios.ClosebyDataPoints(subRoot,dataTable).items():
if(child in visitedNodes):
continue
if(child not in openSetCopy):
meta[child] = subRoot
print(child.data,subRoot.data,"abga aglias")
openSet.put(child)
openSetCopy[child]=child
visitedNodes.add(subRoot)
print(BreadthFirstSearch(),'yes')