I've been working on an implementation of Tetris for the calculator, written purely in TI-BASIC (for now). It includes a custom, hard-coded menu, a help-screen, high-scores, hard drops, and a pause menu. At least 90% of the current version (unstable) was coded on the calculator, and then I used the source-coder and TokenIDE for the remaining ~10%.

When I used the sourcecoder to unsubprogram the game, I had to make some changes to some of the files. The main one that has become a problem is the rotation script. The rotation script is supposed to check 1)That the rotation could fit within the dimensions of the matrix, 2) That the rotation will not intersect another block, and 3) do it if both were ok.

Current, broken, code excerpt:

Code:
If K=25

{0,0,0,0,0,0,0}->|LTPD
If |LCPD(7)<7:Then
For(I,0,2)
~|LCPD(2I+1)->|LTPD(2I+2)
|LCPD(2I+2)->|LTPD(2I+1)
End
0->R
For(I,0,2)

If A+|LTPD(2I+1)>10:Then
1->R
Else
If A+|LTPD(2I+1)<1:Then
1->R
Else
If B-|LTPD(2I+2)>20:Then
1->R
Else
If B-|LTPD(2I+2)<1:Then
1->R
Else
If [A](B-|LTPD(2I+2),A+|LTPD(2I+1):Then
1->R
End:End:End:End:End

End
For(I,0,2)
Pt-Off(~1+3(A+|LCPD(2I+1)),62-3(B-|LCPD(2I+2)),2)
End
For(I,1,6)
|LTPD(I)->|LCPD(I):End
For(I,0,2)
Pt-On(~1+3(A+|LCPD(2I+1)),62-3(B-|LCPD(2I+2)),2)
End
End

End

Note: The actual dim error does not occur here, but later, when the tetronimo tries to move down one square. The problem with this is that it allows the tetronimo to rotate so that part of the piece is off the board.


Old, working (I think - not downloaded from here and tested), subprogram code

Code:
:{0,0,0,0,0,0,0}→∟TPD
:If ∟CPD(7)<7:Then
:For(I,0,2)
:{-}∟CPD(2I+1)→∟TPD(2I+2)
:∟CPD(2I+2)→∟TPD(2I+1)
:End
:For(I,0,2)
:If A+∟TPD(2I+1)>10:Then
:Return
:End
:If A+∟TPD(2I+1)<1:Then
:Return
:End
:If B-∟TPD(2I+2)>20:Then
:Return
:End
:If B-∟TPD(2I+2)<1:Then
:Return
:End
:If [A](B-∟TPD(2I+2),A+∟TPD(2I+1):Then
:Return
:End
:End
:For(I,0,2)
:Pt-Off({-}1+3(A+∟CPD(2I+1)),62-3(B-∟CPD(2I+2)),2)
:End
:For(I,1,6)
:∟TPD(I)→∟CPD(I):End
:For(I,0,2)
:Pt-On({-}1+3(A+∟CPD(2I+1)),62-3(B-∟CPD(2I+2)),2)
:End
:End
Have you thought about using the "or" operator?

"If P=1 or P=3 or P=5" is satisfied if any one of the conditions is true.
I'm not quite sure what you mean by that. Can you clarify how you would apply that to my program?
LiquidMetal wrote:
I'm not quite sure what you mean by that. Can you clarify how you would apply that to my program?
Quick, read Chapter 3 of the book you just got! Wink Are you unfamiliar with 'and' and 'or'?


Code:
If A+|LTPD(2I+1)>10 or A+|LTPD(2I+1)<1 or B-|LTPD(2I+2)>20 or B-|LTPD(2I+2)<1 or [A](B-|LTPD(2I+2),A+|LTPD(2I+1)
1->R
I am familiar with 'and' and 'or'. Wouldn't it be more efficient to use '+'? I believe I left it the way it is in order to keep it fast: When it was using returns, it was more efficient that way, because it didn't necessarily need to test all of the possible options. Now, it doesn't necessarily help to separate them, but I'll wait for optimizations until the script works in the first place.

In the earlier code, the whole section of code would stop execution whenever any part of that code was true. I think that might be the source of the bug, that the program continues execution even if it sets R to 1, but I'm not 100% sure.
Well, you don't seem to be using R for anything. Shouldn't you have this?

Code:
If not(R:Then
For(I,0,2)
Pt-Off(~1+3(A+|LCPD(2I+1)),62-3(B-|LCPD(2I+2)),2)
End
For(I,1,6)
|LTPD(I)->|LCPD(I):End
For(I,0,2)
Pt-On(~1+3(A+|LCPD(2I+1)),62-3(B-|LCPD(2I+2)),2)
End
End
Assuming, of course, that R=0 means safe and R=1 means not safe. I'm a little confused about how this code is actually checking bounds; can you help explain, if my tip above isn't the solution?
I'll try that and get back to you, thanks.
on the topic of or, is TI-BASIC smart enough to stop calculating statements when the or is true? Will it optimize 'if 1 or 0+0+0+0+0 or -1'? I assume not, but :-\
AHelper wrote:
on the topic of or, is TI-BASIC smart enough to stop calculating statements when the or is true? Will it optimize 'if 1 or 0+0+0+0+0 or -1'? I assume not, but :-\
What you're asking is if it does short-circuiting of Boolean logic statements, to put it more formally, and to my knowledge, the answer is true. Smile
OK, I tried it, but it didn't change anything. As before, the program rotates the tetronimo off the board, and the error is generated when it tries to move down.
LiquidMetal wrote:
OK, I tried it, but it didn't change anything. As before, the program rotates the tetronimo off the board, and the error is generated when it tries to move down.
OK, then let's go back to the part where you explain how this code is supposed to work and where in it the actual rotation is performed (which presumably you want to not do if that rotation would push the tetromino off the screen).
Wait! I noticed a text file on my screen that was called DEBUG.8xp (name of temporary subprogram for debugging purposes). I loaded that onto the calculator, and now I get a syntax error instead:

Code:
{0,0,0,0,0,0,0}->|LTPD
If |LCPD(7)<7:Then
For(I,0,2)
~|LCPD(2I+1)->|LTPD(2I+2)
|LCPD(2I+2)->|LTPD(2I+1)
End
0->R
For(I,0,2)

If A+|LTPD(2I+1)>10:Then
1->R
Else
If A+|LTPD(2I+1)<1:Then
1->R
Else
If B-|LTPD(2I+2)>20:Then
1->R
Else
If B-|LTPD(2I+2)<1:Then
1->R
Else
If [A](B-|LTPD(2I+2),A+|LTPD(2I+1):Then
1->R
End:End:End:End:End

End
If not(R:Then //SYNTAX ERROR HERE WHEN ROTATING AGAINST WALL
For(I,0,2)
Pt-Off(~1+3(A+|LCPD(2I+1)),62-3(B-|LCPD(2I+2)),2)
End
For(I,1,6)
|LTPD(I)->|LCPD(I):End
For(I,0,2)
Pt-On(~1+3(A+|LCPD(2I+1)),62-3(B-|LCPD(2I+2)),2)
End
End
End


What could be the problem?
KermMartian wrote:
AHelper wrote:
on the topic of or, is TI-BASIC smart enough to stop calculating statements when the or is true? Will it optimize 'if 1 or 0+0+0+0+0 or -1'? I assume not, but :-\
What you're asking is if it does short-circuiting of Boolean logic statements, to put it more formally, and to my knowledge, the answer is true. Smile


I was curious about this when you said it last night, so I just tried it now. Not sure entirely how the parser works, but it does at least parse the tokens of an entire conditional, with no short circuit breaking before moving onto the next target line. For example, I just tried this program to confirm this:


Code:
0→A
If A=0 or A≠0 or Output(
Disp "ASDF"


Runs through the entire If statement and throws a syntax error.
Do we know that it does a one-pass execution? I've always sort of assumed it parses to the next newline or colon, then executes. I bet I could figure it out if I traced through parsing a program, but it's probably documented on WikiTI.
This 'or' logic business is distracting us. Please note where I have the syntax error, 3rd post above this one. Can someone tell me what is causing that error?
LiquidMetal wrote:
Wait! I noticed a text file on my screen that was called DEBUG.8xp (name of temporary subprogram for debugging purposes). I loaded that onto the calculator, and now I get a syntax error instead:

Code:
{0,0,0,0,0,0,0}->|LTPD
If |LCPD(7)<7:Then
For(I,0,2)
~|LCPD(2I+1)->|LTPD(2I+2)
|LCPD(2I+2)->|LTPD(2I+1)
End
0->R
For(I,0,2)

If A+|LTPD(2I+1)>10:Then
1->R
Else
If A+|LTPD(2I+1)<1:Then
1->R
Else
If B-|LTPD(2I+2)>20:Then
1->R
Else
If B-|LTPD(2I+2)<1:Then
1->R
Else
If [A](B-|LTPD(2I+2),A+|LTPD(2I+1):Then
1->R
End:End:End:End:End

End
If not(R:Then //SYNTAX ERROR HERE WHEN ROTATING AGAINST WALL
For(I,0,2)
Pt-Off(~1+3(A+|LCPD(2I+1)),62-3(B-|LCPD(2I+2)),2)
End
For(I,1,6)
|LTPD(I)->|LCPD(I):End
For(I,0,2)
Pt-On(~1+3(A+|LCPD(2I+1)),62-3(B-|LCPD(2I+2)),2)
End
End
End


What could be the problem?


+1. Scroll down in that^ code for location of syntax error.
Please convert that to use ' or 's so I don't have to break my brain trying to track eight levels of End-requiring constructs. Wink I suspect a mismatch.
holy nested if statements, batman!
AHelper wrote:
holy nested if statements, batman!
Indeed, that's why we were suggesting the use of a few ' or 's above. Smile Well, I went ahead and did it for you, and optimized out a few more bytes. How does this work?

Code:
{0,0,0,0,0,0,0->|LTPD
If |7>LCPD(7:Then
For(I,0,2
~|LCPD(2I+1)->|LTPD(2I+2
|LCPD(2I+2)->|LTPD(2I+1
End

Delvar RFor(I,0,2
If A+|LTPD(2I+1)>10 or A+|LTPD(2I+1)<1 or B-|LTPD(2I+2)>20 or B-|LTPD(2I+2)<1 or [A](B-|LTPD(2I+2),A+|LTPD(2I+1
1->R
End

If not(R:Then //SYNTAX ERROR HERE WHEN ROTATING AGAINST WALL
For(I,0,2
Pt-Off(~1+3(A+|LCPD(2I+1)),62-3(B-|LCPD(2I+2)),2)
End
For(I,1,6)
|LTPD(I)->|LCPD(I):End
For(I,0,2)
Pt-On(~1+3(A+|LCPD(2I+1)),62-3(B-|LCPD(2I+2)),2)
End
End
End
This code had a syntax error on the first line! (emulator)
  
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 2
» 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