so
writing this one with C ( as ANSI as possible )
need advice/tips/criticism
hopefully all the above
don't hold back, I'll read em all
the idea is that one day there will be ui/gui
user will choose:
table size
what hole cards he has
and
possibly
flop
turn
river
the software will then make about 10'000 rounds
and then give a percentage of wins
also,
pay attention to the random number generator
time-function will give a new srand-seed only once per second
not sure if this is random enough
the code:
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct kortti /* a card */ { int maa; /* suit 0-3 */ int arvo; /* value 0-12 */ } KORTTI; typedef struct kasi /* a holdem hand(2 cards) .. not yet in use */ { KORTTI a; KORTTI b; } KASI; typedef struct ll /* linklist for the deck of cards */ { KORTTI item; struct ll *seuraava; } LL; LL * luo_ll(void); /* create linklist eg the deck */ KORTTI * arvokortti(LL **linklist); /* pick a random card from from created by luo_ll()*/ int tuhoakortti(KORTTI *kortan,LL **linklist); /* destroys a card from the deck */ void virhe(int status); /* for serious failures and program shutdown */ void tulosta_kortti(int mode,int maa,int arvo); /* given mode(0 or 1), suit and value, will print the card in an understandable way */ float calc_odds(KORTTI *kortit,int k); /*args: player1's cards,[flop,turn,river] */ int main(void) { int k = 3; KORTTI *kortit = malloc(k*sizeof(KORTTI)); (*kortit).maa=0; (*kortit).arvo=0; (*(kortit+1)).maa=1; (*(kortit+1)).arvo=0; (*(kortit+2)).maa = 2; (*(kortit+2)).arvo = 0; float res = calc_odds(kortit,k); printf("float res = %f\n",res); return EXIT_SUCCESS; } float calc_odds(KORTTI *kortit,int k) { srand(time(NULL)); LL *ptr = 0; ptr = luo_ll(); if(ptr == 0) virhe(2); int i,t; for(i=0;i<k;++i) { t = tuhoakortti((kortit+i),&ptr); printf("destroia tulos: %d\n",t); } /* yllä olevan tuhoamisen voisi yhdistää korttien siirtoon pakasta */ /* luotavaan tietorakenteeseen eli kortit siis "siirretään" */ /* luo tietorakenne pelaajien käsille ja flop/turn/river */ /* jaa kortit muille pelaajilla ja flop/turn/river */ ptr = 0; return 3.14; } int tuhoakortti(KORTTI *kortan,LL **linklist) { int i; LL *edellinen = *linklist; *linklist = (**linklist).seuraava; for(i=0;;++i) { if( (**linklist).item.maa == (*kortan).maa && (**linklist).item.arvo == (*kortan).arvo ) break; else { edellinen = *linklist; *linklist = (**linklist).seuraava; } } (*edellinen).seuraava = (**linklist).seuraava; free(*linklist); return EXIT_SUCCESS; } KORTTI * arvokortti(LL **linklist) { int rint = ( rand() % 1000 ) + 100; int i; LL *edellinen; KORTTI *newcard = malloc(sizeof(KORTTI)); if(newcard==NULL) virhe(59); for(i=0;i<rint;++i) { edellinen = *linklist; *linklist = (**linklist).seuraava; } (*newcard).maa = (**linklist).item.maa; (*newcard).arvo = (**linklist).item.arvo; (*edellinen).seuraava = (**linklist).seuraava; free(*linklist); return newcard; } LL * luo_ll(void) { LL *eka = malloc(sizeof(LL)); if(eka == NULL) virhe(59); LL *current = NULL; current = eka; (*eka).item.maa = 0; (*eka).item.arvo = 0; int i; int maa=0; int arvo=1; for(i=0;i<51;++i) { LL *new = malloc(sizeof(LL)); if(new==NULL) virhe(59); (*new).item.maa = maa; (*new).item.arvo = arvo; current->seuraava = new; current = new; if(arvo<12) ++arvo; else { arvo=0; maa+=1; } } (*current).seuraava = eka; return eka; } void virhe(int status) { if(status==59) printf("malloc problem\n"); if(status==2) printf("linklist creation failure\n"); exit(1); } void tulosta_kortti(int mode,int maa,int arvo) /* mode 0 = short, 1=long */ { if(arvo>0&&arvo<10) { printf("%2d",arvo+1); } switch(arvo) { case 0: printf(" A"); break; case 10: printf(" J"); break; case 11: printf(" Q"); break; case 12: printf(" K"); break; } switch(maa) { case 0: if(mode==0) printf("H"); else printf(" of Hearts"); break; case 1: if(mode==0) printf("S"); else printf(" of Spades"); break; case 2: if(mode==0) printf("D"); else printf(" of Diamonds"); break; case 3: if(mode==0) printf("C"); else printf(" of Clubs"); break; } }
I have an issue with the basic strategy you are taking in your program. You would do better to understand the probabilities and expected values involved, and code against those than a random sample of 10,000 hands. In a game with 4 players there are 733,055,400 possible ways for the other 3 players to have their cards on the final round of betting. That number is higher on earlier rounds. your 10,000 random samples are not statistically significant.
hmm .. suppose I could do a few tests and see which number would be right .. I thought 10'000 would give me a reasonable accuracy .. somewhere like +-1% error .. which is enough .. I suppose I could do calculations and increase the number of rounds until the difference of odds are not meaninful anymore ..
The above was for when you have the river card, it gets worse the earlier in the process you get. To have a valid test, you would need to implement several multiple of 1,136,464,726,320 (the number when 3 cards are showing in the middle). You're looking at a minimum of 100 trillion trials to get meaningful test results.
You're correct, but to estimate the odds through trials requires performing enough trials to estimate the true odds with confidence. Since certain hands have a VERY low occurrence, relative to the number of possible hands, you will need at least as many trials as the actual number of possible results.
For comparison: There are 40 ways to get a straight flush on a 5-card poker hand. There are 2,598,960 possible 5-card poker hands (.15 in 10000 probability). On 10,000 trials, the probability of getting any straight flushes is 14%. That means there's an 86% chance that you would conclude there is 0 chance of a straight flush and a 14% chance you will conclude there is a 1 in 10000 or higher probability of getting a straight flush. Either way, the conclusion would be wrong. Note: I am producing these numbers with the computing power of a $10 calculator, so the calculations involved aren't overly arduous.
hmm
It would be interesting to see how much power there is in computers these days ..
I wonder how much time would it take to do all the trillions of possibilities
Processors are pretty fast these days so I imagine not as long you'd think
But I do see your point
There is a better way to approach probabilities in poker than to do random trials
I just don't know what it is
I might do it this way just because I'm a beginner and this way is easy enough for me![]()
Realize, too, that you're talking to a guy that taught probability/statistics![]()
Excellent
So then you know how to approach something like this .. how ?
( if it's not too complicated )
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks