I have a big list of ingame coords(x,y) in 2D game as tuple. Example:
[(2014, 2619),(1985, 2589),(2024, 2594),(2016, 2616),(2001, 2605)]
They stored absolutly chaotical after parsing I need to sort the list by optimizing it so that starting with the first coord I go through all the points, ideally coming back in a short time.
I tried to write a sorting, but right now, instead of going to the closest point, it runs somewhere far away, and then comes back to the one that was closest before.
What i tried:
The program for automation allows you to build a route between two points. And i can see distance between them.
Made two arrays: 1 empty. 1 with coordinates.
I copied the first coordinates into the empty one and deleted it from the second one.
In the loop went through the array with coordinates and looked at the length of the route from the last element of the first array to each of the second. Where the shortest distance, put in the first array, deleting from the second.
In theory it looked reliable, but in reality it ran at the closest coordinates, then ran somewhere to the far coordinate and came back, instead of immediately approaching the closest coordinate.
