In my game, I have a list of tuples (x,y) :
solution = [(36, 37), (36, 36), (36, 35), (37, 35), (38, 35), (38, 34), (38, 33), (38, 32)]
This list describes the movements the player should do to move from point (36, 37) to point (38, 32).
I want to simplify this list to the following :
opti = [(36, 37), (36, 35), (38, 35), (38, 32)]
This means I want to reduce any series of steps where x is fixed (or y is fixed) to only the first and the last step.
I'm struggling to figure out an algorithm to do this. I've been trying for more than two hours and here is what I'm currently trying to work on:
solution = [(36, 37), (36, 36), (36, 35), (37, 35), (38, 35), (38, 34), (38, 33), (38, 32)]
opti = [solution[0]]
for i in range(len(solution)):
if opti[-1][0] == solution[i][0]:
pass
elif opti[-1][1] == solution[i][1]:
pass
else:
opti.append(solution[i])
In the end opti is equal to [(36, 37), (37, 35), (38, 34)] which is not what I want.. Can someone point me to the right way to do this?