I don’t really think i need to dump all of the classes into this text box, but I will if I have to. What I’m trying to cut out all of the unecessary indexes of the a list of points used during pathfinding.
In the simulator I am running, creatures will only be able to walk left, right, up, and down so the pathfinding cant use diagonal movement. (Images are below to help with what i’m talking about.)
What I mean:
I have access to the starting point when the pathfinding starts. I want a list with a clear in order path to the end point. for example: If I had the list going from point 0,0 to 3,4 it would look like
[(0,0), (1,0), (1,1), (2,1), (2,2), (2,3), (3,3), (3,4)]
if before it was all messed up like:
[(0,0), (2,2), (1,0), (1,1), (2,3), (3,3), (2,1), (2,3), (3,4), (3,5), (3,6), (2,4)]
Note: in the fixed one, all of the coordinates are adjacent to each-other.
I used random in the pathfinding so they are all different but here is an example of a list of points after running it through a repeat deleter.
[(6, 7), (6, 6), (5, 6), (2, 6), (1, 6), (3, 4), (1, 5), (2, 5), (3, 6), (4, 6), (0, 4), (0, 5), (0, 7), (0, 6), (1, 4), (2, 3), (1, 3), (2, 4), (0, 3), (4, 4), (4, 3), (4, 2), (4, 1), (3, 1), (3, 0), (2, 0), (1, 0), (0, 0)]
Here is a picture of my console:
1’s represent the points used in an example of the pathfinding, the ‘-‘s are nothing, and the target was 0,0. The green represents the points I want to keep, and the red circles the points that don’t matter and should be destroyed. the gray represents the walls that the pathfinding has to maneuver around. the start was 7,7 or the bottom right corner.
I was trying to use this function that tells you if one coordinate is adjacent to another and I’m not ruling it out as useful. In the solution something like this will probably be used to kind of lego the correct points together.
def PointIsNextToPoint(point1, point2):
x1 = point1[0]
y1 = point1[1]
x2 = point2[0]
y2 = point2[1]
return (abs(x1 - x2) == 1 and y1 == y2) or (abs(y1 - y2) == 1 and x1 == x2)
Normal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.