-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
157 lines (108 loc) · 3.47 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "poker.h"
/*******************************************************************
Function : rankHand
Process : Ranks the hand to determine its type (ie Straight)
Build hand repetition list (singles, pairs, trips, quads)
Switch on the number of unique card number elements in hand
If we have two items in our map,
we have either a full house of a four of a kind
If we have four cards of same number,
we have a four of a kind
Else, it is a full house
If we have three items in our map,
we have either a two pair or a three of a kind
If we have three cards of same number,
we have three of a kind
Else, it is two pair
If we have four items in our map, we have one pair
If we have five items in our map, we need to look further
Check for straight flush, flush, or straight
If this is a low ace straight,
we need to fix the sort order
Check for a flush
Check for a straight
If this is a low ace straight,
we need to fix the sort order
Else, we have a high card
Notes : None
https://github.com/donnemartin/poker/blob/master/src/HandRanker.cpp
*/
#define SPADE_B (wint_t)9824
#define HEART_B (wint_t)9829
#define DIAMOND_B (wint_t)9830
#define CLUB_B (wint_t)9827
#define SPADE_W (wint_t)9828
#define HEART_W (wint_t)9825
#define DIAMOND_W (wint_t)9826
#define CLUB_W (wint_t)9831
int deck_top = 51; // deck[deck_top] is the top card of the deck
community_cards com_cards; // the community cards
int sb = 1; // small blind amount (in units of chips)
int bb = 2; // big blind amount
int button_player; // which player is button
int sb_player; // which player is sb
int bb_player; // which player is bb
int init_stack = 100; // initial stack (chips) of each player
int pot = 0; // how many chips are in the pot currently
int main(int argc, char const *argv[]) {
srand(time(NULL));
setlocale(LC_ALL, "");
int i;
int num_of_players = 4;
player players[num_of_players];
initialize_players(players, num_of_players);
card deck[deck_top+1];
initialize_deck(deck);
int player_turn = 0;
int betting = 0;
while (players_still_playing(players, num_of_players) >= 2) {
com_cards.num_of_cards = 0;
for (i = 0; i < num_of_players; i++) {
printf("p%d : chips %d\n", i+1, players[i].chips);
} // for
shuffle_deck(deck);
give_cards(players, num_of_players, deck);
getchar();
for (i = 0; i < num_of_players; i++) {
if (is_player_still_playing(players[i])) {
clear_screen();
printf("p%d: ", i+1);
print_player_hand(players[i]);
getchar();
} // if
} // for
clear_screen();
// BETTING PHASE
print_button_sb_bb_players(player_turn, players, num_of_players);
players[sb_player].chips -= sb;
players[sb_player].chips += sb;
players[bb_player].chips -= bb;
players[bb_player].chips += bb;
pot += sb + bb;
getchar();
clear_screen();
flop_cards(deck);
print_community_cards(); // show flop
getchar();
turn_cards(deck);
print_community_cards(); // show turn
getchar();
river_cards(deck);
print_community_cards(); // show river
getchar();
for (i = 0; i < num_of_players; i++) { // show each player's cards
printf("p%d: ", i+1);
print_player_hand(players[i]);
} // for
getchar();
deck_top = 51;
player_turn = next_avail_player(player_turn, players, num_of_players);
clear_screen();
} // while
return 0;
}