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:
|
if len(self.thingPos[oldPos]) == 0:
|
||||||
del self.thingPos[oldPos]
|
del self.thingPos[oldPos]
|
||||||
del self.thingNames[name]
|
del self.thingNames[name]
|
||||||
|
|
||||||
def path(self, x1, y1, x2, y2, closeEnough = True):
|
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)
|
startThing = self.getThingAtCoords(x1, y1)
|
||||||
if not closeEnough:
|
if not closeEnough:
|
||||||
if startThing and not startThing.passable:
|
if startThing and not startThing.passable:
|
||||||
return -1, [] # meaning you can't get there
|
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)
|
endPoint = self.coordsToInt(x2, y2)
|
||||||
numVertex = self.dimensions[0] * self.dimensions[1]
|
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)]
|
dist = [numVertex + 1 for i in range(numVertex)]
|
||||||
prev = [-1 for i in range(numVertex)]
|
prev = [-1 for i in range(numVertex)]
|
||||||
dist[startPoint] = 0
|
dist[startPoint] = 0
|
||||||
|
@ -617,10 +627,11 @@ The closeEnough parameter will create a path that lands beside the source if nec
|
||||||
prev[v] = u
|
prev[v] = u
|
||||||
heapq.heappush(queue, (dist[v], v))
|
heapq.heappush(queue, (dist[v], v))
|
||||||
|
|
||||||
if dist[endPoint] < numVertex + 1:
|
return dist, prev
|
||||||
return dist[endPoint], prev
|
#if dist[endPoint] < numVertex + 1:
|
||||||
else:
|
# return dist[endPoint], prev
|
||||||
return -1, [] # meaning you can't get there
|
#else:
|
||||||
|
# return -1, [] # meaning you can't get there
|
||||||
|
|
||||||
def lineOfSight(self, x1, y1, x2, y2):
|
def lineOfSight(self, x1, y1, x2, y2):
|
||||||
pass
|
pass
|
||||||
|
|
31
shell.py
31
shell.py
|
@ -20,7 +20,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301, USA.
|
# MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# Ver. 0.1.0028
|
# Ver. 0.1.0029
|
||||||
|
|
||||||
|
|
||||||
import types as _types
|
import types as _types
|
||||||
|
@ -137,6 +137,7 @@ class Shell(object):
|
||||||
else:
|
else:
|
||||||
self.handleUnknownCommand(command)
|
self.handleUnknownCommand(command)
|
||||||
self.update()
|
self.update()
|
||||||
|
self.__exit = False
|
||||||
|
|
||||||
def man(self, args):
|
def man(self, args):
|
||||||
help(self.__commands[args[0]])
|
help(self.__commands[args[0]])
|
||||||
|
@ -164,10 +165,32 @@ conventionally called args or argv"""
|
||||||
# Beyond this point are functions that are called within the main loop.
|
# Beyond this point are functions that are called within the main loop.
|
||||||
def scanInput(self):
|
def scanInput(self):
|
||||||
"""Parses input. Override this for custom input parsing, or input source."""
|
"""Parses input. Override this for custom input parsing, or input source."""
|
||||||
ret = input()
|
instr = input()
|
||||||
if ret == '':
|
if instr == '':
|
||||||
return []
|
return []
|
||||||
ret = ret.split()
|
inQuotes = False
|
||||||
|
ret = []
|
||||||
|
argStart = 0
|
||||||
|
c = 0
|
||||||
|
while c < len(instr):
|
||||||
|
if inQuotes:
|
||||||
|
if instr[c] == '"':
|
||||||
|
inQuotes = False
|
||||||
|
ret.append(instr[argStart:c])
|
||||||
|
argStart = c+1
|
||||||
|
else:
|
||||||
|
if instr[c] == '"':
|
||||||
|
inQuotes = True
|
||||||
|
if argStart != c:
|
||||||
|
ret.append(instr[argStart:c])
|
||||||
|
argStart = c+1
|
||||||
|
elif instr[c] in ' \t\n':
|
||||||
|
if argStart != c:
|
||||||
|
ret.append(instr[argStart:c])
|
||||||
|
argStart = c + 1
|
||||||
|
c += 1
|
||||||
|
if argStart != c:
|
||||||
|
ret.append(instr[argStart:c])
|
||||||
a = self.getAlias(ret[0])
|
a = self.getAlias(ret[0])
|
||||||
if a:
|
if a:
|
||||||
ret = a[:] + ret[1:]
|
ret = a[:] + ret[1:]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue