Connect with Facebook Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-2008, 02:18 AM
Learning Programmer
 
Join Date: Jul 2008
Location: Joensuu, Finland
Posts: 63
Rep Power: 0
denarced is an unknown quantity at this point
Question .. creating a holdem odds software .. need advice/critisism ..

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;
	}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-17-2008, 11:03 AM
WingedPanther's Avatar   
Super Moderator
 
Join Date: Jul 2006
Age: 36
Posts: 8,079
Blog Entries: 48
Rep Power: 20
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: .. creating a holdem odds software .. need advice/critisism ..

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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-17-2008, 11:28 AM
Learning Programmer
 
Join Date: Jul 2008
Location: Joensuu, Finland
Posts: 63
Rep Power: 0
denarced is an unknown quantity at this point
Default Re: .. creating a holdem odds software .. need advice/critisism ..

Quote:
Originally Posted by WingedPanther View Post
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 ..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-17-2008, 12:25 PM
WingedPanther's Avatar   
Super Moderator
 
Join Date: Jul 2006
Age: 36
Posts: 8,079
Blog Entries: 48
Rep Power: 20
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: .. creating a holdem odds software .. need advice/critisism ..

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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-17-2008, 01:39 PM
Learning Programmer
 
Join Date: Jul 2008
Location: Joensuu, Finland
Posts: 63
Rep Power: 0
denarced is an unknown quantity at this point
Default Re: .. creating a holdem odds software .. need advice/critisism ..

Quote:
Originally Posted by WingedPanther View Post
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.
hmm .. I have to disagree .. surely I don't have to know each and every possibility to know the odds ?? ..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-17-2008, 02:02 PM
WingedPanther's Avatar   
Super Moderator
 
Join Date: Jul 2006
Age: 36
Posts: 8,079
Blog Entries: 48
Rep Power: 20
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: .. creating a holdem odds software .. need advice/critisism ..

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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 10-17-2008, 03:15 PM
Learning Programmer
 
Join Date: Jul 2008
Location: Joensuu, Finland
Posts: 63
Rep Power: 0
denarced is an unknown quantity at this point
Default Re: .. creating a holdem odds software .. need advice/critisism ..

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 10-17-2008, 03:22 PM
Learning Programmer
 
Join Date: Jul 2008
Location: Joensuu, Finland
Posts: 63
Rep Power: 0
denarced is an unknown quantity at this point
Default Re: .. creating a holdem odds software .. need advice/critisism ..

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 10-17-2008, 04:13 PM
WingedPanther's Avatar   
Super Moderator
 
Join Date: Jul 2006
Age: 36
Posts: 8,079
Blog Entries: 48
Rep Power: 20
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: .. creating a holdem odds software .. need advice/critisism ..

Realize, too, that you're talking to a guy that taught probability/statistics
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 10-17-2008, 06:55 PM
Learning Programmer
 
Join Date: Jul 2008
Location: Joensuu, Finland
Posts: 63
Rep Power: 0
denarced is an unknown quantity at this point
Default Re: .. creating a holdem odds software .. need advice/critisism ..

Excellent
So then you know how to approach something like this .. how ?
( if it's not too complicated )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
c poker holdem



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Successfully Selling Your Software Jordan Tutorials 11 07-16-2008 05:25 PM
Creating Software and Graphic Interfaces Question idontknow87 General Programming 14 08-24-2007 05:35 AM


All times are GMT -5. The time now is 09:24 PM.

Freelance Jobs

XML/XSL: Need code for Book with Chapers using XML
Create an XML file for a book of your creation, and a basic CSS file that will format it to display ...
Earn: $40.00


C++/C: Simple firework cue sequencer
What I require is a rework of a simple cue sequencer. I have a piece of hardware (an Arduino boar...
Earn: $50.00


HTML/XHTML: Menu Rework - ASCIIBin
I'm placing this in the HTML/XHTML section of the Freelance site but you are not limited to HTML. Wh...
Earn: $20.00



CodeCall Goal

Goal #1: 1,000 Blogs
Goal #2: 1,000 Wiki Pages
Goal #3: 300,000 Posts
Goal #4: 20,000 Threads
Done: 30%, 23%, 55%, 75%

Ads