Don't have an account? Register now to chat, post, use our tools, and much more.
Online Users
There are 120 users online: 8 members, 92 guests and 20 bots.
Members: Ivoah, M. I. Wright.
Bots: MSN/Bing (2), MSN/Bing (3), Magpie Crawler (1), Googlebot (14).
SAX
 » Goto page 1, 2  Next
Author Message
LiquidMetal

Joined: 16 Sep 2012
Posts: 58

 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
Weregoose

Cemetech Expert

Joined: 23 Oct 2009
Posts: 520

 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
LiquidMetal

Joined: 16 Sep 2012
Posts: 58

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

Joined: 14 Mar 2005
Posts: 60683

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! 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```

_________________

LiquidMetal

Joined: 16 Sep 2012
Posts: 58

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

Joined: 14 Mar 2005
Posts: 60683

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

Joined: 16 Sep 2012
Posts: 58

 Posted: 03 Oct 2012 07:47:07 pm    Post subject: I'll try that and get back to you, thanks.
AHelper

-

Joined: 30 Jan 2011
Posts: 2266

 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 :-\_________________Cemetech's PvE server is still being hosted! RoosterTeeth's Lazer Team!
KermMartian

Joined: 14 Mar 2005
Posts: 60683

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

LiquidMetal

Joined: 16 Sep 2012
Posts: 58

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

Joined: 14 Mar 2005
Posts: 60683

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

LiquidMetal

Joined: 16 Sep 2012
Posts: 58

 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?

Guru-in-Training

Joined: 01 Dec 2010
Posts: 2497

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.

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
KermMartian

Joined: 14 Mar 2005
Posts: 60683

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

Joined: 16 Sep 2012
Posts: 58

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

Joined: 16 Sep 2012
Posts: 58

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

Joined: 14 Mar 2005
Posts: 60683

 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. I suspect a mismatch._________________
AHelper

-

Joined: 30 Jan 2011
Posts: 2266

 Posted: 10 Oct 2012 12:58:44 am    Post subject: holy nested if statements, batman!_________________Cemetech's PvE server is still being hosted! RoosterTeeth's Lazer Team!
KermMartian

Joined: 14 Mar 2005
Posts: 60683

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

_________________

LiquidMetal

Joined: 16 Sep 2012
Posts: 58

 Posted: 10 Oct 2012 06:26:54 pm    Post subject: This code had a syntax error on the first line! (emulator)
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
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.

»
 » Goto page 1, 2  Next Page 1 of 2 » All times are GMT - 5 Hours

 Jump to: Select a forum Announcements----------------Cemetech News and AnnouncementsCemetech LabsContests General Discussion----------------Technology & Calculator Open Topic-- Electronics/Hardware Development-- Calculator HardwareYour ProjectsGeneral Open Topic-- Politics & Rants-- Reviews-- Humour/Jokes Cemetech's Projects----------------Doors CS and Doors CSESourceCoderMember Features-- TI-Freak8x-- Merthsoft-- Grammer-- Super Smash Bros. Open-- MateoConLechugaOther & Upcoming Projects-- The BASIC Elite-- mobileTunes-- CALCnet 2.2-- SuggestionsProgramming the TI-83 Plus/TI-84 PlusUsing the TI-83 Plus/TI-84 PlusWebsite Programming & Design----------------General Programmingz80 & ez80 AssemblyTI-BASICCasio Prizm/FX Development & ProgrammingHP Calculator News, Projects, and SupportWebsite Markup & ScriptingGraphics1337 Programming Tips Building with Blocks----------------FreeBuild, LEGO, and Minecraft-- FreeBuild General-- Minecraft-- Suggestions & Troubleshooting-- Content & Gallery-- Servers & Activities
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-2015 Cemetech & Kerm Martian :: Page Execution Time: 0.061687 seconds.