I'm writing a snake game in TI-Basic, and every time I move I need to see if the head of the snake has hit any point in the tail. The tail is stored as a circular list-based queue, and I can add the beginning and end in constant time.
The only hard part is that I have to do something similar to this on every iteration: (S = Size of the list)
For(I,1,S)
If X=LX(I) and Y=LY(I)
Then
Disp "GAME OVER"
Return
End
End
It's a fairly short loop, but it takes forever even on a list of 10 items. I tried the sequence way:
If sum(seq(X=LX(I) and Y=LY(I),I,1,S))
...
The only other optimization I can think of is to not check values for N to N+2 (because the first part of your tail that's possible to hit is at N+3), but that just puts off the problem after 4 points, and having the game unplayable with 14 points is no better than being unplayable after 10 points.
Using assembly isn't an option because I don't have a link cable (or the desire to write assembly).