-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMazeGraphMatrix.py
More file actions
74 lines (62 loc) · 4.75 KB
/
MazeGraphMatrix.py
File metadata and controls
74 lines (62 loc) · 4.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import WeightedGraphNode
import botCode.botCode.robomodules
class MazeGraphMatrix:
I = 'wall'
o = 'pellet'
(n, e) = ('empty space', 'empty space')
O = 'power pellet'
grid = [[I, I, I, I, I, I, I, I, I, I, I, I, e, e, e, e, e, e, e, e, e, I, I, I, I, I, I, I, I, I, I], # 0
[I, o, o, o, o, I, I, O, o, o, o, I, e, e, e, e, e, e, e, e, e, I, o, o, o, o, o, O, o, o, I],
[I, o, I, I, o, I, I, o, I, I, o, I, e, e, e, e, e, e, e, e, e, I, o, I, I, o, I, I, I, o, I],
[I, o, I, I, o, o, o, o, I, I, o, I, e, e, e, e, e, e, e, e, e, I, o, I, I, o, I, e, I, o, I],
[I, o, I, I, o, I, I, I, I, I, o, I, e, e, e, e, e, e, e, e, e, I, o, I, I, o, I, e, I, o, I],
[I, o, I, I, o, I, I, I, I, I, o, I, I, I, I, I, I, I, I, I, I, I, o, I, I, o, I, I, I, o, I], # 5
[I, o, I, I, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, I],
[I, o, I, I, I, I, I, o, I, I, o, I, I, I, I, I, e, I, I, I, I, I, I, I, I, o, I, I, I, o, I],
[I, o, I, I, I, I, I, o, I, I, o, I, I, I, I, I, e, I, I, I, I, I, I, I, I, o, I, e, I, o, I],
[I, o, I, I, o, o, o, o, I, I, o, e, e, e, e, e, e, e, e, e, I, I, o, o, o, o, I, e, I, o, I],
[I, o, I, I, o, I, I, o, I, I, o, I, I, e, I, I, I, I, I, e, I, I, o, I, I, o, I, e, I, o, I], # 10
[I, o, I, I, o, I, I, o, I, I, o, I, I, e, I, n, n, n, I, e, I, I, o, I, I, o, I, I, I, o, I],
[I, o, o, o, o, I, I, o, o, o, o, I, I, e, I, n, n, n, I, e, e, e, o, I, I, o, o, o, o, o, I],
[I, o, I, I, I, I, I, e, I, I, I, I, I, e, I, n, n, n, n, e, I, I, I, I, I, o, I, I, I, I, I],
[I, o, I, I, I, I, I, e, I, I, I, I, I, e, I, n, n, n, n, e, I, I, I, I, I, o, I, I, I, I, I],
[I, o, o, o, o, I, I, o, o, o, o, I, I, e, I, n, n, n, I, e, e, e, o, I, I, o, o, o, o, o, I], # 15
[I, o, I, I, o, I, I, o, I, I, o, I, I, e, I, n, n, n, I, e, I, I, o, I, I, o, I, I, I, o, I],
[I, o, I, I, o, I, I, o, I, I, o, I, I, e, I, I, I, I, I, e, I, I, o, I, I, o, I, e, I, o, I],
[I, o, I, I, o, o, o, o, I, I, o, e, e, e, e, e, e, e, e, e, I, I, o, o, o, o, I, e, I, o, I],
[I, o, I, I, I, I, I, o, I, I, o, I, I, I, I, I, e, I, I, I, I, I, I, I, I, o, I, e, I, o, I],
[I, o, I, I, I, I, I, o, I, I, o, I, I, I, I, I, e, I, I, I, I, I, I, I, I, o, I, I, I, o, I], # 20
[I, o, I, I, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, I],
[I, o, I, I, o, I, I, I, I, I, o, I, I, I, I, I, I, I, I, I, I, I, o, I, I, o, I, I, I, o, I],
[I, o, I, I, o, I, I, I, I, I, o, I, e, e, e, e, e, e, e, e, e, I, o, I, I, o, I, e, I, o, I],
[I, o, I, I, o, o, o, o, I, I, o, I, e, e, e, e, e, e, e, e, e, I, o, I, I, o, I, e, I, o, I],
[I, o, I, I, o, I, I, o, I, I, o, I, e, e, e, e, e, e, e, e, e, I, o, I, I, o, I, I, I, o, I], # 25
[I, o, o, o, o, I, I, O, o, o, o, I, e, e, e, e, e, e, e, e, e, I, o, o, o, o, o, O, o, o, I],
[I, I, I, I, I, I, I, I, I, I, I, I, e, e, e, e, e, e, e, e, e, I, I, I, I, I, I, I, I, I, I]]
# | | | | | | |
# 0 5 10 15 20 25 30
matrix = [[WeightedGraphNode for i in range(30)] for j in range(30)]
# in iteration, start at 1 because edges are borders
def __init__(self):
# print len(self.matrix)
for y in range(1, len(self.grid) - 1):
for x in range(1, len(self.grid[0]) - 1):
# iterate through the maze
if self.grid[y][x] == 'pellet' or self.grid[y][x] == 'power pellet':
# add pellet space to graph matrix
if self.grid[y][x] == 'pellet':
print "x: ", x, " y: ", y
self.matrix[y][x] = WeightedGraphNode.WeightedGraphNode(x, y, -1)
else:
# power pellets have a very high weight so we avoid them until we specifically seek them out
self.matrix[y][x] = WeightedGraphNode.WeightedGraphNode(x, y, 100000)
# iterate down-right; add double edges up-left of current space
# link up
if self.grid[y-1][x] == 'pellet' or self.grid[y-1][x] == 'power pellet':
self.matrix[y][x].add_edge(self.matrix[y-1][x])
# link left
if self.grid[y][x-1] == 'pellet' or self.grid[y][x-1] == 'power pellet':
self.matrix[y][x].add_edge(self.matrix[y][x-1])
def node_at(self, x, y):
print "node_at", self.matrix[y][x].__class__
return self.matrix[y][x]