Archived

This topic is now archived and is closed to further replies.

TI 83 programming help

This topic is 5535 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am making a poker program for my TI 83. I am done with the basic parts (hand, drawing, discarding etc.) of the game but i cannot get the program to recognize the hane. I have two variables for each of the five cards, one for the number (king queen, ace, 3, 2, etc.) and one for each suit. How can i make it recognize the hand using these vriables.

Share this post


Link to post
Share on other sites
Why would you program on a TI-83, its so primitive, and it takes like 10 minutes to load up the program because of the media...

Try a bunch of IF statements... ?


_________________________________________
"Why, why why does everyone ask ''why'' when ''how'' is so much more fun"
-Spawn 1997




[edited by - Infuscare on October 17, 2002 1:34:07 PM]

Share this post


Link to post
Share on other sites
I hate programming those blasted TIs. I highly don''t suggest making games on those things either. The program feature was really only made to provide short cuts like making a program to determine the cotangent of something for you. Or maybe if you a real genius write out the function for the inverse of a function.

Share this post


Link to post
Share on other sites
My friend once wrote a Poker game for his TI, and I think he ended up having to hard code all the permutations of possible hands and check them. It was pretty horrible, but it worked.

That being said, I think this is what I would do. I assume, since you are programming on a TI, that you are pretty new to programming, so forgive me if I tell you a bunch of stuff you already know. Also, I'm pretty rusty in basic, so you'll have to translate my pseudocode.

first, I would set up some boolean variables (true or false. by convention, 1 is true and zero is false) that describe the possible hands. for example:
TRUE=1
FALSE=ZERO
PLAYER1FLUSH=FALSE
PLAYER1STRAIGHT=FALSE

note that I did not say PLAYER1FLUSH=0. that's because computer's are good at remembering what numbers mean, and people aren't. It's the same principle as not naming variables XGB117FRXZ.

Once you have these flags, and you draw your cards, you have to set them. To do this, you need to sort the cards. this is accomplished by a series of swaps. the way to swap two variables is like this:

VARIABLE1= some value
VARIABLE2= something else

now the swap.

TEMP=VARIABLE1
VARIABLE1=VARIABLE2
VARIABLE2=TEMP

simple, huh? and yet, it wasn't till I was in college that I learned that. nobody tells me anything.

a series of these swaps with if statements should sort the hand. something like this:

IF CARD1VALUE < CARD2VALUE THEN SWAP THEM

I told you it was pseudo code. Actually, sorting is a little more complicated than this, and requires some loops. Look up how to do a bubble sort, it's the easiest. Basically, you compare adjacent cards, and if they're out of order, you swap them. every time you go through all the cards, the smallest one will end up in the right spot. Repeat, until all the cards are sorted. (note: this is not a very efficient sorting method, but with so few cards, it doesn't matter)

allright, enough of sorting. let's set some of our booleans.

let's start with the easiest: a flush.

IF CARD1SUITE=CARD2SUITE
ANDIF CARD2SUITE=CARD3SUITE
ANDIF CARD3SUITE=CARD4SUITE
ANDIF CARD4SUITE=CARD5SUITE
THEN PLAYER1FLUSH=TRUE

note that if you use arrays, this is easyer, but arrays are kinda tricky in and of themselves, so let's not worry about them.

now let's see if it's a straight (this is one of the reasons to sort the cards. otherwise, we'd have to check all the permutations, and that would be rediculous. just ask your math teacher.)

IF (CARD1VALUE-1)=CARD2VALUE
ANDIF (CARD2VALUE-1)=CARD3VALUE
ANDIF (CARD3VALUE-1)=CARD4VALUE
ANDIF (CARD4VALUE-1)=CARD5VALUE
THEN PLAYER1STRAIGHT=TRUE

now that we know whether or not it's a straight or a flush, it's easy to check and see if it's a straight flush:
IF PLAYER1STRAIGHT=TRUE
ANDIF PLAYER1FLUSH=TRUE
THEN PLAYER1STRAIGHTFLUSH=TRUE

by the by, you should do all of this, and anything else you can get away with, inside gosubs. it will make your life a lot easier. Thus, a portion of your code might look sorta like this:

START
GOSUB SORTCARDS
GOSUB RANKCARDS
END

RANKCARDS
GOSUB CHECKFLUSH
GOSUB CHECKSTRAIGHT
GOSUB CHECKSTRAIGHFLUSH
RETURN

you get the idea. once you know what kind of hand it is, then you have to compare it to the other player's hand. Since poker hands are ranked, this should be fairly easy. (note: I don't remember the poker hands too well, so bear with me. you should be able to figure out what i mean though.)

you could do something like:
IF PLAYER1STRAIGHT=TRUE THEN PLAYER1RANK=5
IF PLAYER1FLUSH=TRUE THEN PLAYER1RANK=6
IF PLAYER1STRAIGHTFLUSH=TRUE THEN PLAYER1RANK=7

actually, I just realized that this approach is a bit redundant, and has ugly magic numbers to remember. a better way might be to forget about the booleans and just set the rank when you check to see what kind of hand it is:

IF (CARD1VALUE-1)=CARD2VALUE
ANDIF (CARD2VALUE-1)=CARD3VALUE
ANDIF (CARD3VALUE-1)=CARD4VALUE
ANDIF (CARD4VALUE-1)=CARD5VALUE
THEN PLAYER1RANK=STRAIGHT

Oh well, that's the way programming is. there's always a better way. ^_^

anyway, once the players are ranked, then you just compare the ranks to find out who won!

IF PLAYER1RANK>PLAYER2RANK THEN GOSUB PLAYER1WINS
ELSEIF PLAYER2RANK>PLAYER1RANK THEN GOSUB PLAYER2WINS
ELSEIF PLAYER1RANK=PLAYER2RANK THEN GOSUB COMPAREHIGHCARDS

I hope I helped some, or at least gave you some ideas. If you stick with programming long enough you'll learn about wonderful things like functions, local variables, and objects that make things a lot easier but don't exist in basic.

PS: Poker's quite a bit trickier to program than it has any right to be. If you get really frustrated and feel like giving up, you might try to write a text adventure instead. If you play some Dungeons and Dragons and read some "Choose Your Own Adventure" books you should get a pretty good idea of how one of these could be programmed.










Why yes, I will take the "FUSE".

[edited by - Cliff_Robinson on October 18, 2002 3:22:05 AM]

[edited by - Cliff_Robinson on October 18, 2002 3:24:55 AM]

Share this post


Link to post
Share on other sites