Ejemplo n.º 1
0
// deal cards
void deal( const Card * const wDeck)
{ 
   // initialize suit array                       
   const char *suit[ SUITS ] =            
      { "Hearts", "Diamonds", "Clubs", "Spades" };
   
   // initialize face array                   
   const char *face[ FACES ] =
      { "King","Ace", "Deuce", "Three", "Four",         
        "Five", "Six", "Seven", "Eight",         
        "Nine", "Ten", "Jack", "Queen" };
   size_t i; // counter
   int array[6];
   int count = 0;
   int hand = 1;

   printf("現在為第 %d 手牌\n", hand);
   
   puts(" ");
   // loop through wDeck
   for ( i = 1; i < 51; ++i ) {
      printf( "%5s of %-8s\n", wDeck[ i ].face, wDeck[ i ].suit);
      count = count + 1;
      array[count] = wDeck[ i ].number + 1;
      if(count == 5){
      	puts(" ");
      	hand = hand + 1;
   	onepair(array,face);
   	twopair(array,face);
  	threesame(array,face);
   	foursame(array,face);
   	sameflower(array,suit);
	count = 0;
	int array[6] = {0};
	puts("-------------------------");
	if(i == 50){
		
	} else {
		printf("現在為第 %d 手牌\n", hand);
		puts(" "); 
	}
      	
      }
   }
    
   
} // end function deal
Ejemplo n.º 2
0
// deal cards
void deal( const Card * const wDeck)
{ 
   // initialize suit array                       
   const char *suit[ SUITS ] =            
      { "紅心", "方塊", "梅花", "黑桃" };
   
   // initialize face array                   
   const char *face[ FACES ] ={ "老k","一", "老二", "三", "四", "五",
      "六", "七", "八", "九", "十", "十一", "十二" };
   size_t i; // counter
   int array[6];
   int count = 0;
   int hand = 1;

   printf("現在為第 %d 手牌\n", hand);
   
   puts(" ");
   // loop through wDeck
   for ( i = 1; i < 51; ++i ) {
      printf( "%5s%-8s\n",  wDeck[ i ].suit,wDeck[ i ].face);
      count = count + 1;
      array[count] = wDeck[ i ].number + 1;
      if(count == 5){
      	puts(" ");
      	hand = hand + 1;
   		onepair(array,face);
   		twopair(array,face);
  		threesame(array,face);
   		foursame(array,face);
   		sameflower(array,suit);
		count = 0;
		int array[6] = {0};
		puts("-------------------------");
		if(i == 50){
		} else {
			printf("現在為第 %d 手牌\n", hand);
			puts(" "); 
		}
      	
      }
   }
    
   
} // end function deal
Ejemplo n.º 3
0
int getWinner(char player1[10], char player2[10]) {
    // Different hands ranked from 0 to 9
    int rank1;
    int rank2;
    
    // RKS NOTE: Ranking Player 1
    if (royal(player1)) {
        rank1 = 9;
    } else if (straightf(player1) > 0) {
        rank1 = 8;
    } else if (fourkind(player1) > 0) {
        rank1 = 7;
    } else if (fullh(player1) > 0) {
        rank1 = 6;
    } else if (flush(player1) > 0) {
        rank1 = 5;
    } else if (straight(player1) > 0) {
        rank1 = 4;
    } else if (threekind(player1) > 0) {
        rank1 = 3;
    } else if (twopair(player1) > 0) {
        rank1 = 2;
    } else if (onepair(player1) > 0) {
        rank1 = 1;
    } else {
        rank1 = 0;
    }
    

    // RKS NOTE: Ranking Player 2
    if (royal(player2)) {
        rank2 = 9;
    } else if (straightf(player2) > 0) {
        rank2 = 8;
    } else if (fourkind(player2) > 0) {
        rank2 = 7;
    } else if (fullh(player2) > 0) {
        rank2 = 6;
    } else if (flush(player2) > 0) {
        rank2 = 5;
    } else if (straight(player2) > 0) {
        rank2 = 4;
    } else if (threekind(player2) > 0) {
        rank2 = 3;
    } else if (twopair(player2) > 0) {
        rank2 = 2;
    } else if (onepair(player2) > 0) {
        rank2 = 1;
    } else {
        rank2 = 0;
    }

    if (rank1 > rank2) {
        return 0;
    } else if (rank2 > rank1) {
        return 1;
    } else if (rank1 == rank2) {
        if (rank1 == 8) {
            if (straightf(player1) > straightf(player2)) {
                return 0;
            } else if (straightf(player1) < straightf(player2)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 7)  {
            if (fourkind(player1) > fourkind(player2)) {
                return 0;
            } else if (fourkind(player2)>fourkind(player1)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 6) {
            if (fullh(player1) > fullh(player2)) {
                return 0;
            } else if (fullh(player1)>fullh(player2))
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 5) {
            return todeath(player1, player2);
        } else if (rank1 == 4) {
            if (straight(player1) > straight(player2)) {
                return 0;
            } else if (straight(player1) < straight(player2)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 3) {
            if (threekind(player1) > threekind(player2)) {
                return 0;
            } else if (threekind(player1) < threekind(player2)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 2) {
            if (twopair(player1) > twopair(player2)) {
                return 0;
            } else if (twopair(player1) < twopair(player2)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 1) {
            if (onepair(player1)>onepair(player2)) {
                return 0;
            } else if (onepair(player1)<onepair(player2)) {
                return 1;
            } else {
                return todeath(player1, player2);
            }
        } else if (rank1 == 0) {
            return todeath(player1, player2);
        }
    
    return -1;
}