Check each value in a list in TI-Basic

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).

+3
source share
3 answers

Never Used TI-Basic ...

2D- . , . , . 2D-.

+2

:

For(I,1,S)
    If X=LX(I) and Y=LY(I)
    Then
        Disp "GAME OVER"
        Return
    End
End

:

If sum(X=LX and Y=LY)
Then
    Disp "Game Over"
    Return
End

X=LX LX, Y=LY. sum() , 1 .

+2

, , Snake, , , . , , "", .

For example, if I and J are the position of the head and tail, (F, G) is the direction of the snake, and (M, N) is food.

if Pxl-Test(I+F, J+G) #pixel in front of snake
then
if I+F=M and J+G=N
stop
end

Significantly more memory than a 2D array.

+1
source

Source: https://habr.com/ru/post/1762988/


All Articles