-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
43 lines (29 loc) · 1005 Bytes
/
graph.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
from vertex import Vertex
class Graph:
def __init__(self):
self.graph_dict = {}
def add_vertex(self, node):
self.graph_dict[node.value] = node
def add_edge(self, from_node, to_node, weight = 0):
self.graph_dict[from_node.value].add_edge(to_node.value, weight)
self.graph_dict[to_node.value].add_edge(from_node.value, weight)
def explore(self):
print("Exploring the graph....\n")
#FILL IN EXPLORE METHOD BELOW
def print_map(self):
print("\nMAZE LAYOUT\n")
for node_key in self.graph_dict:
print("{0} connected to...".format(node_key))
node = self.graph_dict[node_key]
for adjacent_node, weight in node.edges.items():
print("=> {0}: cost is {1}".format(adjacent_node, weight))
print("")
print("")
def build_graph():
graph = Graph()
# MAKE ROOMS INTO VERTICES BELOW...
# ADD ROOMS TO GRAPH BELOW...
# ADD EDGES BETWEEN ROOMS BELOW...
# DON'T CHANGE THIS CODE
graph.print_map()
return graph