-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.py
More file actions
59 lines (49 loc) · 1.75 KB
/
path.py
File metadata and controls
59 lines (49 loc) · 1.75 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
'''
class Step and Path, to store pathfinding paths
Created on 2010-09-11
@author: Artsimboldo
'''
#-----------------------------------------------------------------------------
class Step(object):
'''
classdocs
'''
#----------------------------------------------------------------------
def __init__(self, node):
'''
Constructor
'''
self.i = node.i
self.j = node.j
#-----------------------------------------------------------------------------
def __str__(self):
return "(" + str(self.i) + "," + str(self.j) + ")"
#----------------------------------------------------------------------
def __eq__(self, other):
if isinstance(other, Step):
return (self.i == other.i and self.j == other.j)
else:
return False
#----------------------------------------------------------------------
def __hash__(self):
return self.i * self.j
#-----------------------------------------------------------------------------
class Path(object):
'''
classdocs
'''
#----------------------------------------------------------------------
def __init__(self):
'''
Constructor
'''
self.steps = []
#-----------------------------------------------------------------------------
def __str__(self):
return '->'.join(step.__str__() for step in self.steps)
#----------------------------------------------------------------------
def appendStep(self, node):
self.steps.append(Step(node))
#----------------------------------------------------------------------
def prependStep(self, node):
self.steps.insert(0, Step(node))