Skip to content

Commit

Permalink
v6.14.3 --towards should be much better behaved
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Smith committed Mar 17, 2015
1 parent 6dbbcde commit 8bc3a72
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions commands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
33 changes: 19 additions & 14 deletions tradecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 8bc3a72

Please sign in to comment.