Skip to content

Instantly share code, notes, and snippets.

@theraphim
Created October 27, 2015 07:42
Show Gist options
  • Save theraphim/e3aeaed7917d67594901 to your computer and use it in GitHub Desktop.
Save theraphim/e3aeaed7917d67594901 to your computer and use it in GitHub Desktop.
from math import sqrt, pow
def dist(a, b):
return sqrt(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2));
qspace = [((544, 532), (036, 633)),
((530, 528), (775, 890)),
((520, 540), (584, 621)),
((488, 538), (973, 315)),
((476, 496), (616, 412)),
((466, 514), (230, 399)),
((458, 492), (858, 18)),
((448, 504), (560, 955)),
((468, 464), (921, 610)),
((520, 514), (011, 940)),
((506, 474), (190, 92)),
((516, 466), (567, 121)),
((476, 458), (409, 774)),
((502, 460), (318, 450))]
#start = (197.8, 598.8)
#start = (39.5, 745.8)
sol = (175.2, 145.0)
#qspace_center = (500, 500)
#d = (033.3, 981.2) # (175.2, 145.0) #(277.6, 867.3)
finish = (996.0, 904.2) # (39.5, 745.8)
#finish = (175.2, 145.0)
def get_best_path(start, finish):
hs_distance = dist(start, finish)
di = hs_distance
b = None
for a in qspace:
if di > (100 + dist(a[1], finish)):
b = a
di = 100 + dist(a[1], finish)
return (di, hs_distance, b)
def get_desc(x):
return "Cost: %d, via: %s" % (x[0]/10, x[2])
#print "Destination:", finish
#print "Hyperspace travel cost:", hs_distance / 10
#if b:
# print "Quasispace travel via %s [-> %s], cost %s" % (b[0], b[1], di / 10)
rbw = [ #(039.5, 745.8),
#(283.6, 785.7),
(543.7, 827.0),
#(766.6, 866.6),
#(853.4, 879.7),
#(996.0, 904.2),
#(862.5, 700.0),
(741.6, 508.3),
(602.0, 297.9),
#(468.1, 091.6),
]
print get_desc(get_best_path((408.3, 551.3), (33.3, 981.2)))
print get_desc(get_best_path((412, 377), (593.7, 393.7)))
print get_desc(get_best_path(sol, (492.3, 029.4)))
start = sol
startf = 100
while rbw:
crbw = sorted([ (get_best_path(start, x), x) for x in rbw ], key=lambda x: x[0])
print '%s: %s' % (crbw[0][1], get_desc(crbw[0][0]))
start = crbw[0][1]
startf -= crbw[0][0][0] / 10
di = get_best_path(start, sol)
if (startf < (di[0] / 10)):
print "Out of fuel :("
break
rbw = [ x[1] for x in crbw[1:]]
#for w in crbw:
#print '%s: %s' % (w[1], get_desc(w[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment