diff --git a/cli.py b/cli.py index 4d72295d..5b3c36ee 100644 --- a/cli.py +++ b/cli.py @@ -28,7 +28,7 @@ def run(dst=None, stn=None, cr=None, cap=None, maxJumps=None, maxLy=None): return calc.getBestHopFrom(srcStn, withCr, capacity=cap, maxJumps=None, maxLy=None) dstStn = dst if isinstance(dst, Station) else tdb.getStation(dst) print(srcStn, dstStn, withCr, cap) - return calc.getBestTrade(srcStn, dstStn, withCr, capacity=cap) + return calc.getBestTrade(srcStn, dstStn, withCr, capacity=cap, maxJumps=maxJumps, maxLy=maxLy) def links(stn=None, maxJumps=None, maxLy=None): srcStn = stn if stn else curStation @@ -39,3 +39,32 @@ def links(stn=None, maxJumps=None, maxLy=None): srcStn = tdb.getStation(srcStn) return srcStn.stations.getDestinations(maxJumps=maxJumps, maxLy=maxLy) +def routes(maxHops=2, stn=None, cr=None, cap=None, maxJumps=None, maxLy=None, maxRoutes=1, maxJumpsPer=None): + global calc + srcStn = stn if stn else curStation + withCr = cr if cr else curCredits + routes = [ Route([srcStn], [], withCr, 0, 0) ] + lastHop = numHops - 1 + + print("From %s via %s to %s with %d credits for %d hops" % (srcStn, "None", "Any", withCr, numHops)) + + for hopNo in range(numHops): + if calc.debug: print("# Hop %d" % hopNo) + restrictTo = None + # if hopNo == 0 and viaStation: + # restrictTo = viaStation + # elif hopNo == lastHop: + # restrictTo = finalStation + # if viaStation: + # # Cull to routes that include the viaStation + # routes = [ route for route in routes if viaStation in route.route[1:] ] + routes = calc.getBestHops(routes, withCr, restrictTo=restrictTo, maxJumps=maxJumps, maxJumpsPer=maxJumpsPer, maxLy=maxLy) + + if not routes: + print("No routes match your selected criteria.") + return + + routes.sort() + + for i in range(0, min(len(routes), maxRoutes)): + print(routes[i]) diff --git a/tradecalc.py b/tradecalc.py index fec1b79d..f1bf1f78 100644 --- a/tradecalc.py +++ b/tradecalc.py @@ -125,13 +125,13 @@ def getBestHops(self, routes, credits, restrictTo=None, maxJumps=None, maxLy=Non bestToDest = {} safetyMargin = 1.0 - self.margin unique = self.unique - perJumpLimit = maxJumpsPer if maxJumpsPer > 0 else 0 + perJumpLimit = maxJumpsPer if (maxJumpsPer or 0) > 0 else 0 for route in routes: src = route.route[-1] startCr = credits + int(route.gainCr * safetyMargin) routeJumps = route.jumps jumpLimit = perJumpLimit - if maxJumps and maxJumps > 0: + if (maxJumps or 0) > 0: jumpLimit = min(maxJumps - routeJumps, perJumpLimit) if perJumpLimit > 0 else maxJumps - routeJumps if jumpLimit == 0: continue