-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.py
113 lines (82 loc) · 1.96 KB
/
node.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import field
class Node(object):
"""description of class"""
id = None
fieldPoint = None
fieldPointType = None
edges = None
inEdges = None
outEdges = None
lastOutEdges = None
hashIndex = None
canvas = None
graphic = None
belongToPlayerID = None
numberOfPaths = None
def __init__(self):
self.edges = list()
self.inEdges = list()
self.outEdges = list()
#def __eq__(self, other):
# return id(self)==id(other)
def addEdge(self, edge):
self.edges.append(edge)
def getFirstNotUsedEdge(self):
E = next((E for E in self.edges if not E.used), None)
return(E)
def onlyOneUsedEdge(self):
mE = self.getAllUsedEdges()
if len(mE)==1:
return True
else:
return False
def getAllUsedEdges(self):
mE = [E for E in self.edges if E.used]
return(mE)
def getAllUsedOrTracedEdges(self):
mE = [E for E in self.edges if E.used or E.traced]
return(mE)
def noUsedOrTracedEdges(self):
mE = [E for E in self.edges if E.used or E.traced]
if len(mE)==0:
return(True)
else:
return(False)
def setInEdge(self, E):
self.inEdges.append(E)
def untraceInEdge(self):
self.inEdges[-1].traced = False
def deleteInEdge(self):
self.inEdges.pop()
def setOutEdgesToScan(self):
mE = [E for E in self.edges if (not E.used) and (not E.traced)]
self.outEdges.append(mE)
def deleteOutEdgesToScan(self):
self.outEdges.pop()
def getOutEdgeToScan(self):
if len(self.outEdges[-1])==0:
return(None)
E = self.outEdges[-1].pop()
return(E)
def isGoal(self):
if self.fieldPointType==field.FieldPointType.Goal:
return(True)
else:
return(False)
def isNoOutEdges(self):
if len(self.outEdges[-1])==0:
return(True)
else:
return(False)
def isOnlyOneUsedOrTracedEdge(self):
mE = [E for E in self.edges if E.used or E.traced]
if len(mE)==1:
return(True)
else:
return(False)
if __name__ == '__main__':
N1 = Node()
N2 = Node()
a = N1==N2
a = N1 in [N1, N2]
debug = 1