improve distance list
This commit is contained in:
parent
e26cc9b033
commit
17cda812ca
26
UI/window.py
26
UI/window.py
@ -2,6 +2,7 @@ import pygame as pg
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import random
|
import random
|
||||||
from math import hypot
|
from math import hypot
|
||||||
|
import itertools as it
|
||||||
from UI.grid import Grid, Node
|
from UI.grid import Grid, Node
|
||||||
from Logic.Apath import a_path
|
from Logic.Apath import a_path
|
||||||
|
|
||||||
@ -64,25 +65,24 @@ class Window():
|
|||||||
for point in to_collect:
|
for point in to_collect:
|
||||||
if point[0]<10 and point[1] < 10:
|
if point[0]<10 and point[1] < 10:
|
||||||
q[0].append(point)
|
q[0].append(point)
|
||||||
elif point[0]>=10 and point[1] < 10:
|
elif point[0] < 10 and point[1] >=10 :
|
||||||
q[1].append(point)
|
q[1].append(point)
|
||||||
elif point[0]<10 and point[1] >= 10:
|
elif point[0] >= 10 and point[1] < 10:
|
||||||
q[2].append(point)
|
q[2].append(point)
|
||||||
elif point[0] >= 10 and point[1] >= 10:
|
elif point[0] >= 10 and point[1] >= 10:
|
||||||
q[3].append(point)
|
q[3].append(point)
|
||||||
for ind, y in enumerate(q):
|
for ind, y in enumerate(q):
|
||||||
di = []
|
di = []
|
||||||
for x in y:
|
def dist(x,y):
|
||||||
if ind == 0:
|
return hypot(y[0]-x[0],y[1]-x[1])
|
||||||
x1 = 0
|
|
||||||
y1 = 0
|
paths = [ p for p in it.permutations(y) ]
|
||||||
else :
|
path_distances = [ sum(map(lambda x: dist(x[0],x[1]),zip(p[:-1],p[1:]))) for p in paths ]
|
||||||
x1 = 9
|
min_index = np.argmin(path_distances)
|
||||||
x2 = 9
|
|
||||||
dist = np.sqrt(pow((x[0] - x1), 2) + pow(x[1] - y1, 2))
|
print (paths[min_index], path_distances[min_index])
|
||||||
di.append(dist)
|
to_collect_sorted.extend(paths[min_index])
|
||||||
ddd ,to_collect_sorted_quarter = zip(*sorted(zip(di,y)))
|
|
||||||
to_collect_sorted.extend(to_collect_sorted_quarter)
|
|
||||||
|
|
||||||
|
|
||||||
#window init
|
#window init
|
||||||
|
Loading…
Reference in New Issue
Block a user