CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 111 users online: 1 member, 99 guests and 11 bots.
Members: chickendude.
Bots: MSN/Bing (2), Spinn3r (1), Magpie Crawler (1), Magpie Crawler (2), Googlebot (5).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
    Goto page 1, 2  Next
View previous topic :: View next topic  
Author Message
LiquidMetal


Advanced Newbie


Joined: 16 Sep 2012
Posts: 57

Posted: 03 Oct 2012 01:20:37 pm    Post subject: Tetris 3.0

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


Last edited by LiquidMetal on 03 Oct 2012 01:32:05 pm; edited 1 time in total
Back to top
Weregoose


Cemetech Expert


Joined: 23 Oct 2009
Posts: 519

Posted: 03 Oct 2012 01:28:34 pm    Post subject:

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.
_________________
Common Errors in English How To Ask Questions The Smart Way
Back to top
LiquidMetal


Advanced Newbie


Joined: 16 Sep 2012
Posts: 57

Posted: 03 Oct 2012 01:30:31 pm    Post subject:

I'm not quite sure what you mean by that. Can you clarify how you would apply that to my program?
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 59485

Posted: 03 Oct 2012 01:32:29 pm    Post subject:

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

_________________


Back to top
LiquidMetal


Advanced Newbie


Joined: 16 Sep 2012
Posts: 57

Posted: 03 Oct 2012 01:38:46 pm    Post subject:

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.
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 59485

Posted: 03 Oct 2012 06:31:10 pm    Post subject:

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?
_________________


Back to top
LiquidMetal


Advanced Newbie


Joined: 16 Sep 2012
Posts: 57

Posted: 03 Oct 2012 07:47:07 pm    Post subject:

I'll try that and get back to you, thanks.
Back to top
AHelper


R.I.P. TinyBlub 10/1/14


Joined: 30 Jan 2011
Posts: 2154
Location: WHAT

Posted: 03 Oct 2012 08:31:13 pm    Post subject:

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 :-\
_________________
ᴥ Doggy! Jenkins, it will build your life!

<BrandonW> "You don't even want to know what TI Connect does when it's just detecting your calculator...It ACTUALLY ERASES THE SWAP SECTOR on every communication attempt...EVERY SINGLE ATTEMPT...Yes, TI Connect will kill your calculator..What do I have to do to get your attention?!....Such a bloated protocol."
< KermM> Dearest TI-Connect: Please stop being such an inveterate piece of garbage. Love, Christopher.
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 59485

Posted: 03 Oct 2012 08:38:39 pm    Post subject:

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
_________________


Back to top
LiquidMetal


Advanced Newbie


Joined: 16 Sep 2012
Posts: 57

Posted: 04 Oct 2012 03:35:01 pm    Post subject:

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.
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 59485

Posted: 04 Oct 2012 05:41:51 pm    Post subject:

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).
_________________


Back to top
LiquidMetal


Advanced Newbie


Joined: 16 Sep 2012
Posts: 57

Posted: 04 Oct 2012 06:02:59 pm    Post subject:

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?
Back to top
Ashbad


Guru-in-Training


Joined: 01 Dec 2010
Posts: 2498

Posted: 04 Oct 2012 06:07:13 pm    Post subject:

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.
_________________
R O F L M A O
O
F
L
M
A
O
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 59485

Posted: 04 Oct 2012 06:41:35 pm    Post subject:

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.
_________________


Back to top
LiquidMetal


Advanced Newbie


Joined: 16 Sep 2012
Posts: 57

Posted: 05 Oct 2012 12:18:18 am    Post subject:

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?
Back to top
LiquidMetal


Advanced Newbie


Joined: 16 Sep 2012
Posts: 57

Posted: 09 Oct 2012 11:06:29 pm    Post subject:

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.
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 59485

Posted: 10 Oct 2012 12:52:44 am    Post subject:

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.
_________________


Back to top
AHelper


R.I.P. TinyBlub 10/1/14


Joined: 30 Jan 2011
Posts: 2154
Location: WHAT

Posted: 10 Oct 2012 12:58:44 am    Post subject:

holy nested if statements, batman!
_________________
ᴥ Doggy! Jenkins, it will build your life!

<BrandonW> "You don't even want to know what TI Connect does when it's just detecting your calculator...It ACTUALLY ERASES THE SWAP SECTOR on every communication attempt...EVERY SINGLE ATTEMPT...Yes, TI Connect will kill your calculator..What do I have to do to get your attention?!....Such a bloated protocol."
< KermM> Dearest TI-Connect: Please stop being such an inveterate piece of garbage. Love, Christopher.
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 59485

Posted: 10 Oct 2012 09:53:18 am    Post subject:

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

_________________


Back to top
LiquidMetal


Advanced Newbie


Joined: 16 Sep 2012
Posts: 57

Posted: 10 Oct 2012 06:26:54 pm    Post subject:

This code had a syntax error on the first line! (emulator)
Back to top
Display posts from previous:   
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
    Goto page 1, 2  Next
View previous topic :: View next topic  
Page 1 of 2 All times are GMT - 5 Hours

 
Jump to:  
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

© Copyright 2000-2014 Cemetech & Kerm Martian :: Page Execution Time: 0.047714 seconds.