/*performs double and displays the result*/ void cb_doubledown(GtkWidget *widget, gpointer data) { config *c; c = (config *)data; doubledown(c->s, c->p, c->bamt, c->mamt, c->grid2); dhit(c->d, c->s, c->grid1); result(c->p, c->d, c->result, c->bamt, c->mamt); gtk_widget_show_all((GtkWidget *)c->window); }
//determines how many two eye structures there are in the go board //borrows the helper functions used in determine eyes function int determine_twoeyes_black(char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE]) { int twoeyes=0, row, column; for(row=0; row<GO_BOARD_SIZE; row++) { for(column=0; column<GO_BOARD_SIZE; column++) { if(go_board[row][column]=='+')//goes through and sees if there is a blank space { if(check_blank(row, column, go_board))//checks to see if there is an eye at that blank space { if(doubledown(row, column, go_board))//now checks to see if there is an eye close enough to the eye found { twoeyes++;//if checks true, increment twoeyes } } } } } return twoeyes/2;//returns twoeyes count. The reason we divide by two is because the twoeyes function will count a //two eye structure twice as a consequence of stepping through the array in a nested for loop }
void game() { int left=players;///for deciding if the dealer has to hit int grandgame=1; while (grandgame==1) { int first=0; srand(time(NULL)); for(var=0;var<players+1;var++)///card amounts { hands[var]=1;///reset for(var2=3;var2>=0;var2--) { hand[var][var2][13]=0;///fill hand 13's with 0 } } for(var=1;var<players+1;var++) { if (finance[var]==0) { continue;///can't play } printf("Player %d, how much would you like to bet?",var); printf(" You have %c%d available.\n",pounds,finance[var]); scanf("%d",&hand[var][0][14]); while (hand[var][0][14]>finance [var]) { printf("You do not have enough money.You have %c%d available. Please choose again\n",pounds,finance[var]); scanf("%d",&hand[var][0][14]); } finance [var]=finance [var]-hand[var][0][14]; } while(first<2) { for(var=0;var<players+1;var++) { if (hand[var][0][14]==0&&var>0) { continue; } for (var2=0;var2<hands[var];var2++) { a=hand[var][var2][13]; b=rand(); hand[var][var2][a]=pick(b);///last needs to be the card in hand being dealt hand [var][var2][13]++;///how many cards in hand } } if (firstdeal==0) { firstdeal=1; var++; } first++; } int play=1; while (play==1) { printf("\t\tDealer Cards:"); switch(hand[0][0][0]) { case 1: printf("A "); break; case 11: printf("J "); break; case 12: printf("Q "); break; case 13: printf("K "); break; default: printf("%d ",hand[0][0][0]); } printf(" ?\n\n"); var=0; var2=0; if(value()==21) { print(); printf("Dealer Blackjack!\n"); for(var=1;var<players+1;var++) { if (value()==21) { printf("Player %d has a Blackjack- Push.",var); finance[var]=finance[var]+hand[var][0][14]; hand[var][0][14]=0; } else { printf("Player %d, you lose your bet.\n",var); hand[var][0][14]=0; } hand[var][0][13]=0; } break; } for(var=1;var<players+1;var++) { printf("Player %d hand:",var); print(); } printf("\n\n"); for (var=1;var<=players;var++)//choice, not made by dealer !!!!do busts first!!!! { for (var2=0;var2<hands[var];var2++) { if (hand[var][var2][14]==0&&var>0)//skip empty hands { continue; } if (finance[var]>=hand[var][var2][14])//only can split if have enough money { left+=split();//amount of hands in play for dealer to hit } if (value()>21) { printf("player %d has 'bust' and lost his bet\n\n Funds remaining= %c%d\n",var,pounds,finance[var]); hand[var][var2][13]=0;///no cards hand[var][var2][14]=0; left--; continue; } if (value()==21&&hand[var][var2][13]==2) { printf("Player %d, you have a blackjack! ",var); if (hands[var]>1) { printf("with hand %d: ",var2); } else { ("with hand:"); } print(); finance [var]=finance[var]+hand[var][var2][14];//both bet replaced and added (following) could do in one line using precedence. finance [var]=finance[var]+hand[var][var2][14]; hand[var][var2][14]=0; left--; printf("Your total money is now %c%d\n\n",pounds,finance[var]); continue;///move on to next hand. } printf("\nPlayer %d, your cards are: ",var); print(); if (finance [var]>=hand[var][var2][14]) { printf("Do you want to 1. Hit, 2.Stand, or 3. Double-down"); } else { printf("Do you want to 1. Hit, or 2.Stand"); } if(var2>1) { printf(" with hand %d",var2+1); } printf("?\n"); scanf("%d",&hand[var][var2][12]); //switch to send off to correct function. switch (hand[var][var2][12]) { case 1: b=rand(); hit(b); print(); var2--;//so can keep hitting, i.e. the for loop. could change previous if to while, but leave for now hand[var][var2][12]=0;//allows to do this move and others break; case 2: break;//for loop moves it on. case 3: if (finance [var]>=hand[var][var2][14])//only allows if enough money { doubledown(); break; } default: printf("Invalid choice.\n"); var2--;//to replay that bit } } } var=0;//set to dealer for functions using these variables var2=0; printf("Dealer Cards"); print(); if (left>0) { while (value()<17) { a=hand[0][0][13]; b=rand(); hand[0][0][a]=pick(b); hand [0][0][13]++; } } printf("Dealer Cards"); print(); printf("Dealer hand Value = %d\n",value()); int dealertotal=value(); for (var=1;var<=players;var++)//choice, not made by dealer !!!!do busts first!!!! { for (var2=0;var2<hands[var];var2++) { if (hand[var][var2][14]==0) { continue;//to skip out already bust players. } if (dealertotal<22&&dealertotal>value()) { hand[var][var2][14]=0; printf("Bad news, player %d, you lost your bet.\n\n Your total money is now %c%d\n\n",var,pounds,finance[var]); } else if(dealertotal<22&&dealertotal==value()) { finance [var]=finance[var]+hand[var][var2][14]; hand[var][var2][14]=0; printf("Player %d, it's a push.\n\n Your total money is now %c%d\n\n",var,pounds,finance[var]); } else { finance [var]=finance[var]+hand[var][var2][14]; finance [var]=finance[var]+hand[var][var2][14]; hand[var][var2][14]=0; printf("Well done player %d! You won this hand!\n\n Your total money is now %c%d\n\n",var,pounds,finance[var]); } } } char carryon='r'; while (carryon!='y'&&carryon!='n') { printf("Do you want another game, y/n ?\n"); scanf(" %c",&carryon); if (carryon=='y') { left=players;//or else dealer will stop hitting!(also could just reposition original... var2=0; if (decks<3) { for (var2=13;var2>0;var2--)//fill the cards { cards [var2]=decks*4;//amount of cards in pack x packs } } else { for (var=1;var<14;var++)//how many cards left { var2=var2+cards[var]; } if (var2<decks*17)//aprox a third of 52 { for (var2=13;var2>0;var2--)//fill the cards { cards [var2]=decks*4;//amount of cards in pack x packs } } } play=0; } else if (carryon=='n') { exit(0); } } } } }