So I'm creating a snake game for my Ti-84 plus calculator in my spare time to learn the language. I have a moving and working snake, but I've run into one problem. I have the coordinates of the snake stored in a matrix (column 1 being the X coordinates and column 2 being the Y coordinates, each row represents a new body segment top being the back and bottom being the front) I wanted to know if there is a fast way to delete the first row in the matrix and add a new row to the end. I am currently adding the new row, setting the value, swapping the first and last row, deleting the last row then swapping every row to move the first row back to the front. Thank You in advance for trying to help.
First thing I would do is set the coordiantes as this:
[x0,x1,x2,x3, ... xn]
[y0,y1,y2,y3, ... yn]->[A]
Then:

Code:

dim([A]->LDIM //The L is the list symbol

Then:

Code:

[A]^T->[A] //That's the transpose symbol

Which will give you this:
[xn, ... ,x3,x2,x1,x0]
[yn, ... ,y3,y2,y1,y0]
Then:

Code:

{2,LDIM(2)-1->dim([A]

Which will give you this:
[xn, ... ,x3,x2,x1]
[yn, ... ,y3,y2,y1]
Then:

Code:

[A]^T->[A]

Which will give you this:
[x1,x2,x3, ... xn]
[y1,y2,y3, ... yn]
Then:

Code:

dim([A]->LDIM
{2,LDIM(2)+1->dim([A]

Which will give you this:
[x1,x2,x3, ... ,xn, 0]
[y1,y2,y3, ... ,yn, 0]
Finally:

Code:

dim([A]->LDIM
X->[A](1,LDIM(2
Y->[A](2,LDIM(2

And to put it all together:

Code:

dim([A]->LDIM
[A]^T->[A]
{2,LDIM(2)-1->dim([A]
[A]^T->[A]
{2,LDIM(2)+1->dim([A]
dim([A]->LDIM
X->[A](1,LDIM(2
Y->[A](2,LDIM(2

But there is a possible way to simplify it with a For( loop of some sort, but there you go.
[/code]
Thanks for that, I'm pretty new to Ti Basic so tips and tricks like these will really help. I'll have to put it in my calculator and see if that speeds it up enough.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement