Пример #1
0
void findWinner(Player * nPlayer, double * pot){
	int i, mark, win, first, second;
	float max;
	float result;
	first = second = 100;
	max = 0;
	mark = 0;
	for (i = 0; i < PLAYERS; i++){
		if (nPlayer[i].inGame == 1){
			result = analyze_hand(nPlayer[i]);
			
			/*Here I determine if the player's result is uniquely high, or ties a previous max*/
			if (result > max){
				win = 1;
				max = result;
				mark = i;
			}
			else if (result == max){
				win = 2;
				mark = i;
			}
		}
	}

/*If there is a tie then need to find who tied*/
	if (win == 2){
		mark = 0;
		for (i = 0; i < PLAYERS; i++){
			if (nPlayer[i].inGame == 1){	
				result = analyze_hand(nPlayer[i]);
				if (result == max && first == 100){
					first = i;
					}
				else if (result == max && second == 100){
					second = i;
				}
			}
		}
		/*Split the pot between the two winners*/
		printf("%s and %s have tied and will split the pot of %.2lf\n", nPlayer[first].name, nPlayer[second].name, *pot);
		nPlayer[first].galleons = nPlayer[first].galleons + (*pot/2);
		nPlayer[second].galleons = nPlayer[second].galleons + (*pot/2);
	}
	else{
	/*If only one winner, then then win the whole pot*/
		printf("\n%s has won %.2lf\n\n", nPlayer[mark].name, *pot);
		nPlayer[mark].galleons = nPlayer[mark].galleons + *pot;	
		printf("%s had a hand of:\n", nPlayer[mark].name);
		for (i = 0; i< HAND; i++){
			printf("%d) %s\t%s\n", i, nPlayer[mark].hand[i].face, nPlayer[mark].hand[i].suit);
		}
	}
}
Пример #2
0
int main(void)
{
	while(1) 
	{
		read_cards();
		analyze_hand();
	} 
}
Пример #3
0
/**********************************************************
 * main: Calls read_cards, analyze_hand, and print_result *
 *       repeatedly.                                      *
 **********************************************************/
int main(void)
{
  for (;;) {
    read_cards();
    analyze_hand();
    print_result();
  }
}
/******************************************************************
* main: Calls read_cards, analyze_hand, and print_result          *
* 		repeatedly                                                *
******************************************************************/
int main(int argc, char *argv[]) {
	for(;;)
	{
		read_cards();
		analyze_hand();
		print_result();
	}
	return 0;
}
Пример #5
0
/*
 * Calls read_cards, analyze_hand, and print_result repeatedly.
 */
int main(void)
{
	int hand[NUM_CARDS][2];

	while(true) {
		read_cards(hand);
		analyze_hand(num_in_rank, num_in_suit);
		print_result();
	}
}
/*************************************************************
 * main: Calls read_cards, analyze_hand, and print_result    *
 *       repetedly.                                          *
 *************************************************************/
int main(void)
{
    int num_in_rank[NUM_RANKS], num_in_suit[NUM_SUITS];

    for (;;) {
        read_cards(num_in_rank, num_in_suit);
        analyze_hand(num_in_rank, num_in_suit);
        print_result();
    }
}
/**********************************************************
 * main: Calls read_cards, analyze_hand, and print_result *
 *       repeatedly.                                      *
 **********************************************************/
int main(void)
{
    int hand[NUM_CARDS][2];

    for (;;) {
        read_cards(hand);
        analyze_hand(hand);
        print_result();
    }
}
Пример #8
0
/**********************************************************
 * main: Calls read_cards, analyze_hand, and print_result *
 *       repeatedly.                                      *
 **********************************************************/
int main(void)
{
  int num_in_rank[NUM_RANKS];
  int num_in_suit[NUM_SUITS];
  bool straight, flush, four, three;
  int pairs;   /* can be 0, 1, or 2 */

 for (;;) {
    read_cards(num_in_rank, num_in_suit);
    analyze_hand(num_in_rank, num_in_suit, &straight, &flush, &four, &three, &pairs);
    print_result(&straight, &flush, &four, &three, &pairs);
  }
}
Пример #9
0
int main(void) {
    int num_in_rank[RANKS];
    int num_in_suit[SUITS];
    bool straight, flush, four, three;
    int pairs;
    while (read_cards(num_in_rank, num_in_suit)) {
        analyze_hand(num_in_rank, num_in_suit, &straight, &flush, &four, &three,
                     &pairs);
        print_result(&straight, &flush, &four, &three, &pairs);
    }

    /* This _should_ now return. I will test when I have a working system */
    return 0;
}
Пример #10
0
float MC_rate(Player * nPlayer, int numPlayer){
	Deck simDeck;
	float avg, newAvg, sum;
	int i, j, k, max, count, check;

/*Create Monte Carlo Player to test out all simulations*/
	Player MC;
	Player original;
/*I created Player original so I could quickly reconfigure Monte Carlo's original hand after each exchange*/
	for (i = 0; i<5; i++){
		MC.hand[i] = nPlayer[numPlayer].hand[i];
		original.hand[i] = nPlayer[numPlayer].hand[i];
	}

/*Run the MC_sim_deck function above to get the 47 cards we will use for all simulations*/
	simDeck = MC_sim_deck(&MC, numPlayer);
	
/*initialize average to 0*/	
	avg = 0;

/*In this array, if 1 then echange that card, if 0, do NOT exchange the card*/
	int arr [][5] = {
		{0,0,0,0,0},/*0*/
		{1,0,0,0,0},
		{0,1,0,0,0},
		{0,0,1,0,0},
		{0,0,0,1,0},
		{0,0,0,0,1},
		{1,1,0,0,0},
		{1,0,1,0,0},
		{1,0,0,1,0},
		{1,0,0,0,1},
		{0,1,1,0,0},/*10*/
		{0,1,0,1,0},
		{0,1,0,0,1},
		{0,0,1,1,0},
		{0,0,1,0,1},
		{0,0,0,1,1},
		{1,1,1,0,0},
		{1,1,0,1,0},
		{1,1,0,0,1},
		{1,0,1,1,0},
		{1,0,1,0,1},/*20*/
		{1,0,0,1,1},
		{0,1,1,1,0},
		{0,1,1,0,1},
		{0,1,0,1,1},
		{0,0,1,1,1},
		{1,0,1,1,1},
		{1,1,0,1,1},
		{1,1,1,0,1},
		{1,1,1,1,0},
		{0,1,1,1,1},
		{1,1,1,1,1},/*31*/
	};

/*I run through all 32 possible exchanges and run each scenario 10,000 times to find average for each iteration*/
	for (i = 0; i < 32; i++){
		sum = 0;
		check = 0;
		for (j = 0; j < 10000; j++){
			shuffleDeckMC(&simDeck);
			count = 0;
			/*for loop here just goes up the newly shuffled deck depending on # of card exchanges*/
			/*this made everything alot faster and works to the same effect, rare moment of intelligence*/
			for (k=0; k<5; k++){
				if(arr[i][k] == 1){
					MC.hand[k] = simDeck.stack[count];
					count++;
				}
			}
			/*continue adding the value of each hand scenario to sum*/
			check = analyze_hand(MC);
			sum = sum + check;
			/*reset MC's hand to original*/
			for (k = 0; k<5; k++){
				MC.hand[k] = original.hand[k];
			}
		}

	/*update average if this ith iteration creates a higher value expectation*/
		newAvg = (sum/10000);
		if(newAvg > avg){
			max = i;
			avg = newAvg;
		}
	}
	
	/*Keep track of Monte Carlo Advice array(1 or 0) for each player's mcAdvice*/
	for (k = 0; k<5; k++){
		if(arr[max][k] == 1){
			nPlayer[numPlayer].mcAdvice[k] = 1;
		}
		else{
			nPlayer[numPlayer].mcAdvice[k] = 0;
		}
	}
	/*return highest expected average*/
	return avg;
}
Пример #11
0
int main(){
	float result;
	char userName [40];
	int i, count, choice, betMarker, pLeft;
	double bet, pot;
	Player newPlayers [PLAYERS];

	/*Intro for the game*/
	setup(newPlayers, userName);
	Deck newDeck;
	srand(time(NULL));
	
	/*MAIN GAME LOOP, BASED ON GALLEONS*/

	while (newPlayers[0].galleons >= 5){
		printf("\n\n========  NEW ROUND  ========\n\n\n");
		pot = bet = 0;

		/*Always update each player to be in the game initially, unless they have less than 5 galleons*/
		for(i = 0; i<PLAYERS; i++){
			newPlayers[i].inGame = 1;
			if (newPlayers[i].galleons < 5){
				newPlayers[i].galleons = 0;
				newPlayers[i].inGame = 0;
				newPlayers[i].checkBet = 0;
			}
			newPlayers[i].checkBet = 0;
			newPlayers[i].galleons = newPlayers[i].galleons - 5;
			if(newPlayers[i].inGame == 1){
				pot = pot + 5;
			}
		}
		/*if the three computers are out of the game, user has won, so end the game!*/
		pLeft = 0;
		for (i = 1; i<PLAYERS; i++){
			if (newPlayers[i].inGame == 0){
				pLeft++;
			}
			if (pLeft == 3){
				printf("\n\nCONGRATULATIONS %s, you won! Harry, Voldy and Dumbly seem to have lost all their money!!!\n\n", newPlayers[0].name);
				return 0;
			}
		}


		sleep(2);
		/*Print out current standings, how many galleons each player has and if they are still in*/	
		printf("Current Standings:\n\n");
		for (i = 0; i<PLAYERS; i++){
			if (newPlayers[i].inGame == 1){
				printf("%s has %.2f Galleons\n", newPlayers[i].name, newPlayers[i].galleons);
			}
		}
		for (i = 0; i<PLAYERS; i++){
			if (newPlayers[i].inGame == 0){
				printf("%s is out of the game\n", newPlayers[i].name);
			}
		}

		/*Initialize Game*/
		fillDeck(&newDeck);
		shuffleDeck(&newDeck);
		dealOut(&newDeck, newPlayers);
		printf("\nYou are about to receive your hand!\n");
		
		/*User specifics*/
		sleep(1);
		displayHand(newPlayers);	
		result = MC_rate(newPlayers, 0);
		sleep(1);

		/*Monte Carlo Advice in MC.c*/
		advice(&newPlayers[0]);

		/*This exchange is only for the user, computers have its own function*/
		exchangeCards(newPlayers, &newDeck);
		displayHand(newPlayers);
		printf("\nYou can now either: \n1) Place a Bet\n2) Pass\n3) Fold\nPlease type 1,2, or 3: ");
		scanf("%d", &choice);
		if (choice == 1){
			bet = placeBet(newPlayers, &pot);
		}
		else if (choice == 3){
			endPlayer(newPlayers, 0);
		}
		else if (choice == 2){
			printf("You have chosen to pass.\n");
		}

		/*run Computer exchanges and whether they decide to raise, pass or fold*/	
		count = 1;
		while (count <= 3){
			if(newPlayers[count].inGame == 1){
				
				sleep(1);
				/*result value is more for testing purposes, but still needs to run to fill in the correct*/
				/*int array mcAdivce for Monte carlo advice for each computer*/
				result = MC_rate(newPlayers, count);
				
				/*This can be found in exchange.c, just exchange based on MC advice*/
				computerExchange(newPlayers, &newDeck, count);
				
				/*This can be found in display.c, determines for the computer what to do (raise, pass, fold)*/
				comp_decision(newPlayers, count, &bet, &pot);
				
				/*keep track of which computer raises for later*/
				if (newPlayers[count].checkBet > 0){
					betMarker = count;
				}
			}

			count++;
		}


		/*if any computer raises, then go back to user one time to either match or fold, then each computer*/

		if (betMarker > 0){
			if (newPlayers[0].galleons < newPlayers[betMarker].checkBet){
				printf("\nOH NOOOO, the bet is more than you can afford, and by wizarding rules, you lose the game!!!\n\n");
					return 0;
			}
		if (newPlayers[0].inGame != 0){	
		printf("%s raised by %.2lf. Would you like to either:\n1) Match\n2) Fold \nPlease type 1 or 2: ", newPlayers[betMarker].name, newPlayers[betMarker].checkBet);
		scanf("%d", &choice);
			if (choice == 1){
				newPlayers[0].galleons = newPlayers[0].galleons - newPlayers[betMarker].checkBet;
				pot = pot + newPlayers[betMarker].checkBet;
				printf("You have matched the raise\n");
			}
			else {
				newPlayers[0].inGame = 0;
				printf("You Folded\n");
			}
			}

	/*Determine whether each computer should match or fold*/	
		for (i = 1; i<betMarker; i++){
			if (newPlayers[i].inGame == 1){
				if (newPlayers[i].galleons > newPlayers[betMarker].checkBet){
					result = analyze_hand(newPlayers[i]);
					if (result < 23){
						newPlayers[i].inGame = 0;
						printf("%s has folded\n", newPlayers[i].name);
					}
					else{	
						newPlayers[i].galleons = newPlayers[i].galleons - newPlayers[betMarker].checkBet;	
						pot = pot + newPlayers[betMarker].checkBet;
						printf("%s has matched the raise\n",newPlayers[i].name);
						}
					}
				}
			}
		}
		
		sleep(2);
		/*find winner of the game, give winning's to rightful winner, display winner's hand*/
		findWinner(newPlayers, &pot);
		
		/*reset betMarker for next game*/
		betMarker = 0;
		sleep(2);
	}

	/*After game loop, you have lost all your money or you have less than the 5 Galleon entrance amount*/	
		printf("\n\nOH NO, you lost at Wizard's poker!!!!\n");
		printf("Final Galleon Count for each player:\n");
		for (i = 0; i < PLAYERS; i++){
			if (newPlayers[i].galleons < 0){
				newPlayers[i].galleons = 0;
			}
			printf("\t%s has %.2f Galleons\n", newPlayers[i].name, newPlayers[i].galleons);
		}

	return 0;
}