I have been working on a bunch of small programs lately (I am still fairly new to programming and don't know a whole lot about it) and I have gotten stuck on how to progress on this specific one.

My goal is to be able to have the user (or users as it's supposed to be for 1-4 players) choose a combination for three coin flips. Then, each coin flip is displayed on the screen one by one. Once a prediction is made by the repeated coin tosses, the program registers this and declares the winner.

Iv'e hit a brick wall on this one and don't really know how to move forward from here. Any help is greatly appreciated!

Code:
1→H
0→Z
ClrHome
Disp "SELECT NUMBER OF PLAYERS
Input "PLAYERS=",W
Lbl 0C



Lbl C0
IS>(Z,W-1
Goto CS
ClrHome
Output(1,9,"PLAYER
Output(1,16,Z
Repeat H=4
Output(3,4,"INPUT COIN FLIP
Output(3,20,H
Input Y
Y→⌊V(H
H+1→H
End
Goto C0
Output(3,20,




Lbl CS
0→H
ClrHome
Output(1,1,"P1:
Output(1,5,⌊V(1
Output(1,6,⌊V(2
Output(1,7,⌊V(3
randInt(0,1,54)→G
While H<26
H+1→H
⌊G(H)→L
If L=0
Then
Output(5,H,"H
Else
Output(5,H,"T
End
Pause
End
Lbl CR
H+1→H
⌊G(H)→L
If L=0
Then
Output(6,H-26,"H
Else
Output(6,H-26,"T
End
Pause
Goto CR


Note: I have been programming for the TI-84 Plus CE

Also, a second question. When I use the code editor here, or copy someones code here, I won't run on my calculator because it adds a space at the end of every line. I've had to manually delete every space to get it to run. Is there any way that I can prevent this from happening or get my calculator to run it?
So you basically want to check if a combination of 3 zeroes or ones is in the long list of the 54 coin flips?

Outside of this, I see a ton of optimizations Razz
First of all, you have the TI-84 Plus CE, which means the BASIC token toString() is available with the latest OS, so
Code:
Output(1,9,"PLAYER
Output(1,16,Z
can be
Code:
Output(1,9,"PLAYER "+toString(Z
, or something like this.
Secondly,

Code:
1->H
Repeat H=4
...
H+1->H
End
can be
Code:
For(H,1,4
, which is smaller and faster Smile
My last point is, that

Code:
While H<26
H+1→H
⌊G(H)→L
If L=0
Then
Output(5,H,"H
Else
Output(5,H,"T
End
Pause
End
Lbl CR
H+1→H
⌊G(H)→L
If L=0
Then
Output(6,H-26,"H
Else
Output(6,H-26,"T
End

can be optimised to

Code:
For(H,1,54
Output(5+int((H-1)/26),1+remainder(H,26),sub("HT",|G(H)+1,1
Pause
End

I will explain this code line by line, as it can be hard to understand Wink
You want to loop through all the coin flips, so For(H,1,54. Now, if H<27, you want to display them at line 5, and for H>26, at line 6. This is done by 5+int((H-1)/26). If H=26, it calculates 5+int(25/26) = 5+0 which is of course 5, and that is what we want. If H=27, then we calculate 5+int(26/26) which is... 6, exactly what we want! Now, for the first 26 coin flips, you want to display the outcode at column H, and if H>26, at column H-26. This is done by 1+remainder(H,26). remainder(H,26) returns the remainder of H/26, which is a number between 0 and 25, so that I why I added the "+1". The last part is to figure out what we want to display at the specific coordinates. sub("HT",|G(H)+1,1) gets the coin flip, and then selects the corresponding letter to it, which is either the "H" or the "T".

Outside the fact that this is smaller and faster, I've removed a Lbl/Goto, and I recommend you to do too, because normally a Goto/Lbl is pretty slow.

Hopefully you will understand this all, and if not, don't hesitate to ask us anything!

I also moved this to the TI-BASIC subforum, as this is the right place to ask questions about TI-BASIC.
Alpha527 wrote:

Also, a second question. When I use the code editor here, or copy someones code here, I won't run on my calculator because it adds a space at the end of every line. I've had to manually delete every space to get it to run. Is there any way that I can prevent this from happening or get my calculator to run it?



I believe someone wrote a website made to remove spaces form the end of lines in SC3, but I can't remember the website. Ask around, and see if you can get some one to tell you. I think @PT_ did it.
Just as an update, I understand what you were saying, but I was really looking for a way for the Coin Flip order to be registered by the game. However, I figured that part out now that I know a bit more about TI-Basic.

Here's the code I have now, I'd consider this a finished product besides the minor user interface changes that I want to add for a mini games program.


Code:
1→B
0→A
0→Z
ClrHome
Disp "SELECT NUMBER OF PLAYERS
Input "PLAYERS=",W
Lbl C0
1→E
0→H
1→T
If W=Z
Goto CS
ClrHome
Output(1,9,"PLAYER
Output(1,16,Z+1
Repeat E=4
Output(3,4,"INPUT COIN FLIP
Output(3,20,E
Input Y
Y→⌊V(E+3Z
E+1→E
End
Z+1→Z
Goto C0
Lbl CS
ClrHome
If W≤1
Then
2→⌊V(4
2→⌊V(5
2→⌊V(6
End
If W≤2
Then
2→⌊V(7
2→⌊V(8
2→⌊V(9
End
If W≤3
Then
2→⌊V(10
2→⌊V(11
2→⌊V(12
End
Output(1,1,"P1:
If 0=⌊V(1
Output(1,5,"H
If 1=⌊V(1
Output(1,5,"T
If 0=⌊V(2
Output(1,6,"H
If 1=⌊V(2
Output(1,6,"T
If 0=⌊V(3
Output(1,7,"H
If 1=⌊V(3
Output(1,7,"T
If W>1
Then
Output(1,20,"P2:
If 0=⌊V(4
Output(1,24,"H
If 1=⌊V(4
Output(1,24,"T
If 0=⌊V(5
Output(1,25,"H
If 1=⌊V(5
Output(1,25,"T
If 0=⌊V(6
Output(1,26,"H
If 1=⌊V(6
Output(1,26,"T
End
If W>2
Then
Output(2,1,"P3:
If 0=⌊V(7
Output(2,5,"H
If 1=⌊V(7
Output(2,5,"T
If 0=⌊V(8
Output(2,6,"H
If 1=⌊V(8
Output(2,6,"T
If 0=⌊V(9
Output(2,7,"H
If 1=⌊V(9
Output(2,7,"T
End
If W>3
Then
Output(2,20,"P4:
V(7
Output(2,24,"H
If 1=⌊V(7
Output(2,24,"T
If 0=⌊V(8
Output(2,25,"H
If 1=⌊V(8
Output(2,25,"T
If 0=⌊V(9
Output(2,26,"H
If 1=⌊V(9
Output(2,26,"T
End
randInt(0,1,54)→G
While H<26 and A=0
H+1→H
⌊G(H)→L
If L=0
Then
Output(5,H,"H
Else
Output(5,H,"T
End
If H≥3
Then
If ⌊G(H-2)=⌊V(1) and ⌊G(H-1)=⌊V(2) and ⌊G(H)=⌊V(3
Then
1→A
End
If ⌊G(H-2)=⌊V(4) and ⌊G(H-1)=⌊V(5) and ⌊G(H)=⌊V(6
Then
2→A
End
If ⌊G(H-2)=⌊V(7) and ⌊G(H-1)=⌊V(8) and ⌊G(H)=⌊V(9
Then
3→A
End
If ⌊G(H-2)=⌊V(10) and ⌊G(H-1)=⌊V(11) and ⌊G(H)=⌊V(12
Then
4→A
End
End
Pause
End

If A≠0
Then
Output(9,1,"PLAYER   WINS!!
Output(9,8,A
Pause
ClrHome
Return
End


Opinions are the program are greatly appreciated!
Alpha527 wrote:
Just as an update, I understand what you were saying, but I was really looking for a way for the Coin Flip order to be registered by the game. However, I figured that part out now that I know a bit more about TI-Basic.

Here's the code I have now, I'd consider this a finished product besides the minor user interface changes that I want to add for a mini games program.


Code:
1→B
0→A
0→Z
ClrHome
Disp "SELECT NUMBER OF PLAYERS
Input "PLAYERS=",W
Lbl C0
1→E
0→H
1→T
If W=Z
Goto CS
ClrHome
Output(1,9,"PLAYER
Output(1,16,Z+1
Repeat E=4
Output(3,4,"INPUT COIN FLIP
Output(3,20,E
Input Y
Y→⌊V(E+3Z
E+1→E
End
Z+1→Z
Goto C0
Lbl CS
ClrHome
If W≤1
Then
2→⌊V(4
2→⌊V(5
2→⌊V(6
End
If W≤2
Then
2→⌊V(7
2→⌊V(8
2→⌊V(9
End
If W≤3
Then
2→⌊V(10
2→⌊V(11
2→⌊V(12
End
Output(1,1,"P1:
If 0=⌊V(1
Output(1,5,"H
If 1=⌊V(1
Output(1,5,"T
If 0=⌊V(2
Output(1,6,"H
If 1=⌊V(2
Output(1,6,"T
If 0=⌊V(3
Output(1,7,"H
If 1=⌊V(3
Output(1,7,"T
If W>1
Then
Output(1,20,"P2:
If 0=⌊V(4
Output(1,24,"H
If 1=⌊V(4
Output(1,24,"T
If 0=⌊V(5
Output(1,25,"H
If 1=⌊V(5
Output(1,25,"T
If 0=⌊V(6
Output(1,26,"H
If 1=⌊V(6
Output(1,26,"T
End
If W>2
Then
Output(2,1,"P3:
If 0=⌊V(7
Output(2,5,"H
If 1=⌊V(7
Output(2,5,"T
If 0=⌊V(8
Output(2,6,"H
If 1=⌊V(8
Output(2,6,"T
If 0=⌊V(9
Output(2,7,"H
If 1=⌊V(9
Output(2,7,"T
End
If W>3
Then
Output(2,20,"P4:
V(7
Output(2,24,"H
If 1=⌊V(7
Output(2,24,"T
If 0=⌊V(8
Output(2,25,"H
If 1=⌊V(8
Output(2,25,"T
If 0=⌊V(9
Output(2,26,"H
If 1=⌊V(9
Output(2,26,"T
End
randInt(0,1,54)→G
While H<26 and A=0
H+1→H
⌊G(H)→L
If L=0
Then
Output(5,H,"H
Else
Output(5,H,"T
End
If H≥3
Then
If ⌊G(H-2)=⌊V(1) and ⌊G(H-1)=⌊V(2) and ⌊G(H)=⌊V(3
Then
1→A
End
If ⌊G(H-2)=⌊V(4) and ⌊G(H-1)=⌊V(5) and ⌊G(H)=⌊V(6
Then
2→A
End
If ⌊G(H-2)=⌊V(7) and ⌊G(H-1)=⌊V(8) and ⌊G(H)=⌊V(9
Then
3→A
End
If ⌊G(H-2)=⌊V(10) and ⌊G(H-1)=⌊V(11) and ⌊G(H)=⌊V(12
Then
4→A
End
End
Pause
End

If A≠0
Then
Output(9,1,"PLAYER   WINS!!
Output(9,8,A
Pause
ClrHome
Return
End


Opinions are the program are greatly appreciated!


Very good, but there are several things that could be optimized. I would recommend putting the

Code:
If 1=⌊V(a
Output(b,c,"T

where 'a','b', and 'c' are numbers with a for loop.

Anytime you have code that is mostly repetitive with small changes, I put it into a for loop. If you need any help doing this, just ask! Smile[/code]
  
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