-
Notifications
You must be signed in to change notification settings - Fork 3
/
table.c
746 lines (648 loc) · 22.4 KB
/
table.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
#include "holdem.h"
#include "table.h"
table_t *g_tables = NULL;
int g_num_tables = 0;
static struct timeval _timeout_minute = {60, 0};
table_t *table_create()
{
int i;
table_t *table;
player_t *players;
if (g_num_tables >= MAX_TABLES) {
return NULL;
}
table = (table_t *)malloc(sizeof(table_t));
if (table == NULL) {
return NULL;
}
memset(table, 0, sizeof(table_t));
players = (player_t *)malloc(TABLE_MAX_PLAYERS * sizeof(player_t));
if (players == NULL) {
return NULL;
}
memset(players, 0, TABLE_MAX_PLAYERS * sizeof(player_t));
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
table->players[i] = players + i;
}
g_num_tables++;
return table;
}
void table_destroy(table_t *table)
{
if (table) {
if (table->players[0]) {
free(table->players[0]);
}
free(table);
g_num_tables--;
}
}
void table_prepare(table_t *table)
{
int i;
table->pot = 0;
table->bet = 0;
table->minimum_bet = 100;
table->minimum_raise = 100;
table->num_cards = 0;
table->num_active = 0;
table->num_all_in = 0;
table->num_folded = 0;
table->pot_count = 0;
table->turn = -1;
table->action_mask = 0;
init_deck(&(table->deck));
table_clear_timeout(table);
memset(table->side_pots, 0, sizeof(table->side_pots));
memset(table->community_cards, 0, sizeof(table->community_cards));
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
table->players[i]->bet = 0;
table->players[i]->talked = 0;
table->players[i]->rank.score = 0;
table->players[i]->pot_offset = 0;
if (table->players[i]->user) {
if (table->players[i]->chips < table->minimum_bet && table->players[i]->user->money > 10000 ) {
player_buy_chips(table->players[i], 10000);
}
table->players[i]->state = PLAYER_STATE_WAITING;
if (table->players[i]->chips >= table->minimum_bet) {
table->num_available++;
}
} else {
table->players[i]->state = PLAYER_STATE_EMPTY;
}
}
table->state = TABLE_STATE_WAITING;
}
void table_pre_flop(table_t *table)
{
int i;
if (table->num_available < MIN_PLAYERS) {
broadcast(table, "not enough players to start game: %d", table->num_available);
return;
}
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
if (table->players[i]->state == PLAYER_STATE_WAITING
&& table->players[i]->chips >= table->minimum_bet) {
table->players[i]->state = PLAYER_STATE_ACTIVE;
table->players[i]->hand_cards[0] = get_card(&table->deck);
table->players[i]->hand_cards[1] = get_card(&table->deck);
table->num_active++;
send_msg(table->players[i]->user, "[PRE_FLOP] %s, %s",
card_to_string(table->players[i]->hand_cards[0]),
card_to_string(table->players[i]->hand_cards[1]));
}
}
// dealer move next
table->dealer = next_player(table, table->dealer);
// small blind
table->small_blind = next_player(table, table->dealer);
table->players[table->small_blind]->chips -= (table->minimum_bet >> 1);
table->players[table->small_blind]->bet += (table->minimum_bet >> 1);
broadcast(table, "player %d bet %d", table->small_blind, table->players[table->small_blind]->bet);
// big blind
table->big_blind = next_player(table, table->small_blind);
table->players[table->big_blind]->chips -= table->minimum_bet;
table->players[table->big_blind]->bet += table->minimum_bet;
broadcast(table, "player %d raise to %d", table->big_blind, table->players[table->big_blind]->bet);
// prepare table
table->bet = table->minimum_bet;
table->turn = next_player(table, table->big_blind);
table->action_mask = ACTION_FOLD | ACTION_ALL_IN | ACTION_CALL | ACTION_RAISE;
table_reset_timeout(table);
table->state = TABLE_STATE_PREFLOP;
report_table(table);
}
void table_flop(table_t *table)
{
int i;
table->community_cards[table->num_cards++] = get_card(&table->deck);
table->community_cards[table->num_cards++] = get_card(&table->deck);
table->community_cards[table->num_cards++] = get_card(&table->deck);
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
if(table->players[i]->state == PLAYER_STATE_ACTIVE) {
table->players[i]->talked = 0;
}
}
broadcast(table, "[FLOP] %s, %s, %s",
card_to_string(table->community_cards[0]),
card_to_string(table->community_cards[1]),
card_to_string(table->community_cards[2]));
table->state = TABLE_STATE_FLOP;
table->bet = 0;
table->minimum_bet = 100;
table->minimum_raise = 100;
table->turn = next_player(table, table->dealer);
table->action_mask = ACTION_FOLD | ACTION_ALL_IN | ACTION_CHCEK | ACTION_BET;
table_reset_timeout(table);
report_table(table);
}
void table_turn(table_t *table)
{
int i;
table->community_cards[table->num_cards++] = get_card(&table->deck);
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
if(table->players[i]->state == PLAYER_STATE_ACTIVE) {
table->players[i]->talked = 0;
}
}
broadcast(table, "[TURN] %s %s %s %s",
card_to_string(table->community_cards[0]),
card_to_string(table->community_cards[1]),
card_to_string(table->community_cards[2]),
card_to_string(table->community_cards[3]));
table->state = TABLE_STATE_TURN;
table->bet = 0;
table->minimum_bet = 100;
table->minimum_raise = 100;
table->turn = next_player(table, table->dealer);
table->action_mask = ACTION_FOLD | ACTION_ALL_IN | ACTION_CHCEK | ACTION_BET;
table_reset_timeout(table);
report_table(table);
}
void table_river(table_t *table)
{
int i;
table->community_cards[table->num_cards++] = get_card(&table->deck);
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
if(table->players[i]->state == PLAYER_STATE_ACTIVE) {
table->players[i]->talked = 0;
}
}
broadcast(table, "[RIVER] %s %s %s %s %s",
card_to_string(table->community_cards[0]),
card_to_string(table->community_cards[1]),
card_to_string(table->community_cards[2]),
card_to_string(table->community_cards[3]),
card_to_string(table->community_cards[4]));
table->state = TABLE_STATE_RIVER;
table->bet = 0;
table->minimum_bet = 100;
table->minimum_raise = 100;
table->turn = next_player(table, table->dealer);
table->action_mask = ACTION_FOLD | ACTION_ALL_IN | ACTION_CHCEK | ACTION_BET;
table_reset_timeout(table);
report_table(table);
}
int cmp_by_rank(const void *a, const void *b)
{
player_t **x = (player_t **)a, **y = (player_t **)b;
return (*y)->rank.score - (*x)->rank.score;
}
void table_start(table_t *table)
{
table_prepare(table);
table_switch(table);
}
void table_finish(table_t *table)
{
int i, j, k, l, possible_winners_count, chips;
int pot_share_count[TABLE_MAX_PLAYERS];
player_t *possible_winners[TABLE_MAX_PLAYERS];
char buffer[1024];
// collect main pot to side pots
table->side_pots[table->pot_count++] = table->pot;
table->pot = 0;
// if only one player left
if (table->num_active + table->num_all_in == 1) {
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
if (table->players[i]->state == PLAYER_STATE_ACTIVE || table->players[i]->state == PLAYER_STATE_ALL_IN) {
for (chips = 0, j = 0; j < table->pot_count; j++) {
chips += table->side_pots[j];
table->side_pots[j] = 0;
}
broadcast(table, "player %d wins %d", i, chips);
table->players[i]->chips += chips;
report_table(table);
table_prepare(table);
return;
}
}
err_quit("no winner");
}
// fill community cards
while (table->num_cards < 5) {
table->community_cards[table->num_cards++] = get_card(&table->deck);
}
// calc ranks & put players to possible winners
for (i = 0, possible_winners_count = 0; i < TABLE_MAX_PLAYERS; i++) {
if (table->players[i]->state == PLAYER_STATE_ACTIVE || table->players[i]->state == PLAYER_STATE_ALL_IN) {
if (table->players[i]->state == PLAYER_STATE_ACTIVE) {
table->players[i]->pot_offset = table->pot_count;
}
for (j = 0; j < 5; j++) {
table->players[i]->hand_cards[j + 2] = table->community_cards[j];
}
table->players[i]->rank = calc_rank(table->players[i]->hand_cards);
hand_to_string(table->players[i]->hand_cards, table->players[i]->rank, buffer, sizeof(buffer));
broadcast(table, "player %d's cards is %s, %s. rank is [%s], hand is %s, score is %d",
i, card_to_string(table->players[i]->hand_cards[0]), card_to_string(table->players[i]->hand_cards[1]),
level_to_string(GET_RANK(table->players[i]->rank.score)), buffer, table->players[i]->rank.score);
possible_winners[possible_winners_count++] = table->players[i];
}
}
// sort by rank TODO equal
qsort(possible_winners, possible_winners_count, sizeof(player_t*), cmp_by_rank);
// distribute the pots to winners
for (i = 0; i < possible_winners_count; i = j) {
// we may have more than one winners with the same rank&score
for (j = i + 1; j < possible_winners_count && possible_winners[j]->rank.score == possible_winners[i]->rank.score; j++);
memset(pot_share_count, 0, sizeof pot_share_count);
for (k = i; k < j; k++) {
for (l = 0; l < possible_winners[k]->pot_offset; l++) {
pot_share_count[l]++;
}
}
for (k = i; k < j; k++) {
for (chips = 0, l = 0; l < possible_winners[k]->pot_offset; l++) {
chips += table->side_pots[l] / pot_share_count[l];
table->side_pots[l] -= table->side_pots[l] / pot_share_count[l];
}
possible_winners[k]->chips += chips;
broadcast(table, "player %d wins %d", possible_winners[k] - table->players[0], chips);
}
}
report_table(table);
table_prepare(table);
}
inline void table_init_timeout(table_t *table)
{
table->ev_timeout = event_new(table->base, -1, 0, timeoutcb, table);
}
inline void table_reset_timeout(table_t *table)
{
event_add(table->ev_timeout, &_timeout_minute);
}
inline void table_clear_timeout(table_t *table)
{
event_del(table->ev_timeout);
}
int action_to_string(action_t mask, char *buffer, int size)
{
int offset = 0;
buffer[offset++] = '[';
if (mask & ACTION_BET) offset += snprintf(buffer + offset, size - offset, "bet|");
if (mask & ACTION_RAISE) offset += snprintf(buffer + offset, size - offset, "raise|");
if (mask & ACTION_CALL) offset += snprintf(buffer + offset, size - offset, "call|");
if (mask & ACTION_CHCEK) offset += snprintf(buffer + offset, size - offset, "check|");
if (mask & ACTION_FOLD) offset += snprintf(buffer + offset, size - offset, "fold|");
if (mask & ACTION_ALL_IN) offset += snprintf(buffer + offset, size - offset, "all_in|");
if (offset > 1) offset--;
offset += snprintf(buffer + offset, size - offset, "]");
return offset;
}
void broadcast(table_t *table, const char *fmt, ...)
{
int i;
va_list ap;
va_start(ap, fmt);
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
if (table->players[i]->user) {
send_msgv(table->players[i]->user, fmt, ap);
}
}
va_end(ap);
}
int player_join(table_t *table, user_t *user)
{
int i;
player_t *player;
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
if (table->players[i]->user == NULL && table->players[i]->state == PLAYER_STATE_EMPTY) {
player = table->players[i];
player->user = user;
user->table = table;
user->index = i;
user->state |= USER_STATE_TABLE;
if (player->chips < table->minimum_bet && player->user->money > 10000 ) {
player_buy_chips(player, 10000);
}
broadcast(table, "player %d %s joined chips %d", i, user->name, player->chips);
return TEXAS_RET_SUCCESS;
}
}
return TEXAS_RET_MAX_PLAYER;
}
int player_quit(user_t *user)
{
table_t *table = user->table;
int index = user->index;
player_t *player = table->players[index];
if (table->state > TABLE_STATE_WAITING && player->state == PLAYER_STATE_ACTIVE && table->turn == user->index) {
handle_action(table, table->turn, ACTION_FOLD, 0);
}
if (player->chips > 0) {
user->money += player->chips;
if (user_save_money(user) < 0) {
fprintf(stderr, "save money failure\n");
}
player->chips = 0;
}
player->user = NULL;
user->table = NULL;
user->index = -1;
user->state &= ~USER_STATE_TABLE;
broadcast(table, "player %d quit", index);
return TEXAS_RET_SUCCESS;
}
int next_player(table_t *table, int index)
{
int i, next;
for (i = 1; i < TABLE_MAX_PLAYERS; i++) {
next = (index + i) % TABLE_MAX_PLAYERS;
if (table->players[next]->state == PLAYER_STATE_ACTIVE) {
return next;
}
}
return -1;
}
int player_bet(table_t *table, int index, int bet)
{
player_t *player = table->players[index];
assert(player->bet == 0);
assert(table->bet == 0);
if (bet > player->chips) {
return TEXAS_RET_LOW_POT;
}
if (bet < table->minimum_bet) {
return TEXAS_RET_MIN_BET;
}
player->chips -= bet;
player->bet += bet;
table->bet = player->bet;
table->minimum_raise = table->bet;
player->talked = 1;
return TEXAS_RET_SUCCESS;
}
int player_raise(table_t *table, int index, int raise)
{
player_t *player = table->players[index];
int diff = table->bet - player->bet;
assert(player->chips >= diff + table->minimum_raise);
if (raise < table->minimum_raise) {
return TEXAS_RET_MIN_BET;
}
if (raise + diff > player->chips) {
return TEXAS_RET_LOW_POT;
}
player->chips -= (raise + diff);
player->bet += (raise + diff);
table->bet = player->bet;
table->minimum_raise = raise;
player->talked = 1;
return TEXAS_RET_SUCCESS;
}
int player_call(table_t *table, int index)
{
player_t *player = table->players[index];
int diff = table->bet - player->bet;
assert(player->chips >= diff);
player->chips -= diff;
player->bet += diff;
player->talked = 1;
return TEXAS_RET_SUCCESS;
}
int player_all_in(table_t *table, int index)
{
player_t *player = table->players[index];
int diff;
player->bet += player->chips;
player->chips = 0;
if (player->bet > table->bet) {
diff = player->bet - table->bet;
table->bet = player->bet;
if (diff > table->minimum_raise) {
table->minimum_raise = diff;
}
}
player->talked = 1;
table->num_all_in++;
table->num_active--;
player->state = PLAYER_STATE_ALL_IN;
return TEXAS_RET_SUCCESS;
}
int player_fold(table_t *table, int index)
{
player_t *player = table->players[index];
table->num_active--;
table->num_folded++;
player->talked = 1;
player->state = PLAYER_STATE_FOLDED;
return TEXAS_RET_SUCCESS;
}
int player_check(table_t *table, int index)
{
player_t *player = table->players[index];
assert(table->bet == player->bet && player->talked == 0);
player->talked = 1;
return TEXAS_RET_SUCCESS;
}
int handle_action(table_t *table, int index, action_t action, int value)
{
player_t *player = table->players[index];
player_t *player_next;
int next;
// check action
if (!(action & table->action_mask)) {
send_msg(player->user, "invalid action");
return TEXAS_RET_ACTION;
}
switch (action) {
case ACTION_BET:
if (player_bet(table, index, value) != TEXAS_RET_SUCCESS) {
send_msg(player->user, "bet failed");
return TEXAS_RET_FAILURE;
}
broadcast(table, "player %d bet %d", index, value);
break;
case ACTION_RAISE:
if (player_raise(table, index, value) != TEXAS_RET_SUCCESS) {
send_msg(player->user, "bet failed");
return TEXAS_RET_FAILURE;
}
broadcast(table, "player %d raise %d", index, value);
break;
case ACTION_CALL:
if (player_call(table, index) != TEXAS_RET_SUCCESS) {
send_msg(player->user, "call failed");
return TEXAS_RET_FAILURE;
}
broadcast(table, "player %d call", index);
break;
case ACTION_CHCEK:
if (player_check(table, index) != TEXAS_RET_SUCCESS) {
send_msg(player->user, "check failed");
return TEXAS_RET_FAILURE;
}
broadcast(table, "player %d check", index);
break;
case ACTION_ALL_IN:
if (player_all_in(table, index) != TEXAS_RET_SUCCESS) {
send_msg(player->user, "all in failed");
return TEXAS_RET_FAILURE;
}
broadcast(table, "player %d check", index);
break;
case ACTION_FOLD:
if (player_fold(table, index) != TEXAS_RET_SUCCESS) {
send_msg(player->user, "fold failed");
return TEXAS_RET_FAILURE;
}
broadcast(table, "player %d fold", index);
break;
default:
err_quit("default");
break;
}
// generate available actions
next = next_player(table, table->turn);
if ((table->num_active == 1 && table->num_all_in == 0) || next < 0) {
table_process(table);
table_finish(table);
return TEXAS_RET_SUCCESS;
}
player_next = table->players[next];
assert(player_next);
if (player_next->bet == table->bet && player_next->talked == 1) {
table_process(table);
table_switch(table);
return TEXAS_RET_SUCCESS;
}
table->action_mask = 0;
table->action_mask |= ACTION_FOLD;
if (player_next->chips > 0) {
table->action_mask |= ACTION_ALL_IN;
}
if (table->bet == player_next->bet && player_next->talked == 0) {
table->action_mask |= ACTION_CHCEK;
}
if (table->bet == 0) {
table->action_mask |= ACTION_BET;
}
if (player_next->bet < table->bet && player_next->chips + player_next->bet > table->bet) {
table->action_mask |= ACTION_CALL;
}
if (table->bet > 0 && player_next->chips + player_next->bet >= table->bet + table->minimum_raise) {
table->action_mask |= ACTION_RAISE;
}
table->turn = next;
report_table(table);
if (player_next->user == NULL) {
return handle_action(table, next, ACTION_FOLD, 0);
}
return TEXAS_RET_SUCCESS;
}
int cmp_by_bet(const void *a, const void *b)
{
player_t **x = (player_t **)a, **y = (player_t **)b;
return (((*x)->bet) - ((*y)->bet));
}
int table_process(table_t *table)
{
player_t *all_in_players[TABLE_MAX_PLAYERS];
int i, j, all_in_players_count = 0, bet, side_pot;
// remove left player
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
if (table->players[i]->user == NULL) {
switch (table->players[i]->state) {
case PLAYER_STATE_ALL_IN:
// TODO all in && quit
break;
case PLAYER_STATE_ACTIVE:
err_quit("active");
case PLAYER_STATE_FOLDED:
table->num_folded--;
case PLAYER_STATE_EMPTY:
case PLAYER_STATE_WAITING:
table->players[i]->state = PLAYER_STATE_EMPTY;
break;
}
}
}
// find all in players this round
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
if (table->players[i]->state == PLAYER_STATE_ALL_IN && table->players[i]->bet > 0) {
all_in_players[all_in_players_count++] = table->players[i];
}
}
if (all_in_players_count > 0) {
// sort
qsort(all_in_players, all_in_players_count, sizeof(player_t *), cmp_by_bet);
// calc side pots
for (i = 0; i < all_in_players_count; i++) {
bet = all_in_players[i]->bet;
for (j = 0, side_pot = 0; j < TABLE_MAX_PLAYERS; j++) {
if (table->players[j]->bet > 0) {
if (table->players[j]->bet < bet) {
side_pot += table->players[j]->bet;
table->players[j]->bet = 0;
} else {
side_pot += bet;
table->players[j]->bet -= bet;
}
}
}
side_pot += table->pot;
table->pot = 0;
table->side_pots[table->pot_count] = side_pot;
all_in_players[i]->pot_offset = ++(table->pot_count);
}
}
// collect bets to table's main pot
for (i = 0; i < TABLE_MAX_PLAYERS; i++) {
if (table->players[i]->bet > 0) {
table->pot += table->players[i]->bet;
table->players[i]->bet = 0;
}
}
return TEXAS_RET_SUCCESS;
}
int table_switch(table_t *table)
{
switch (table->state) {
case TABLE_STATE_WAITING:
table_pre_flop(table);
break;
case TABLE_STATE_PREFLOP:
table_flop(table);
break;
case TABLE_STATE_FLOP:
table_turn(table);
break;
case TABLE_STATE_TURN:
table_river(table);
break;
case TABLE_STATE_RIVER:
table_finish(table);
break;
default:
break;
}
return TEXAS_RET_SUCCESS;
}
int player_buy_chips(player_t *player, int chips)
{
assert(player->user);
if (player->user->money < chips) {
return -1;
}
player->user->money -= chips;
player->chips += chips;
if (user_save_money(player->user) < 0) {
return -1;
}
return 0;
}
void report_table(table_t *table)
{
char buffer[1024], mask_buffer[1024];
action_to_string(table->action_mask, mask_buffer, sizeof(mask_buffer));
snprintf(buffer, sizeof(buffer), "turn player %d bet %d pot %d mask %s",
table->turn, table->bet, table->pot, mask_buffer);
broadcast(table, buffer);
}
int table_chat(table_t *table, int index, const char *msg)
{
broadcast(table, "player %d says: %s", index, msg);
return 0;
}