Skip to content

Commit 8ad0bf2

Browse files
author
DogLooksGood
committed
Add omaha cash
1 parent 05adefb commit 8ad0bf2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+603
-233
lines changed

Cargo.lock

Lines changed: 23 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"mtt-table",
77
"mtt-base",
88
"cash",
9+
"omaha-cash",
910
"ltmtt",
1011
]
1112

Justfile

Lines changed: 0 additions & 18 deletions
This file was deleted.

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.PHONY: release-all build-race-omaha-cash
2+
3+
CRATES = race-omaha-cash race-holdem-cash race-holdem-mtt-table race-holdem-mtt
4+
5+
all: $(CRATES)
6+
7+
define BUILD_template
8+
.PHONY: $(1)
9+
$(1):
10+
cargo build -r --target wasm32-unknown-unknown -p $(1)
11+
wasm-opt -Oz target/wasm32-unknown-unknown/release/$$(subst -,_,$(1)).wasm -o target/$$(subst -,_,$(1)).wasm
12+
endef
13+
14+
$(foreach crate,$(CRATES), $(eval $(call BUILD_template,$(crate))))

base/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "race-holdem-base"
2+
name = "race-poker-base"
33
version = "0.1.0"
44
edition = "2021"
55

base/src/errors.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ custom_err!(not_the_acting_player_to_call);
3333
custom_err!(not_the_acting_player);
3434
custom_err!(player_cant_bet);
3535
custom_err!(player_cant_call);
36-
custom_err!(bet_amonut_is_too_small);
36+
custom_err!(bet_amount_is_too_small);
3737
custom_err!(raise_amount_is_too_small);
38+
custom_err!(raise_exceeds_pot_limit);
39+
custom_err!(bet_exceeds_pot_limit);
3840
custom_err!(player_already_betted);
3941
custom_err!(player_cant_check);
4042
custom_err!(player_cant_raise);

base/src/game.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ impl<V: GameVariant> PokerGame<V> {
701701

702702
/// Reveal community cards according to current street
703703
pub fn update_board(&mut self, effect: &mut Effect) -> Result<(), HandleError> {
704-
let players_cnt = self.count_ingame_players() * 2;
704+
let players_cnt = self.count_ingame_players() * self.variant.hole_card_count();
705705
match self.street {
706706
Street::Flop => {
707707
effect.reveal(
@@ -1081,7 +1081,7 @@ impl<V: GameVariant> PokerGame<V> {
10811081
}
10821082
}
10831083

1084-
let board_start = self.hand_index_map.len() * 2;
1084+
let board_start = self.count_ingame_players() * self.variant.hole_card_count();
10851085
effect.reveal(
10861086
self.deck_random_id,
10871087
(board_start..(board_start + 5)).collect(),
@@ -1212,10 +1212,12 @@ impl<V: GameVariant> PokerGame<V> {
12121212
return Err(errors::player_cant_bet());
12131213
}
12141214

1215-
// When bet amount is less than 1BB, only allin is allowed.
1216-
if self.bb > amount && player.chips != amount {
1217-
return Err(errors::bet_amonut_is_too_small());
1218-
}
1215+
self.variant.validate_bet_amount(
1216+
amount,
1217+
self.bb,
1218+
player.chips,
1219+
&self.pots,
1220+
)?;
12191221

12201222
let (allin, real_bet_amount) = self.take_bet(sender.clone(), amount)?;
12211223
self.set_player_acted(sender, allin)?;
@@ -1284,12 +1286,18 @@ impl<V: GameVariant> PokerGame<V> {
12841286

12851287
let betted = self.get_player_bet(sender);
12861288

1289+
let bet_sum_of_all_players = self.bet_map.values().sum::<u64>();
1290+
1291+
effect.info(format!("player.chips = {}, betted = {}, amount = {}, self.street_bet = {}, self.min_raise = {}, bet_sum_of_all_players = {}, pots = {}",
1292+
player.chips, betted, amount, self.street_bet, self.min_raise, bet_sum_of_all_players, self.pots.iter().map(|p| p.amount).sum::<u64>()));
1293+
12871294
self.variant.validate_raise_amount(
1295+
amount,
12881296
player.chips,
12891297
betted,
1290-
amount,
12911298
self.street_bet,
12921299
self.min_raise,
1300+
bet_sum_of_all_players,
12931301
&self.pots,
12941302
)?;
12951303

@@ -1767,17 +1775,24 @@ impl<V: GameVariant> GameHandler for PokerGame<V> {
17671775
}
17681776

17691777
Event::RandomnessReady { .. } => {
1778+
let hole_card_count = self.variant.hole_card_count();
1779+
17701780
for (idx, id) in self.player_order.iter().enumerate() {
1771-
effect.assign(self.deck_random_id, *id, vec![idx * 2, idx * 2 + 1])?;
1772-
self.hand_index_map.insert(*id, vec![idx * 2, idx * 2 + 1]);
1781+
let mut indices: Vec<usize> = Vec::with_capacity(hole_card_count);
1782+
for i in 0..hole_card_count {
1783+
indices.push(idx * hole_card_count + i);
1784+
}
1785+
1786+
effect.assign(self.deck_random_id, *id, indices.clone())?;
1787+
self.hand_index_map.insert(*id, indices);
17731788
}
17741789

17751790
Ok(())
17761791
}
17771792

17781793
Event::SecretsReady { .. } => match self.stage {
17791794
HoldemStage::ShareKey => {
1780-
let players_cnt = self.count_ingame_players() * 2;
1795+
let players_cnt = self.count_ingame_players() * self.variant.hole_card_count();
17811796
let board_prev_cnt = self.board.len();
17821797
self.stage = HoldemStage::Play;
17831798

base/src/holdem.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Holdem implementation for GameVariant
22

3+
use std::collections::{BTreeMap, HashMap};
34
use crate::hand_history::Showdown;
45
use crate::variant::{EvaluateHandsOutput, GameVariant};
5-
use crate::evaluator::evaluate_cards;
6+
use crate::holdem_evaluator::{PlayerHand, evaluate_cards, create_cards, compare_hands};
7+
use crate::essential::Pot;
8+
use crate::errors;
69
use race_api::prelude::*;
710

811
#[derive(BorshSerialize, BorshDeserialize, Default, Debug, PartialEq, Clone)]
@@ -17,8 +20,9 @@ impl GameVariant for HoldemVariant {
1720

1821
fn evaluate_hands(
1922
&self,
20-
board: &[&str],
21-
hole_cards: &[&str],
23+
board: &[String],
24+
hand_index_map: &BTreeMap<u64, Vec<usize>>,
25+
revealed_cards: &HashMap<usize, String>,
2226
) -> HandleResult<EvaluateHandsOutput> {
2327
// A temporary struct to hold all evaluation results before sorting
2428
struct EvalResult {
@@ -32,19 +36,20 @@ impl GameVariant for HoldemVariant {
3236

3337
// Step 1: Evaluate each player's hand and build the Showdown struct.
3438
for (&player_id, indices) in hand_index_map.iter() {
35-
let card1 = revealed.get(&indices[0]).ok_or_else(errors::first_hole_card_error)?;
36-
let card2 = revealed.get(&indices[1]).ok_or_else(errors::second_hole_card_error)?;
39+
let card1 = revealed_cards.get(&indices[0]).ok_or_else(errors::first_hole_card_error)?;
40+
let card2 = revealed_cards.get(&indices[1]).ok_or_else(errors::second_hole_card_error)?;
3741
let hole_cards = vec![card1.clone(), card2.clone()];
3842

39-
let all_cards = create_cards(board, &[card1.as_str(), card2.as_str()]);
43+
let board_cards: Vec<&str> = board.into_iter().map(|x| x.as_ref()).collect();
44+
let all_cards = create_cards(&board_cards, &[card1.as_str(), card2.as_str()]);
4045

4146
// The evaluator now returns a richer PlayerHand struct
4247
let hand = evaluate_cards(all_cards);
4348

4449
let showdown = Showdown {
4550
hole_cards,
4651
category: hand.category.clone(),
47-
picks: hand.picks.clone(),
52+
picks: hand.picks.iter().map(|x| x.to_string()).collect(),
4853
};
4954
results.push(EvalResult { player_id, hand, showdown });
5055
}
@@ -75,16 +80,33 @@ impl GameVariant for HoldemVariant {
7580
})
7681
}
7782

83+
/// Validates a bet amount
84+
fn validate_bet_amount(
85+
&self,
86+
bet_amount: u64,
87+
bb: u64,
88+
player_chips: u64,
89+
_pots: &[Pot],
90+
) -> HandleResult<()> {
91+
// The bet must meet the minimum bet requirement(1BB), unless it's an all-in.
92+
if bet_amount < bb && bet_amount != player_chips {
93+
return Err(errors::bet_amount_is_too_small());
94+
}
95+
96+
Ok(())
97+
}
98+
7899
fn validate_raise_amount(
79100
&self,
80101
player_chips: u64,
81102
betted: u64,
82103
raise_amount: u64,
83104
street_bet: u64,
84105
min_raise: u64,
85-
pots: &[Pot],
106+
_bet_sum_of_all_players: u64,
107+
_pots: &[Pot],
86108
) -> HandleResult<()> {
87-
let total_new_bet = player_bet + raise_amount;
109+
let total_new_bet = betted + raise_amount;
88110

89111
// An all-in is always a valid raise amount, even if it's less than a min-raise.
90112
if raise_amount == player_chips {

0 commit comments

Comments
 (0)