-
Notifications
You must be signed in to change notification settings - Fork 3
/
table.h
131 lines (108 loc) · 3.04 KB
/
table.h
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
#ifndef _TABLE_H
#define _TABLE_H
#include "uthash.h"
#include "card.h"
#include "hand.h"
#include "user.h"
#define TABLE_MAX_PLAYERS 10
#define MIN_PLAYERS 2
#define MAX_TABLES 1024
typedef enum action_e {
ACTION_BET = 0x01,
ACTION_RAISE = 0x02,
ACTION_CALL = 0x04,
ACTION_CHCEK = 0x08,
ACTION_FOLD = 0x10,
ACTION_ALL_IN = 0x20,
} action_t;
int action_to_string(action_t mask, char *buffer, int size);
typedef enum player_state_e
{
PLAYER_STATE_EMPTY = 0,
PLAYER_STATE_WAITING,
PLAYER_STATE_ACTIVE,
PLAYER_STATE_ALL_IN,
PLAYER_STATE_FOLDED,
} player_state_t;
typedef struct player_s {
int bet;
int chips;
int talked;
int pot_offset;
player_state_t state;
card_t hand_cards[7];
hand_rank_t rank;
user_t *user;
} player_t;
typedef enum table_state_e {
TABLE_STATE_WAITING = 0,
TABLE_STATE_PREFLOP,
TABLE_STATE_FLOP,
TABLE_STATE_TURN,
TABLE_STATE_RIVER,
} table_state_t;
typedef struct table_s {
char name[MAX_NAME];
table_state_t state;
deck_t deck;
card_t community_cards[5];
int num_cards;
player_t *players[TABLE_MAX_PLAYERS];
int num_all_in;
int num_folded;
int num_active;
int num_available;
int dealer;
int small_blind;
int big_blind;
int turn;
unsigned int action_mask;
int minimum_bet;
int minimum_raise;
int bet;
int pot;
int side_pots[TABLE_MAX_PLAYERS];
int pot_count;
struct event_base *base;
struct event *ev_timeout;
UT_hash_handle hh;
} table_t;
#define current_player(t) ((t)->players[(t)->turn])
#define CHECK_IN_TURN(user) do {\
if (((user)->index) != (user)->table->turn) {\
send_msg((user), "you are not in turn");\
return -1;\
}\
} while(0)
int player_join(table_t *table, user_t *user);
int player_quit(user_t *user);
int next_player(table_t *table, int index);
int player_bet(table_t *table, int index, int bet);
int player_raise(table_t *table, int index, int raise);
int player_call(table_t *table, int index);
int player_fold(table_t *table, int index);
int player_check(table_t *table, int index);
int player_all_in(table_t *table, int index);
table_t *table_create();
void tatle_destroy(table_t *table);
void table_prepare(table_t *table);
void table_pre_flop(table_t *table);
void table_flop(table_t *table);
void table_turn(table_t *table);
void table_river(table_t *table);
void table_start(table_t *table);
void table_finish(table_t *table);
void table_init_timeout(table_t *table);
void table_reset_timeout(table_t *table);
void table_clear_timeout(table_t *table);
int handle_action(table_t *table, int index, action_t action, int value);
int table_process(table_t *table);
int table_switch(table_t *table);
void broadcast(table_t *table, const char *fmt, ...);
void timeoutcb(evutil_socket_t fd, short events, void *arg);
void report_table(table_t *table);
int player_buy_chips(player_t *player, int chips);
int table_chat(table_t *table, int index, const char *msg);
extern table_t *g_tables;
extern int g_num_tables;
#endif