Added quote support for shell.py, so spaces can be put in single arguments
This commit is contained in:
parent
e96bdfaead
commit
9055d8b257
2 changed files with 47 additions and 13 deletions
29
gamemap.py
29
gamemap.py
|
@ -583,18 +583,28 @@ list of lists of tuples."""
|
|||
if len(self.thingPos[oldPos]) == 0:
|
||||
del self.thingPos[oldPos]
|
||||
del self.thingNames[name]
|
||||
|
||||
|
||||
def path(self, x1, y1, x2, y2, closeEnough = True):
|
||||
"""Uses Dijkstra's Algorithm to find the shortest path from (x1, y1) to (x2, y2)
|
||||
The closeEnough parameter will create a path that lands beside the source if necessary."""
|
||||
# first test to see that the start point is passable
|
||||
startThing = self.getThingAtCoords(x1, y1)
|
||||
if not closeEnough:
|
||||
if startThing and not startThing.passable:
|
||||
return -1, [] # meaning you can't get there
|
||||
startPoint = self.coordsToInt(x1, y1)
|
||||
dist, prev = self.dijkstra(x1, y1, closeEnough)
|
||||
endPoint = self.coordsToInt(x2, y2)
|
||||
numVertex = self.dimensions[0] * self.dimensions[1]
|
||||
if dist[endPoint] < numVertex + 1:
|
||||
return dist[endPoint], prev
|
||||
else:
|
||||
return -1, [] # meaning you can't get there
|
||||
|
||||
def dijkstra(self, x1, y1, closeEnough = True):
|
||||
"""Uses Dijkstra's Algorithm to find the shortest path from (x1, y1) to (x2, y2)
|
||||
The closeEnough parameter will create a path that lands beside the source if necessary."""
|
||||
# first test to see that the start point is passable
|
||||
startThing = self.getThingAtCoords(x1, y1)
|
||||
startPoint = self.coordsToInt(x1, y1)
|
||||
#endPoint = self.coordsToInt(x2, y2)
|
||||
numVertex = self.dimensions[0] * self.dimensions[1]
|
||||
dist = [numVertex + 1 for i in range(numVertex)]
|
||||
prev = [-1 for i in range(numVertex)]
|
||||
dist[startPoint] = 0
|
||||
|
@ -617,10 +627,11 @@ The closeEnough parameter will create a path that lands beside the source if nec
|
|||
prev[v] = u
|
||||
heapq.heappush(queue, (dist[v], v))
|
||||
|
||||
if dist[endPoint] < numVertex + 1:
|
||||
return dist[endPoint], prev
|
||||
else:
|
||||
return -1, [] # meaning you can't get there
|
||||
return dist, prev
|
||||
#if dist[endPoint] < numVertex + 1:
|
||||
# return dist[endPoint], prev
|
||||
#else:
|
||||
# return -1, [] # meaning you can't get there
|
||||
|
||||
def lineOfSight(self, x1, y1, x2, y2):
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue