I write a snake game in TI-Basic, and every time I move, I need to see if the snake’s head hit anywhere in the tail. The tail is stored as a circular queue based on a list, and I can add start and end at constant time.
The only hard part is that I have to do something similar at each iteration: (S = List size)
For(I,1,S)
If X=LX(I) and Y=LY(I)
Then
Disp "GAME OVER"
Return
End
End
This is a rather short cycle, but it takes forever even in a list of 10 elements. I tried the sequence:
If sum(seq(X=LX(I) and Y=LY(I),I,1,S))
...
The only other optimization I can think of is not to check the values for N to N + 2 (because the first part of your tail that can be applied is N + 3), but it just postpones the problem after 4 points, and the game, unplayable with 14 points, no better than unplayable after 10 points.
Using an assembly is not an option because I do not have a connecting cable (or the desire to record an assembly).
source
share