Re: ti-83 basic programming / poker
- From: "Arthur J. O'Dwyer" <ajo@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 29 Oct 2005 00:57:37 -0400 (EDT)
On Fri, 28 Oct 2005 jawon81@xxxxxxxxx wrote:
hi everyone i am in the process of programming a texas holdem game for the ti-83 graphics calculator. i am using their basic programming language.
Yay! Good for you!
so far i have been able to randomize the cards and output them to the screen, here is the basic code for what i've been able to accomplish so far:
LBL Z: randint(1,52)->a // Hole randint(1,52)->b // Cards
randint(1,52)->c randint(1,52)->d // Flop randint(1,52)->e randint(1,52)->f // Turn randint(1,52)->g // Rivers
So far so good. At some point you'll want to get rid of those superfluous closing parentheses. :)
IF a=b or a=c or a=d or a=e or a=f or a=g or b=c or b=d or b=e or b=f or b=g or c=e or c=f or c=g or d=e or d=f or d=g or e=f or e=g or f=g THEN GOTO Z ELSE
Ick! First of all, tangentially, it seems like you're not aware that
IF X:GOTO Z
is superior to
IF X:THEN:GOTO Z:END
for reasons besides simply taking less memory. Executing a GOTO inside a
block terminated by END will mess with the interpreter's stack; it will
keep expecting an END to finish the THEN block.Here's the advice you really wanted, though:
{A,B,C,D,E,F,G->L1
SortA(L1
IF (not(min(AList(L1:GOTO Zwhere 'AList(' is the "delta List" operation, option 7 under LIST->OPS.
This code says: Put all seven cards in a list, and sort them in ascending order. This puts any duplicate cards next to each other. Then,
we simply take the differences of adjacent cards; if any of the differences are zero, then we have one or more duplicate cards.
But that's really not the way you want to do it, I think. It depends on whether you want to allow card-counting or not. If not, your way is OK, if tedious --- each deal will consist of seven cards picked completely at random from the deck. But if you do, then you need some way of remembering which cards have already been dealt. The simplest solution, I think, is to code what you'd do in real life --- take the deck, shuffle it, and then pick the first seven cards. You can do that like this:
seq(I,I,1,52->L1
rand(52->L2
SortA(L2,L1Now L1 contains a random permutation of the integers between 1 and 52. Then it's just
L1(1->A
L1(2->B
...Or you could just forget about A,B,... and use the indices into L1 directly. Perhaps have a pointer D for "top of deck," like this:
1->D
// do a hand of poker
D+7->D
IF D>45:THEN
// reshuffle the deck
1->D
ENDif x=1:output(1,1,"As")
Modulo arithmetic is your friend. :)
[...]
so now the next step is for me to program the different strengths of the hands also taking into consideration all the different aspects of texas holdem poker.
now i could keep on writing the program but it will be very tiresome to program in all the different combinations of winning hands because there are so many different combinations of the 9 different hands in poker. for instance a 5c6c7c8c9c is a straight flush and so is 2c3c4c5c6c. this would probably result in about thousands of line of code and programming this is basic can become very annoying at best.
Well, it's going to involve a certain amount of tedium, because poker is a pretty arbitrary game. But you can certainly cut down the work by using the techniques I've already demonstrated. For example, to see whether the player has a flush showing, it's
0->T // no flush found yet
{A,B,C,D,E,F,G->L1
iPart(L1/13->L1 // compute the suits of the cards
IF 0=L1(5:1->T
IF 3=L1(3:1->T
IF not(T:THEN
1/(L1-1.5->L1
IF -2=L1(5:1->T
IF 2=L1(3:1->T
END
IF T:THEN
Disp "FLUSH
ELSE
Disp "NO FLUSH
ENDThis is another reason you might not want to use A,B,C,... to hold card values --- you'll want a lot of scratch variables to hold the results of
these tests.
For hands such as one pair and straight, you'll need to have the variable hold not just 0 or 1, but a number whose magnitude indicates
the strength of the hand --- two aces beats two jacks, for example. The
mapping from hands to numbers is obvious in those two cases, but it might
require some thought for a hand like full house.
hopefully when i get the program working i will be able to add graphics and even make the game networkable between other plays via the cable :D
I'd say skip the graphics. Basic is bad at graphics even for "dumb" games like Snake and Skiing, and it's a lost cause when it comes to "smart" games like poker. You'll be spending too many cycles on processing the hands to worry about drawing things to the graphics screen.
Hope this helps. Feel free to post if you get stuck; I like TI-83 programming. ;)
-Arthur .
- Follow-Ups:
- Re: ti-83 basic programming / poker
- From: jawon81
- Re: ti-83 basic programming / poker
- References:
- ti-83 basic programming / poker
- From: jawon81
- ti-83 basic programming / poker
- Prev by Date: Re: objects vs library
- Next by Date: Re: need help on divide and conquer algo
- Previous by thread: ti-83 basic programming / poker
- Next by thread: Re: ti-83 basic programming / poker
- Index(es):
Relevant Pages
|