Oct-11-2020, 02:55 AM
(This post was last modified: Oct-11-2020, 02:08 PM by deanhystad.)
This does not calculate the path distance
Once you change the distance calculation to be correct, you'll need to do the same thing when drawing the map. Either add in a line segment to return to start, or you could create a polygon.
You have a lot of duplicate code and some has errors. Clean it up so each block of code only appears once. The code that generates the map should not be in the main body and in the changeR() and in the doOverAgain(). It should appear only once, and if you need to use it multiple places it should be a function that is called from multiple places. To understand what you are doing and where you went wrong, I edited your code and got it to run. With lots of comments it is still only 80 lines long and could be much shorter.[/i][/i]
totalD=0 for i,j in zip(path[:4], path[1:]): totalD+=distance(x[i]-2,y[i]-2,x[j]+2,y[j]+2)This almost works if the path has 5 points, but it does not work at all for a different number of points. It also doesn't add in the distance from the last point back to the starting point. And why are you subtracting and adding 2? Was this copied from the code that draws the dots? There is no need for the offset. You should also consider using numbers instead of dots so you can tell where the route starts and ends.
Once you change the distance calculation to be correct, you'll need to do the same thing when drawing the map. Either add in a line segment to return to start, or you could create a polygon.
You have a lot of duplicate code and some has errors. Clean it up so each block of code only appears once. The code that generates the map should not be in the main body and in the changeR() and in the doOverAgain(). It should appear only once, and if you need to use it multiple places it should be a function that is called from multiple places. To understand what you are doing and where you went wrong, I edited your code and got it to run. With lots of comments it is still only 80 lines long and could be much shorter.[/i][/i]