Ok I'm "new" to programming so I'm really sorry if I "format"/type my programs in a difficult to read way. But anyway here's the program:
Ok I'm working on a "fun" program to try to make a poker game using C programming; I'm going to user an array of functions to impliment into the program and I just started on my first one. My program complies but does not "do" what the function I just programmed needs to do. Can anyone tell me why? I made a lot of the "used" variables global so that I wouldn't have to do pass by reference in every function with them...but the values are not storing. Let me know if you know what I'm doing wrong.Code:#include<stdio.h> #include<stdlib.h> /* Programmer: Matt Lane Date: 10/30/10 *The purpose of this program is to allow the user to play a game of heads up Texas Hold'Em with the program itself; both "players" will start with 1500 chips and will continue to play until one of the players run out. Basics of Texas Hold'Em: *Players are dealt 2 cards each; *The player on the "button" will be 2nd to get to raise/fold/check; *When it is a players turn they can either raise, check, or fold (or call if a bet has already been made); *After the first rotation of turns is completed - and both players are in the hand, the flop will be revealed; allowing the players on the button to, again, make the last move; *If both players are still in after the flop turn sets are completed, the turn will be revealed; again, "button" player goes 2nd; *If both players are still in after the turn sets are completed, the river will be revealed where the final bets will occur; *After a players loses or folds, the winning players gets all money in the pot; the program will reloop to a new hand. */ /******************************************************************************/ /************************Global Variables and Functions************************/ /******************************************************************************/ /*chip count and pot variables*/ int userchips = 1500; int programchips = 1500; int pot = 0; /*once a card is "used" the program inputs it's "value" to ensure the card isn't "resused" in the same hand before the program reloops*/ int usedcards[8] = {0,0,0,0,0,0,0,0}; /*stores the card in the hands and on the "table"*/ int userhand[2] = {0,0}; int programhand[2] = {0,0}; int table[5] = {0,0,0,0,0}; /*RNG function*/ int randint(int, int); /*set card values*/ int da = 1; int d2 = 2; int d3 = 3; int d4 = 4; int d5 = 5; int d6 = 6; int d7 = 7; int d8 = 8; int d9 = 9; int d10 = 10; int dj = 11; int dq = 12; int dk = 13; int ca = 14; int c2 = 15; int c3 = 16; int c4 = 17; int c5 = 18; int c6 = 19; int c7 = 20; int c8 = 21; int c9 = 22; int c10 = 23; int cj = 24; int cq = 25; int ck = 26; int sa = 27; int s2 = 28; int s3 = 29; int s4 = 30; int s5 = 31; int s6 = 32; int s7 = 33; int s8 = 34; int s9 = 35; int s10 = 36; int sj = 37; int sq = 38; int sk = 39; int ha = 40; int h2 = 41; int h3 = 42; int h4 = 43; int h5 = 44; int h6 = 45; int h7 = 46; int h8 = 47; int h9 = 48; int h10 = 49; int hj = 50; int hq = 51; int hk = 52; /***************************************************************************/ /*******************************MAIN FUNCTION*******************************/ /***************************************************************************/ int main () { /*"opperator set 1" functions to deal with game mechanics*/ void dealhand(); void showflop(); void showturn(); void showriver(); /*"opperator set 2" functions to deal with other game mechanics*/ int raise(); int check(); int fold(); int call(); /*"decision" functions to dictate the program's "moves"*/ int preflop_decision(); int flop_decision(); int turn_decision(); int river_decision(); /*"other" functions used in the program*/ /*function to compare the hands of each player*/ int determine_winner(); /*let the button go to another player after a given hand*/ void switchbuttonposition(); /****************TESTING dealhand function****************/ /*call function*/ dealhand(); /*outprint values*/ printf("Program's Hand: %d and %d\n\n", programhand[0], programhand[1]); printf("User's Hand: %d and %d\n\n", userhand[0], userhand[1]); printf("Used Cards: %d, %d, %d, %d\n\n", usedcards[0], usedcards[1], usedcards[2], usedcards[3]); /****************TESTING dealhand function****************/ char hold; scanf("%c", &hold); return 0; } /*****************************************************************************/ /**********************************FUNCTIONS**********************************/ /*****************************************************************************/ /*************************************************************************/ /*****************************Opperator Set 1*****************************/ /*************************************************************************/ void dealhand() { /*controls the loops giving values to the players*/ int i; /*the value is assigned a random number inside the range of the cards*/ int assigncard; /*loop set to go twice to give programhand 2 values*/ for (i = 0; i < 2; i++) { /*give assigncard a value*/ assigncard = randint(1,52); /*test it's value against values not allowed*/ if (assigncard != usedcards[0] && assigncard != usedcards[1]) { /*if test passes, assign value to hand array*/ assigncard = programhand[i]; /*make the value given not allowed again*/ usedcards[i] = assigncard; } else /*if values IS a value not allowed, restart for loop*/ continue; } /*loop set to go twice to give userhand 2 values*/ for (i = 0; i < 2; i++) { /*give assigncard a value*/ assigncard = randint(1,52); /*test it's value agaisnt values not allowed*/ if (assigncard != usedcards[0] && assigncard != usedcards[1] && assigncard != usedcards[2]) { /*if test passes, assign value to hand array*/ assigncard = userhand[i]; /*make the value given now allowed again*/ usedcards[2] = assigncard; } else /*if value IS a value not allowed, restart for loop*/ continue; } /*to ensure accuracy, re-enter all not allowed values incase a value was misplaced during the loop or (like usedcard[3]) was never even given the value through this function; these will be used later to ensure the "table" doesn't recieve the same "card" as one in the hand*/ usedcards[0] = programhand[0]; usedcards[1] = programhand[1]; usedcards[2] = userhand[0]; usedcards[3] = userhand[1]; } void showflop() { } void showturn() { } void showriver() { } /*************************************************************************/ /*****************************Opperator Set 2*****************************/ /*************************************************************************/ int raise() { return 0; } int check() { return 0; } int fold() { return 0; } int call() { return 0; } /************************************************************************/ /***************************Decision Functions***************************/ /************************************************************************/ int preflop_decision() { return 0; } int flop_decision() { return 0; } int turn_decision() { return 0; } int river_decision() { return 0; } /***********************************************************************/ /***************************"Other" Functions***************************/ /***********************************************************************/ int determine_winner() { return 0; } void switchbuttonposition() { } /*gernerates a random number to be returned to main*/ int randint(int min, int max) { if (min > max) { return max+int((min-max+1)*rand()/(RAND_MAX+1.0)); } else { return min+int((max-min+1)*rand()/(RAND_MAX+1.0)); } }
Thanks a lot,
Matt



LinkBack URL
About LinkBacks


