Start on the Route Finding assignment part 0. have the parsing almost complete?
This commit is contained in:
parent
f23ca49f82
commit
39253dfe5e
2 changed files with 91 additions and 0 deletions
|
|
@ -1,4 +1,41 @@
|
|||
# Define Searcher, hSLD, SearchNode.
|
||||
class SearchNode:
|
||||
def __init__(self, label, value):
|
||||
self.label = label
|
||||
self.value = value
|
||||
|
||||
class Searcher:
|
||||
def __init__(self, mapfile):
|
||||
self.mapfile = mapfile
|
||||
# load the mapfile's structure
|
||||
with open(self.mapfile) as mapper:
|
||||
mapContents = mapper.read()
|
||||
mapContents = mapContents.split("\n")
|
||||
for mapIter in range(len(mapContents)):
|
||||
mapContents[mapIter] = mapContents[mapIter].split(", ")
|
||||
for firstDimMapIter in range(len(mapContents) - 1):
|
||||
for secondDimMapIter in range(len(mapContents[firstDimMapIter])):
|
||||
mapContents[firstDimMapIter][secondDimMapIter] = mapContents[firstDimMapIter][secondDimMapIter].strip("')(][")
|
||||
mapContents.pop(len(mapContents) - 1)
|
||||
for tupleIter in range(len(mapContents)):
|
||||
mapContents[tupleIter] = tuple(mapContents[tupleIter])
|
||||
# print(mapContents) # list of tuples
|
||||
# print(mapContents[0]) # tuple of strings (data)
|
||||
# [first node, second node, path cost, first node x, first node y, second node x, second node y]
|
||||
# 0 1 2 3 4 5 6
|
||||
# print(mapContents[0][0]) # data, string format
|
||||
# make two dictionaries of nodes, iterating through list of tuples to make note of every node's paths and locations
|
||||
nodeLoc = dict()
|
||||
nodePaths = dict()
|
||||
for nodeIter in range(len(mapContents)):
|
||||
# these node locations are fine, because they should technically be in only one place.
|
||||
nodeLoc[mapContents[nodeIter][0]] = tuple((mapContents[nodeIter][3], mapContents[nodeIter][4]))
|
||||
nodeLoc[mapContents[nodeIter][1]] = tuple((mapContents[nodeIter][5], mapContents[nodeIter][6]))
|
||||
# however, this is only taking the first node path it gets to...
|
||||
# I probably need a list instead, that gets updated if the node is not in the node's child list.
|
||||
nodePaths[mapContents[nodeIter][0]] = tuple((mapContents[nodeIter][1], mapContents[nodeIter][2]))
|
||||
print(nodeLoc)
|
||||
print(nodePaths)
|
||||
|
||||
# (b) Show your program loading in the 30-node sample file.
|
||||
s=Searcher("30node.txt")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue