So I've been messing around with the TI83+ lately in school because it is almost the end of the school year and we don't do much learning in class anymore... and I came to a quick halt in a program...
I'm dealing with a deck of cards here;
But since TIBASIC isn't like C++ and doesn't have enumerations, what do I use to create the deck?
I messed around and tried stuff like;

Code:

:{1,2,3,4,5,6,7,8,9,10,11,12,13}->LSPADE
:{1,2,3,4,5,6,7,8,9,10,11,12,13}->LHEART
:{1,2,3,4,5,6,7,8,9,10,11,12,13}->LCLUBS
:{1,2,3,4,5,6,7,8,9,10,11,12,13}->LDIMNS

and I've tried;

Code:

:{1,2,3,4,5,6,7,8.........49,50,51,52}->LDECK

but neither way seemed like it was headed in the right direction. I'm confused, and I've been around reading some BASIC tut's such as Kerm's, and the gaming based TIBASIC tut, help is much appreciated Smile
Both of those would work, depending on how you wanted to organize things, and instead of having the numbers 1-13 or 1-52 in each list, you could have 0s and 1s to indicate whether the card is or is not present (in the deck, or in someone's hand, or something).
Have you used seq(? You can find it in the LIST OPS menu.

Essentially,

seq(expression,letter variable,start,end,increment)→list

Is the same as:

:0→dim(list
:For(letter variable,start,end,increment)
:expressionlist(1+dim(list
:End

increment is optional. Also, as for the letter variable that you choose to use, while it appears to take on changes in value for the purpose of generating the list, any number that may have been stored to the letter variable beforehand is not lost. You can see this by storing π→P, running seq(P²,P,1,5), and then checking P's value afterward. In other words, don't be scared to give seq( the same variable that you otherwise need elsewhere in the program.

Cards... Why not continue to allow the integer part be representative of the card number, but let the suit be declared by the fractional part in terms of multiples of .25?

11.75 could be the Jack of Diamonds, and 1.00 the Ace of Spades.
Kerm, I just didn't trust what I was doing because it looked impractical lol.

Oooo Weregoose, I like where you are headed with the fractions. How would I incorporate that to which card is drawn.. maybe something like this?

Code:

            //Just assume I've created LDECK with numbers 1-13.
:Randint(1,13->R     //get a card number
:Randint(1,4->D         
:LDECK(R->R            //card drawn
:(.25)D->S               //get a random fractional to add to card
:R+S->C                   //get the suit matched up with the card
                          //and store the final card value as C.

Would that work? or is there a better way.
Another way you could do it is to get a random number between 1 and 52 and divide that number by 4 to get your: iPart=card number, fPart=card type.
Play that sounds good. But there's only on problem. Anything lower than 4 would come up with a number less than 1, and no matter what, the 13 (or a king) would only come up with one suit since 52 is the highest number, and when divided by 4 you would get an even 13. To get a number higher than 13 you would have to raise the limits for generation.
So maybe a random number From 4 to 56? I think we're on to something Smile
You're just used to thinking like a BASIC coder instead of most other languages, where arrays are indexed from 0 instead of 1. Therefore, if you picked a random number C = 0 to 51, for instance, iPart(C/4) would be from 0 to 12 (since C/4 is 0 to 12.75), where C=0 is an ace and C=12 is a king, and 4fPart(C/4) is 0, 1, 2, or 3; assign the suites as you see fit. Of course, you could also do C=4 to C=55 to get iPart(C/4) from 1 to 13 instead of 0 to 12, with your suites still 0 through 3.
There's no law against aces at zero and kings at 12, but either way is about equally good. I say "about" only because I can just picture a few formulas that would probably benefit byte-wise from starting at zero.

Edit: What Kerm said.
So I'm a noob Kerm? Sad haha jk.
But I was hard at work on my black jack game today in school... now I know everything in here isn't optimized yet, but I just wanted to get the actual game itself working, and then head for optimization. Here's what I've come up with so far;
P.S; I am not using Hearts, Diamonds, Spades, or Clubs, I am using, Pi symbol, +, Theta, and *.



Code:

:ClrHome
:Lbl M
:Menu("Black Jack","Play",1,"High scores",2,"Quit",3
:{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1->LDECK    //This uses boolean to test the deck for used cards
:0->P         // the players score at any point during the game
:{0->LSCORE  //the score earned at the end of a hand
:Lbl 1
:Clrhome
:Output(4,4,"you have "LSCORE
:Output(5,6,"points
:pause
:Clrhome
:Repeat Z=  //Repeats until it finds a card that hasn't been drawn
:Randint(1,52->C
:LDECK(C->Z
:end
:0->LDECK(C  //stores a 0 to the deck to state card is not in deck
:C+4->C   //adds 4 to the card value so value 1<C<13
:ipart(C/4->C  //C always stands for card
:fpart(C/4->S  //S always stands for suit
:If C>10         //In black jack all face cards are worth ten.
:Then
:10->C   //States that face cards, ie: 11,12,13 are all worth 10
:end
:C->P     //adds the cards value to the players handworth.
:Output(2,6,"------              //this is the GUI
:Output(3,5,"!      !
:Output(4,2,"------    !
:Output(5,1,"!      !    !
:Output(6,1,"!      !    !
:Output(7,1,"!      !    !
:Output(8,1,"!      !    !
:Output(5,2,C
:If S=0
:Then
:Output(7,4,"(pi symbol here
:end
:If S=.25
:Then
:Output(7,4,"*
:end
:If S=.5
:Then
:Output(7,4,"+
:end
:If S=.75
:Then
:Output(7,4,"(theta goes here
:end
:Repeat Y=1    //same process as above, draws second card though
:Randit(1,52->C
:LDECK(C->Y
:end
:0->LDECK(C
:C+4->C
:ipart(C/4->C
:fpart(C/4->S
:If C>10
:Then
:10->C
:end
:P+C->P
:Output(3,6,C
:Output(8,10,C
:If S=0
:Then
:Output(5,9,"Pi symbol here
:end
:If S=.25
:Then
:Output(5,9,"*
:end
:If S=.5
:Then
:Output(5,9,"+
:end
:If S=.75
:Then
:Output(5,9,"theta goes here
:end
:Output(1,1,"You have "P"pts,
:Output(3,13,"Hit=
:Output(4,16,"1
:Output(6,13,"Sty=
:Output(7,16,"2
:While K=0
:getkey->K
:end
:If K=1
:Then
:Repeat E=1
:Randint(1,52->C
:LDECK(C->E
:end
:0->LDECK(C
:C+4->C
:ipart(C/4->C
:If C>10
:Then
:10->C
:end
:P+C->P
:end
:If P>21
:Then
:Clrhome
:Output(4,2,"You busted!
:Output(5,2,"No points!
:end
:goto M

That's what I've got so far. I haven't started programming this into my 83 yet, I've just been jotting this down in my physics notebook lol. Anyways... How do I tell the calculator that an ace (ace in my deck comes out to the value of 1) can have the value of 1 OR 11? I don't get how that would work with the part where it checks how much score you have Sad(
So how might I let the calc know that ace could equal 1 or 11? Is that possible?
TI-BASIC is turing-complete, so ignore the question of possibility and ask about the feasibility. This is very feasible. With an ace, one would absolutely want the highest value until it would hurt them, so... Let's say that the hand is in list, and that every computation we do will involve the integer part of this variable, because we don't want to let any suit numbers get in the way of sums and (in)equalities.

First we ask, "How many aces?" We can use the equals sign to write 1=iPart(list), and the answer to this will be a list of ones and zeros showing either "true" or "false" for each element. Wrapping this with sum() will count the "trues," effectively tallying the aces.

:sum(1=iPart(list))→A

Next, what is the hand total, ignoring ace cards? That's the sum of the integers on the card numbers, minus A.

:sum(iPart(list))-A→S

Now, A is the ace count, and S is the subtotal. What is the highest possible amount that we are holding? That's 11*A+S. If that is above 21, subtract 10. Repeat this act until it's less than or equal to 21.

I'll let you figure out the code for this part. Smile

Edit: But wait! Aren't you using a different number for aces? If it's 0, you might want sum(not(iPart(list instead. Wink Also, I foresee trouble with sums, but that's something your gears will need to work on.
My jaw just hit the floor, and knowledge just hit me in the face. You rock. Smile
joshie75 wrote:
My jaw just hit the floor, and knowledge just hit me in the face. You rock. Smile
So lets see the code that you came up with based on Weregoose's jaw-dropping revelations to you! Smile
Ok, I just got back from camping this weekend, so I haven't been working on the code. With my new sunburn I have a reason to just sit around and be lazy, aka write some code. So I'll do a little bit of testing and messing around, and get back to you guys tonight Smile p.s, sorry for the semi-pointless post. Sad

EDIT: Is this a valid command?

Code:

//adds all values from the list and assigns the value to P.
:sum(LHAND->P
Yes, that's valid. You can even sum the mth–to–nth elements of list using sum(list,m,n):


Code:
:{1,7,2,9→L1
:sum(L1,3,4

= 11
Many thanks Goose, that must've been at least the 50th question you've answered of mine Smile

EDIT: Goose, may I call you Goose? I am going to combine your knowledge of sum( with my understanding of basic so I can more clearly understand the code and debug it. I think I'm going to go with something like this;

Code:

:sum(1=(LHAND))->theta
:Repeat theta=0 or P<21
:P-10->P
:theta-1->theta
:end

Won't that effectively minus off 10 for every ace as long as the score is above 21, and even if the score is still above 21 when theta = 0 (or all aces have been subtracted 10), then it will break the loop and I can send it to a screen where it tells you that that you've busted or "insert code here"?
  
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