• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
daily pastebin goal
31%
SHARE
TWEET

# Untitled

a guest Feb 12th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. class Poker
2. {
3.     int flush;          //Whether It's a flush or not.
4.     int straight;       //Whether It's a straight, if so highest card val, else zero.
5.     int pair;           //Pair Value = (highest_pair_val)*14^n +
6.                         //(next_highest_pair_val)*14^n-1 and so on.
7.
8.     int three;          //Three value = highest_three_kind_value.
9.     int four;           //Same as above.
10.     int highval;        //High Card Value = (highest_card_value)*13^n +
11.                         //(next_highest_card)*13^n-1 and so on.
12.     public:
13.     void setpoker(string &cards);     //Fill the contents of the object based on the input string.
14.     int winorloose(Poker &b);         //Determines whether current object wins or looses.
15. };
16.
17. void Poker::setpoker(string &a)
18. {
19.     vector <int> hands, cval;
20.     hands.assign(4, 0);    //each array element gives the number of cards of
21.                            //these type: club, or, diamond, or, heart, or spade.
22.
23.     cval.assign(13, 0);    //each array element gives the number of cards of
24.                            //having value: 2, 3 ...
25.                            //(indexing starts at 0, so 2 is at 0 and Ace is at 12)
26.
27.     /*
28.     **Code of filling of hands and cval comes here.
29.     */
30.
31.     flush = 0; straight = 0; highval = 0;
32.     three = 0; pair = 0; four = 0;
33.
34.     for (int i = 0; i < 4; i++)
35.         if (hands[i] == 5)
36.             flush = 1;
37.
38.     int stchk = 0;        //checks how many cards we have seen straight yet.
39.     int HN = 1, PN = 1;
40.     for (int i = 0; i < 13; i++)
41.     {
42.         if (cval[i] > 0) {
43.             highval += i*HN;
44.             HN *= 13;
45.             if (cval[i] == 2) {
46.                 pair += (i+1)*PN;
47.                 PN *= 14;        //I chosed it to be 14 to be able to distinguish
48.                                  //between pair of 2(at cval[0]) and no pair.
49.             }
50.             if (cval[i] == 3)
51.                 three = i;
52.             if (cval[i] == 4)
53.                 four == i;
54.             if (stchk == 4)
55.                 straight = i;
56.             else
57.                 stchk++;
58.         }
59.         else
60.             stchk = 0;
61.
62.     }
63. }
64.
65. int Poker::winorloose(Poker &b)
66. {
67.     //royal flush
68.     if (flush && straight == 12)
69.         return 1;
70.     if (b.flush && b.straight == 12)
71.         return 0;
72.
73.     //straight flush
74.     if (flush && straight)
75.         if (flush > b.flush || straight > b.straight)
76.             return 1;
77.
78.     if (b.flush && b.straight)
79.         if (b.flush > flush || b.straight > straight)
80.             return 0;
81.     //four of kind
82.     if (four > b.four)
83.         return 1;
84.     if (b.four > four)
85.         return 0;
86.
87.     //full house
88.     if (three && pair)
89.         if (!(b.three && b.pair) || three > b.three)
90.             return 1;
91.
92.     if (b.three && b.pair)
93.         if (!(three && pair) || b.three > three)
94.             return 0;
95.
96.     //Flush
97.     if (flush > b.flush)
98.         return 1;
99.     if (b.flush > flush)
100.         return 0;
101.
102.     //straight
103.     if (straight > b.straight)
104.         return 1;
105.     if (b.straight > straight)
106.         return 0;
107.
108.     //three of kind
109.     if (three > b.three)
110.         return 1;
111.     if (b.three > three)
112.         return 0;
113.
114.     //pair
115.     if (pair > b.pair)
116.         return 1;
117.     if (b.pair > pair)
118.         return 0;
119.
120.     //highest value card
121.     if (highval > b.highval)
122.         return 1;
123.     if (b.highval > highval)
124.         return 0;
125. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top