void evaluateWinner (Card hand[][HAND_SIZE], int numPlayers, int handScores[][6], int *bestHandIndices, int *numTied) {
	int cardRankCount[numPlayers][NUM_RANKS];
	memset(cardRankCount, 0, numPlayers * NUM_RANKS * sizeof(int));
	
	for (int i = 0; i < numPlayers; i++)
		for (int j = 0; j < HAND_SIZE; j++)
			cardRankCount[i][hand[i][j].rank]++;
	for (int i = 0; i < numPlayers; i++)
		evaluateHand (&hand[i][0], &cardRankCount[i][0], &handScores[i][0]);
	
	for (int i = 1; i < numPlayers; i++) {
		if (handScores[i][0] > handScores[bestHandIndices[0]][0]) {
			*numTied = 0;
			bestHandIndices[*numTied] = i;
		}
		else if (handScores[i][0] == handScores[bestHandIndices[0]][0]) {
			for (int j = 1; j < 1 + HAND_SIZE; j++) {
				if (handScores[i][j] > handScores[bestHandIndices[0]][j]) {
					bestHandIndices[*numTied] = i;
					break;
				}
				else if (j == HAND_SIZE - 1 && handScores[i][HAND_SIZE] == handScores[bestHandIndices[0]][HAND_SIZE]) {
					bestHandIndices[++*numTied] = i;
					break;
				}
				else break;
			}
		}
	}
}
Esempio n. 2
0
File: utils2.c Progetto: dwesa/notes
void dealerBlackJack(Card player[], int playerCount, Card dealer[], int dealerCount)
{
  int i;

  printf ("Dealer\'s cards:\n");
  for ( i = 0; i < dealerCount ; i++)
    printf ("  %s of %s\n", dealer[i].name, dealer[i].suit);
  printf ("  Points: %d\n", evaluateHand(dealer, dealerCount));

  if (evaluateHand(player, playerCount) == 21)
  {
    printf ("Both Dealer and Player have Blackjack.  Tie\n");
  }
  else
  {
    printf ("The Dealer has Blackjack.  You lose\n");
  }
}
Esempio n. 3
0
int main(){

  Card deck[DECKSIZE];
  Card player[5];
  Card dealer[5];
  int cardsLeft;
  int playerCount;
  int dealerCount;
  int i;

  initDeck(deck);
  cardsLeft = 52;

  player[0] = deck[--cardsLeft];
  dealer[0] = deck[--cardsLeft];
  player[1] = deck[--cardsLeft];
  dealer[1] = deck[--cardsLeft];
  playerCount = 2;
  dealerCount = 2;

  printf ("Player\'s cards:\n");
  for ( i = 0; i < playerCount ; i++)
    printf ("  %s of %s\n", player[i].name, player[i].suit); 
  printf ("  Points: %d\n", evaluateHand(player, playerCount));
  printf ("Dealer shows: %s of %s\n", dealer[0].name, dealer[0].suit);
 
  if (evaluateHand(dealer, dealerCount) == 21)
  {
    dealerBlackJack(player, playerCount, dealer, dealerCount);
  }
  else if (evaluateHand(player, playerCount) == 21)
  {
    printf ("Player has Blackjack.  You win.\n");
  }
  else
  {
    playHand(player, playerCount, dealer, dealerCount, deck, cardsLeft);
  }

  return 0;
}
Esempio n. 4
0
int calcularguanyador(int cartes1[7],int cartes2[7],int cartes3[7], int cartes4[7], int *guanyadors)
{
	int empat=false;
	int jugadaempat;
	int iguany;
	
	bool noempat = true;
	int handcompare1[5];
	int handcompare2[5];
    
    
	int handres1[5];
	int handres2[5];
	int handres3[5];
	int handres4[5];
    
    
	int puntuacio1;
	int puntuacio2;
	int puntuacio3;
	int puntuacio4;
    
	int pguanyadora = 0;
    
	std::vector <int> puntuacions;
    
	int hand[5] = {-10,-10,-10,-10,-10};
	int puntuacio;
    
    //comencem a mirar les 4 mans.
    
    //ma1
    if(cartes1[0]!=-1){
        evaluateHand(cartes1,hand,&puntuacio);
        for(int i=0;i<5;i++)handres1[i]=hand[i];
        for(int i=0;i<5;i++) std::cout <<"Hand: "<< num(handres1[i])<< " de " << pal(handres1[i]) << std::endl;
        puntuacio1=puntuacio;
        puntuacions.push_back(puntuacio1);
        //std::cout << "Puntuacio de la hand final: "<<puntuacio1<<std::endl;
        for(int i=0;i<5;i++)hand[i]=-10;
    }
    if(cartes1[0]==-1)	puntuacions.push_back(0);
    
    //ma2
    if(cartes2[0]!=-1){
        evaluateHand(cartes2,hand,&puntuacio);
        for(int i=0;i<5;i++)handres2[i]=hand[i];
        for(int i=0;i<5;i++) std::cout <<"Hand: "<< num(handres2[i])<< " de " << pal(handres2[i]) << std::endl;
        puntuacio2=puntuacio;
        puntuacions.push_back(puntuacio2);
        //std::cout << "Puntuacio de la hand final: "<<puntuacio2<<std::endl;
        for(int i=0;i<5;i++)hand[i]=-10;
    }
    if(cartes2[0]==-1)	puntuacions.push_back(0);
    
    
    //ma3
    if(cartes3[0]!=-1){
        evaluateHand(cartes3,hand,&puntuacio);
        for(int i=0;i<5;i++)handres3[i]=hand[i];
        for(int i=0;i<5;i++) std::cout <<"Hand: "<< num(handres3[i])<< " de " << pal(handres3[i]) << std::endl;
        puntuacio3=puntuacio;
        puntuacions.push_back(puntuacio3);
        //std::cout << "Puntuacio de la hand final: "<<puntuacio3<<std::endl;
        for(int i=0;i<5;i++)hand[i]=-10;
    }
    if(cartes3[0]==-1)	puntuacions.push_back(0);
    
    
    //ma4
    if(cartes4[0]!=-1){
        evaluateHand(cartes4,hand,&puntuacio);
        for(int i=0;i<5;i++)handres4[i]=hand[i];
        for(int i=0;i<5;i++) std::cout <<"Hand: "<< num(handres4[i])<< " de " << pal(handres4[i]) << std::endl;
        puntuacio4=puntuacio;
        puntuacions.push_back(puntuacio4);
        //std::cout << "Puntuacio de la hand final: "<<puntuacio4<<std::endl;
        for(int i=0;i<5;i++)hand[i]=-10;
    }
    if(cartes4[0]==-1)	puntuacions.push_back(0);
    
    
	std::cout<<"size puntuacions: "<<puntuacions.size()<<std::endl;
    
	//for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
    
	for(int i =0;i <puntuacions.size();i++)
	{
		noempat = true;
        
		if(i==0)
		{
			for(int i =0;i<5;i++)handcompare1[i]=handres1[i];
		}
		if(i==1)
		{
			for(int j =0;j<5;j++)handcompare1[j]=handres2[j];
		}
		if(i==2)
		{
			for(int j =0;j<5;j++)handcompare1[j]=handres3[j];
		}
		if(i==3)
		{
			for(int j =0;j<5;j++)handcompare1[j]=handres4[j];
		}
        
        
		//std::cout<<"handcompare1[0]: "<< num(handcompare1[0]) <<std::endl;
		//std::cout<<"handcompare2[0]: "<< num(handcompare2[0]) <<std::endl;
		if(puntuacions[i]>pguanyadora)
		{
			pguanyadora = puntuacions[i];
			iguany = i;
            
			empat=false;
            
			if(i==0)
			{
				for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
			}			
			if(i==1)
			{
				for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
			}
			if(i==2)
			{
				for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
			}
			if(i==3)
			{
				for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
			}
			noempat =false;
            
		}
		
		else if(puntuacions[i]==pguanyadora and pguanyadora!=0)
		{
            
			if(pguanyadora==1)
			{
				if(num(handcompare1[0])>num(handcompare2[0]))
				{
					pguanyadora = puntuacions[i];
					iguany = i;
                    
					empat=false;
                    
					if(i==0)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
					}			
					if(i==1)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
					}
					if(i==2)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
					}
					if(i==3)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
					}
					noempat =false;
				}
				if(num(handcompare1[0])==num(handcompare2[0]))
				{
					if(num(handcompare1[1])>num(handcompare2[1]))
					{
						pguanyadora = puntuacions[i];
						iguany = i;
                        
						empat=false;
						if(i==0)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
						}			
						if(i==1)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
						}
						if(i==2)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
						}
						if(i==3)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
						}
						noempat =false;
					}
					if(num(handcompare1[1])==num(handcompare2[1]))
					{
						if(num(handcompare1[2])>num(handcompare2[2]))
						{
							pguanyadora = puntuacions[i];
							iguany = i;
                            
							empat=false;
							if(i==0)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
							}			
							if(i==1)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
							}
							if(i==2)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
							}
							if(i==3)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
							}
						}
						if(num(handcompare1[2])==num(handcompare2[2]))
						{
							if(num(handcompare1[3])>num(handcompare2[3]))
							{
								pguanyadora = puntuacions[i];
								iguany = i;
                                
								empat=false;
								if(i==0)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
								}			
								if(i==1)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
								}
								if(i==2)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
								}
								if(i==3)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
								}
							}
							if(num(handcompare1[3])==num(handcompare2[3]))
							{
								if(num(handcompare1[4])>num(handcompare2[4]))
								{
									pguanyadora = puntuacions[i];
									iguany = i;
									std::cout<<"i guany : "<<iguany<<std::endl;
									empat=false;
									if(i==0)
									{
										for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
									}			
									if(i==1)
									{
										for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
									}
									if(i==2)
									{
										for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
									}
									if(i==3)
									{
										for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
									}
								}
								if(num(handcompare1[4])==num(handcompare2[4]))
								{
									empat = true;
									pguanyadora = puntuacions[i];
									jugadaempat = pguanyadora;
                                    
									guanyadors[i-1]=1;
									guanyadors[i]=1;
								}	
							}	
						}
					}
				}
			}
			if(pguanyadora==2)
			{
				if(num(handcompare1[0])>num(handcompare2[0]))
				{
					pguanyadora = puntuacions[i];
					iguany = i;
                    
					empat=false;
					if(i==0)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
					}			
					if(i==1)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
					}
					if(i==2)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
					}
					if(i==3)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
					}
				}
				if(num(handcompare1[0])==num(handcompare2[0]))
				{
					if(num(handcompare1[4])>num(handcompare2[4]))
					{
						pguanyadora = puntuacions[i];
						iguany = i;
                        
						empat=false;
						if(i==0)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
						}			
						if(i==1)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
						}
						if(i==2)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
						}
						if(i==3)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
						}
					}
					if(num(handcompare1[4])==num(handcompare2[4]))
					{
						if(num(handcompare1[3])>num(handcompare2[3]))
						{
							pguanyadora = puntuacions[i];
							iguany = i;
                            
							empat=false;							
							if(i==0)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
							}			
							if(i==1)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
							}
							if(i==2)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
							}
							if(i==3)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
							}
						}
						if(num(handcompare1[3])==num(handcompare2[3]))
						{
							if(num(handcompare1[2])>num(handcompare2[2]))
							{
								pguanyadora = puntuacions[i];
								iguany = i;
                                
								empat=false;
								if(i==0)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
								}			
								if(i==1)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
								}
								if(i==2)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
								}
								if(i==3)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
								}
							}
							if(num(handcompare1[2])==num(handcompare2[2]))
							{
								empat = true;
								pguanyadora = puntuacions[i];
								jugadaempat = pguanyadora;
								guanyadors[i-1]=1;
								guanyadors[i]=1;
							}	
						}					
					}
				}
			}
			if(pguanyadora==3)
			{
				if(num(handcompare1[0])>num(handcompare2[0]))
				{
					pguanyadora = puntuacions[i];
					iguany = i;
                    
					empat=false;
					if(i==0)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
					}			
					if(i==1)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
					}
					if(i==2)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
					}
					if(i==3)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
					}
				}
				if(num(handcompare1[0])==num(handcompare2[0]) and noempat)
				{
					if(num(handcompare1[2])>num(handcompare2[2]))
					{
						pguanyadora = puntuacions[i];
						iguany = i;
                        
						empat=false;
						if(i==0)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
						}			
						if(i==1)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
						}
						if(i==2)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
						}
						if(i==3)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
						}
					}
					if(num(handcompare1[2])==num(handcompare2[2]) and noempat)
					{
						if(num(handcompare1[4])>num(handcompare2[4]))
						{
							pguanyadora = puntuacions[i];
							iguany = i;
                            
							empat=false;							
							if(i==0)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
							}			
							if(i==1)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
							}
							if(i==2)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
							}
							if(i==3)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
							}
						}
						if(num(handcompare1[4])==num(handcompare2[4]))
						{
							empat = true;
							pguanyadora = puntuacions[i];
							jugadaempat = pguanyadora;
							guanyadors[i-1]=1;
							guanyadors[i]=1;
						}					
					}
				}
			}
			if(pguanyadora==4)
			{
				if(num(handcompare1[0])>num(handcompare2[0]))
				{
					pguanyadora = puntuacions[i];
					iguany = i;
                    
					empat=false;
					if(i==0)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
					}			
					if(i==1)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
					}
					if(i==2)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
					}
					if(i==3)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
					}
                    
				}
				if(num(handcompare1[0])==num(handcompare2[0]))
				{
                    //std::cout<<"compare1: "<<num(handcompare1[0])<<num(handcompare2[0])<<" compare2"<<std::endl; 
					if(num(handcompare1[3])>num(handcompare2[3]))
					{
						pguanyadora = puntuacions[i];
						iguany = i;
                        
						empat=false;
						if(i==0)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
						}			
						if(i==1)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
						}
						if(i==2)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
						}
						if(i==3)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
						}
                        
					}
					if(num(handcompare1[3])==num(handcompare2[3]))
					{
						//std::cout<<"compare1: "<<num(handcompare1[3])<<num(handcompare2[3])<<" compare2"<<std::endl; 
						if(num(handcompare1[4])>num(handcompare2[4]))
						{
							pguanyadora = puntuacions[i];
							iguany = i;
                            
							empat=false;							
							if(i==0)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
							}			
							if(i==1)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
							}
							if(i==2)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
							}
							if(i==3)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
							}
                            
						}
                        
						if(num(handcompare1[4])==num(handcompare2[4]))
						{
							//std::cout<<"compare1: "<<num(handcompare1[4])<<num(handcompare2[4])<<" compare2"<<std::endl; 
							empat = true;
							pguanyadora = puntuacions[i];
							jugadaempat = pguanyadora;
							guanyadors[i-1]=1;
							guanyadors[i]=1;
						}		
					}
				}
			}
			if(pguanyadora==5)
			{
				if(num(handcompare1[0])>num(handcompare2[0]))
				{
					pguanyadora = puntuacions[i];
					iguany = i;
                    
					empat=false;
					if(i==0)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
					}			
					if(i==1)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
					}
					if(i==2)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
					}
					if(i==3)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
					}
				}
				if(num(handcompare1[0])==num(handcompare2[0]))
				{
					empat = true;
					pguanyadora = puntuacions[i];
					jugadaempat = pguanyadora;
					guanyadors[i-1]=1;
					guanyadors[i]=1;
				}
			}
			if(pguanyadora==6)
			{
				if(num(handcompare1[4])>num(handcompare2[4]))
				{
					pguanyadora = puntuacions[i];
					iguany = i;
                    
					empat=false;
                    
					if(i==0)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
					}			
					if(i==1)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
					}
					if(i==2)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
					}
					if(i==3)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
					}
				}
				if(num(handcompare1[4])==num(handcompare2[4]))
				{
					if(num(handcompare1[1])>num(handcompare2[1]))
					{
						pguanyadora = puntuacions[i];
						iguany = i;
                        
						empat=false;
						if(i==0)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
						}			
						if(i==1)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
						}
						if(i==2)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
						}
						if(i==3)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
						}
					}
					if(num(handcompare1[3])==num(handcompare2[3]))
					{
						if(num(handcompare1[2])>num(handcompare2[2]))
						{
							pguanyadora = puntuacions[i];
							iguany = i;
                            
							empat=false;
							if(i==0)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
							}			
							if(i==1)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
							}
							if(i==2)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
							}
							if(i==3)
							{
								for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
							}
						}
						if(num(handcompare1[2])==num(handcompare2[2]))
						{
							if(num(handcompare1[1])>num(handcompare2[1]))
							{
								pguanyadora = puntuacions[i];
								iguany = i;
                                
								empat=false;
								if(i==0)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
								}			
								if(i==1)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
								}
								if(i==2)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
								}
								if(i==3)
								{
									for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
								}
							}
							if(num(handcompare1[1])==num(handcompare2[1]))
							{
								if(num(handcompare1[0])>num(handcompare2[0]))
								{
									pguanyadora = puntuacions[i];
									iguany = i;
                                    
									empat=false;
									if(i==0)
									{
										for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
									}			
									if(i==1)
									{
										for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
									}
									if(i==2)
									{
										for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
									}
									if(i==3)
									{
										for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
									}
								}
								if(num(handcompare1[0])==num(handcompare2[0]))
								{
									empat = true;
									pguanyadora = puntuacions[i];
									jugadaempat = pguanyadora;
									guanyadors[i-1]=1;
									guanyadors[i]=1;
								}	
							}	
						}
					}
				}
			}
			if(pguanyadora==7)
			{
				if(num(handcompare1[0])>num(handcompare2[0]))
				{
					pguanyadora = puntuacions[i];
					iguany = i;
                    
					empat=false;
					if(i==0)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
					}			
					if(i==1)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
					}
					if(i==2)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
					}
					if(i==3)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
					}
				}
				if(num(handcompare1[0])==num(handcompare2[0]))
				{
					if(num(handcompare1[3])>num(handcompare2[3]))
					{
						pguanyadora = puntuacions[i];
						iguany = i;
                        
						empat=false;
						if(i==0)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
						}			
						if(i==1)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
						}
						if(i==2)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
						}
						if(i==3)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
						}
					}
					if(num(handcompare1[3])==num(handcompare2[3]))
					{
						empat = true;
						pguanyadora = puntuacions[i];
						jugadaempat = pguanyadora;
						guanyadors[i-1]=1;
						guanyadors[i]=1;
					}
				}
			}
			if(pguanyadora==8)
			{
				if(num(handcompare1[0])>num(handcompare2[0]))
				{
					pguanyadora = puntuacions[i];
					iguany = i;
                    
					empat=false;
					if(i==0)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
					}			
					if(i==1)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
					}
					if(i==2)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
					}
					if(i==3)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
					}
				}
				if(num(handcompare1[0])==num(handcompare2[0]))
				{
					if(num(handcompare1[4])>num(handcompare2[4]))
					{
						pguanyadora = puntuacions[i];
						iguany = i;
                        
						empat=false;
						if(i==0)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
						}			
						if(i==1)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
						}
						if(i==2)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
						}
						if(i==3)
						{
							for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
						}
					}
					if(num(handcompare1[4])==num(handcompare2[4]))
					{
						empat = true;
						pguanyadora = puntuacions[i];
						jugadaempat = pguanyadora;
						guanyadors[i-1]=1;
						guanyadors[i]=1;
					}
				}
			}
			if(pguanyadora==9)
			{
				if(num(handcompare1[0])>num(handcompare2[0]))
				{
					pguanyadora = puntuacions[i];
					iguany = i;
                    
					empat=false;
					if(i==0)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres1[j];
					}			
					if(i==1)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres2[j];
					}
					if(i==2)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres3[j];
					}
					if(i==3)
					{
						for(int j =0;j<5;j++)handcompare2[j]=handres4[j];
					}
				}
				if(num(handcompare1[0])==num(handcompare2[0]))
				{
					empat = true;
					pguanyadora = puntuacions[i];
					jugadaempat = pguanyadora;
					guanyadors[i-1]=1;
					guanyadors[i-1]=1;
					guanyadors[i]=1;
				}
			}
			
		}
        
	}
    
	if(empat)std::cout<<"jugada guanyadora : "<< pguanyadora<<std::endl;
	if(empat)std::cout<<"EMPAT: "<< pguanyadora<<std::endl;
	if(empat)return -1;
        return iguany;
}
Esempio n. 5
0
void playHand (Card player[], int playerCount, 
               Card dealer[], int dealerCount,
               Card deck[], int cardsLeft)
{
  int playerPoints;
  int dealerPoints;
  int i;
  char input[100];

  do 
  {
    printf ("Do you want another card? (y/n):");
    gets(input);
    if (input[0] == 'y')
      player[playerCount++] = deck[--cardsLeft];

    printf ("Player\'s cards:\n");
    for ( i = 0; i < playerCount ; i++)
      printf ("  %s of %s\n", player[i].name, player[i].suit); 
    printf ("  Points: %d\n", evaluateHand(player, playerCount));
    printf ("Dealer shows: %s of %s\n", dealer[0].name, dealer[0].suit);
  }
  while (input[0] == 'y' && evaluateHand(player, playerCount) != -1);

  if(evaluateHand(player, playerCount) == -1)
  {
    printf ("Your point value went over 21.  You lose\n");
    return ;
  }

  printf ("\nDealer\'s cards:\n");
  for ( i = 0; i < dealerCount ; i++)
    printf ("  %s of %s\n", dealer[i].name, dealer[i].suit); 
  printf ("  Points: %d\n", evaluateHand(dealer, dealerCount));
  while (evaluateHand(dealer, dealerCount) < 17)
  {
    dealer[dealerCount++] = deck[--cardsLeft];
    printf ("  Newcard for dealer: %s of %s\n", 
            dealer[dealerCount - 1].name, dealer[dealerCount - 1].suit); 
    printf ("  Points: %d\n", evaluateHand(dealer, dealerCount));
    if (evaluateHand(dealer, dealerCount) == -1)
    {
      printf ("The dealer went over 21 points.  You win\n");
      return ;
    }
  }

  playerPoints = evaluateHand(player, playerCount);
  dealerPoints = evaluateHand(dealer, dealerCount);
  if (playerPoints == dealerPoints)
  {
    printf("Dealer and Player have the same point total.  Tie\n");
  }
  else if (playerPoints > dealerPoints)
  {
    printf("Player has the higher point total.  You win.\n");
  }
  else
  {
    printf("Dealer has the higher point total.  You lose.\n");
  }

}