I received my TI-82 STATS programmable calculator (which is in fact more of a TI-83) about two days ago - and wanted to program a Snake game with the builtin TI-BASIC language.
Although I had to find out: TI-BASIC is extremely slow. My first implementation was so slow, that it wasn't even a challenge for the player! The main bottleneck for me lies in the management of the list (array) containing the coordinates of the snake body.
I have tried two things:
myList[ N ]
to myList[ N - 1 ]
, in order to make the snake appear to be moving.This however, gets unplayable after the list gets about 4 parts long. (too slow)
This worked a bit better, but also gets too slow over time.
TL;DR / actual question:
Use a circular buffer. To elaborate:
Get an array, sufficiently big to hold the maximum snake. Establish two pointers, one for the head, one for the tail.
At the beginning, the tail would be in cell #1, the head in cell #3. As the snake moves, move the head pointer to the right and write the new coordinate. Then, if there's no food eaten, move the tail pointer to the right as well. If either of the pointers tries to go beyond the rightmost end of the array, wrap them over to the beginning.
A trick that most likely will work is instead of [ N - 1 ] do [ N - 2 ] or a higher number that way it makes up time by mathematically moving faster (you also have to adjust the size of the head to go faster
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With