English 中文(简体)
Minimalistic approach for a Snake-style game
原标题:

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
问题回答

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

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.





相关问题
Fewer connections in a Qt calculator

I m writing a simplified calculator using Qt with C++, for learning purposes. Each number is a QPushButton that uses the same slot to modify the text in a lineEdit widget being used as a display. The ...

How do I detect an operator vs. int in C using scanf?

How do I read in the following input in my RPN calculator so that it will find the operator no matter what order? 2 2+ 4 As of now my scanf only sees the first char in the string and I can only do ...

Z80 (TI-83+) stops working on CALL

Every time I assemble an application for the TI-83+ calculator (Z80 processor), it stops running at CALL. Here is an example ("Hello") — it starts running just fine, but the calculator freezes at the ...

why is this sin method returning a wrong answer?

Hey, working on some categories and I ve bumped up against a weird issue, im basically expanding on a calculator class to add some trig methods, and i am getting an incorrect value when i call the sin ...

Need a calc example for ANTLR3

I ve succesfully installed ANTLR3 on my Windows and bound it to Visual Studio, but... Could anybody show me a working example of calculator in C++/ANTLR? The same as from distrib, which is written in ...

C++ simple operations (+,-,/,*) evaluation class

I am looking for a C++ class I can incorporate into a project I am working on. the functionality I need is evaluation of string operations to numerical form: for example "2 + 3*7" should evaluate to ...

Real time price x quantity calculator

I m using ASP.NET and a Repeater control to display my data. The data I have is in stored in a List. How would I implement a simple calculator that is affected in real time? Would I have to use AJAX, ...

热门标签