5

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:

  • When the snake moves, update head position, then loop through the array from the tail position, and set 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)

  • Then, I tried implementing some sort of queue/deque using TI-BASIC's list manipulation features, like popping off the end and adding something at the front of the array.

This worked a bit better, but also gets too slow over time.

TL;DR / actual question:

  • Do you know a trick so the game doesn't slow down with the snake getting longer? I have seen that this is possible in other games made in TI-BASIC
AstroCB
  • 12,337
  • 20
  • 57
  • 73
Carx
  • 51
  • 2

3 Answers3

3

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.

Andriy Volkov
  • 18,653
  • 9
  • 68
  • 83
1

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

Moshe Goldberg
  • 461
  • 2
  • 15
0

A simple trick when working with lists to improve speed is to make full use of the functions provided under the LIST menu. In particular, seq can provide significant performance benefits over a for loop that accomplishes the same goal. Other functions that I find useful are cumSum and Ξ”List.

ankh-morpork
  • 1,732
  • 1
  • 19
  • 28