Error with analyzing hand function with my poker game C code -


i have code printing out cards , hands when time analyze hand function nothing , i'm not sure go here or i'm missing fresh pair of eyes!

#include <stdio.h> #include <stdlib.h> #include <time.h>  #define suits 4 // suits of cards #define faces 13 // 2 / ace #define available 0 // card not drawn deck #define taken 1 // card has been drawn deck #define size 5 #define true 1 #define false 0   //declarations of structs void dealacard(char *suits[], char *faces[], int deck[][faces]); void dealahand(char *suits[], char *faces[], int deck[][faces]);  //declaration of analyze function void analyzehand(int suitsinhand[], int facesinhand[]);   typedef int bool; bool straight, flush, four, three; int pairs;  int main(void) {      //character array of suits     char *suits[4] = {"hearts", "diamonds", "spades", "clubs"};      //character arrau of face cards     char *faces[13] = {"two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king", "ace" };      int deck[4][13] = { available }; // using 2=d array make sure same card drawn single deck     int i;     int suitsinhand[suits], facesinhand[faces];      srand(time(null)); //seed random number generator      //deal 2 hands     for(i = 0; < 2; i++)     {         dealahand(suits, faces, deck);         analyzehand(suitsinhand, facesinhand);     } }  //instructions dealing hand function void dealahand(char *suits[], char *faces[], int deck[][faces]) {     int i;     for(i = 0; < 5; i++)         dealacard(suits, faces, deck);     printf("\n");  }  //instructions dealing card function void dealacard(char *suits[], char *faces[], int deck[][faces]) {      int suitindex, faceindex;      suitindex = rand() % 4;     faceindex = rand() % 13;      while (deck[suitindex][faceindex] == taken)     {         suitindex = rand() % 4;         faceindex = rand() % 13;     }      deck[suitindex][faceindex] = taken;      printf("%s of %s \n", faces[faceindex], suits[suitindex]);  }  //instructions analyze function void analyzehand( int facesinhand[], int suitsinhand[]) {     int num_consec = 0;     int rank, suit;      straight = false;     flush = false;     4 = false;     3 = false;     pairs = 0;      // check flush – 5 cards of same suit     (suit = 0; suit < suits; suit++)         if (suitsinhand[suit] == 5)             flush = true;      // check straight – eg. 1 each of 5,6,7,8,9     //    locate first card     rank = 0;     while (facesinhand[rank] == 0)         rank++;      //     count consecutive non-zero faces     (; rank < faces && facesinhand[rank]; rank++)         num_consec++;      if (num_consec == 5)     {         straight = true;         return;     }      /* check 4-of-a-kind, 3-of-a-kind, , pairs */     (rank = 0; rank < faces; rank++)     {         if (facesinhand[rank] == 4)             4 = true;         if (facesinhand[rank] == 3)             3 = true;         if (facesinhand[rank] == 2)             pairs++;     } }  if (straight && flush)     printf("straight flush\n\n"); else if (four)     printf("four of kind\n\n"); else if (three && pairs == 1)     printf("full house\n\n"); else if (flush)     printf("flush\n\n"); else if (straight)     printf("straight\n\n"); else if (three)     printf("three of kind\n\n"); else if (pairs == 2)     printf("two pairs\n\n"); else if (pairs == 1)     printf("pair\n\n"); else     printf("high card\n\n"); 


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -