/********************************************************** File: poker.cc Description: A program that simulates a simple poker game to serve as an example of using the Scatter and Gather functions from MPI. Author: Dana Vrajitoru Organization: IUSB Date: October 14, 2004 ***********************************************************/ #include using namespace std; #include #include "poker.h" #include "common.h" // Main poker playing function. void Poker_play(int proc_id, int nb_proc) { int *all_cards=NULL, score, *all_scores=NULL; int my_hand[hand_size]; int nb_cards = nb_proc * hand_size; if (proc_id == 0) { Draw_card(true); all_cards = new int[nb_cards]; for (int i=0; i= 4); drawn[card]++; } return card; } // Computes the score of the hand by sorting the cards first and then // calling the other functions bellow. int Score(int *hand) { // For only 5 elements it's not worth using the quicksort. Selection_sort(hand, hand_size); if (Four_of_a_kind(hand)) return 60; else if (Full_house(hand)) return 50; else if (Straight(hand)) return 40; else if (Three_of_a_kind(hand)) return 30; else if (Two_pairs(hand)) return 20; else if (Pair(hand)) return 15; else // If none of these applies, the score is the highest card. return hand[hand_size-1]; // hand is sorted at this point. } // For the following functions, the hand should have at least 5 // elements and only 5 will be used even if there are more. We will // assume that the cards have been sorted before the functions are // called. The functions should be called in decreasing order of // importance, such that the function "Pair" for example should not // worry if the hand is in fact a "3 of a kind". // Verifies if the hand has 4 of a kind cards, meaning 4 cards with // the same number. bool Four_of_a_kind(int *hand) { // Code to be supplied by the student. // Statement for compilation. return false; } // Verifies if the hand is a full house, meaning 3 cards of a kind // plus a pair of a different number. bool Full_house(int *hand) { if (hand[0] == hand[1] && hand[1] == hand[2] && hand[3] == hand[4]) return true; if (hand[0] == hand[1] && hand[2] == hand[3] && hand[3] == hand[4]) return true; return false; } // Verifies if the cards are in sequence. bool Straight(int *hand) { // Code to be supplied by the student. // Statement for compilation. return false; } // Verifies if the hand has 3 of a kind cards, meaning 3 cards with // the same number. bool Three_of_a_kind(int *hand) { // Code to be supplied by the student. // Statement for compilation. return false; } // Verifies if there are 2 pairs of cards in the hand. bool Two_pairs(int *hand) { int i, j; bool pair = false; for (i=0; i