From 8bc3a72680cceb5b44189099c5e75bdd7a486bb7 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Mon, 16 Mar 2015 22:53:27 -0700 Subject: [PATCH] v6.14.3 --towards should be much better behaved --- CHANGES.txt | 3 +++ commands/run_cmd.py | 1 + tradecalc.py | 33 +++++++++++++++++++-------------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3e7437c0..48e52530 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,9 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014 ============================================================================== +v6.14.3 Mar 16 2015 +. (kfsone) "--towards" should be much better behaved + v6.14.2 Mar 15 2015 . (kfsone) Minor tweaks . (kfsone) Removed the "tradingWith" cache because its hit rate was so low diff --git a/commands/run_cmd.py b/commands/run_cmd.py index 8a017e0b..223bd9dd 100644 --- a/commands/run_cmd.py +++ b/commands/run_cmd.py @@ -1100,6 +1100,7 @@ def run(results, cmdenv, tdb): ) if routes[0].lastSystem is goalSystem: cmdenv.NOTE("Goal system reached!") + routes = routes[:1] break if not routes: diff --git a/tradecalc.py b/tradecalc.py index 92c0b4a0..a33dcc7a 100644 --- a/tradecalc.py +++ b/tradecalc.py @@ -774,10 +774,12 @@ def station_iterator(srcStation): if goalSystem: origSystem = route.firstSystem srcSystem = srcStation.system - srcGoalDist = srcSystem.distanceTo(goalSystem) - srcOrigDist = srcSystem.distanceTo(origSystem) + srcDistTo = srcSystem.distanceTo goalDistTo = goalSystem.distanceTo origDistTo = origSystem.distanceTo + srcGoalDist = srcDistTo(goalSystem) + srcOrigDist = srcDistTo(origSystem) + origGoalDist = origDistTo(goalSystem) for dest in station_iterator(srcStation): dstStation = dest.station @@ -801,25 +803,16 @@ def station_iterator(srcStation): if restrictStations: if dstStation not in restrictStations: continue - elif goalSystem: + if goalSystem: # Bias in favor of getting closer dstSys = dstStation.system if dstSys is srcSystem: if tdenv.unique: continue - elif dstSys is goalSystem: - multiplier = 99999999999 - else: + elif dstSys is not goalSystem: # Ignore jumps longer than remaining distance to goal. if dest.distLy >= srcGoalDist: continue - # Discount jumps that increase distance to goal - dstGoalDist = goalDistTo(dstSys) - if dstGoalDist >= srcGoalDist: - continue - # The closer dst is, the smaller the divider - # will be, so the larger the remainder. - multiplier /= min(dstGoalDist, 1) if tdenv.debug >= 1: tdenv.DEBUG1( @@ -841,7 +834,19 @@ def station_iterator(srcStation): # Calculate total K-lightseconds supercruise time. # This will amortize for the start/end stations - score = trade.gainCr + if goalSystem and dstSys is not goalSystem: + dstGoalDist = goalDistTo(dstSys) + # Biggest reward for shortening distance to goal + score = 5000 * origGoalDist / dstGoalDist + # bias towards bigger reductions + score += 50 * srcGoalDist / dstGoalDist + # discourage moving back towards origin + if dstSys is not origSystem: + score += 10 * (origDistTo(dstSys) - srcOrigDist) + # Gain per unit pays a small part + score += (trade.gainCr / trade.units) / 25 + else: + score = trade.gainCr if lsPenalty: # Only want 1dp cruiseKls = int(dstStation.lsFromStar / 100) / 10