Skip to content

Commit

Permalink
Merge pull request #46 from winstonrc/casino-poker-patch0
Browse files Browse the repository at this point in the history
Casino poker patch0
  • Loading branch information
winstonrc authored Jul 15, 2024
2 parents 5200dc2 + 3af8fb9 commit e6950df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/casino_poker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ keywords = ["poker", "casino", "texas-hold-em", "cards", "game"]
categories = ["game-development"]

[dependencies]
casino_cards = { version = "0.1.0", path = "../casino_cards" }
casino_cards = { version = "0.1.1", path = "../casino_cards" }
strum = { version = "0.26.2", features = ["derive"] }
uuid = { version = "1.8.0", features = ["v4"] }
32 changes: 16 additions & 16 deletions crates/casino_poker/src/games/texas_hold_em.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ use crate::player::Player;
///
/// The game currently defaults to no-limit.
pub struct TexasHoldEm {
minimum_table_buy_in_chips_amount: u32,
maximum_players_count: usize,
pub game_over: bool,
deck: Deck,
players: HashMap<Uuid, Player>,
pub seats: Vec<Uuid>, // todo: make private after testing is complete
small_blind_amount: u32,
big_blind_amount: u32,
main_pot: Pot,
side_pots: Vec<Pot>,
minimum_table_buy_in_chips_amount: u32,
maximum_players_count: usize,
small_blind_amount: u32,
big_blind_amount: u32,
}

impl TexasHoldEm {
Expand All @@ -34,16 +34,16 @@ impl TexasHoldEm {
big_blind_amount: u32,
) -> Self {
Self {
minimum_table_buy_in_chips_amount,
maximum_players_count,
game_over: false,
deck: Deck::new(),
players: HashMap::new(),
seats: Vec::new(),
small_blind_amount,
big_blind_amount,
main_pot: Pot::new(0, HashMap::new()),
side_pots: Vec::new(),
minimum_table_buy_in_chips_amount,
maximum_players_count,
small_blind_amount,
big_blind_amount,
}
}

Expand Down Expand Up @@ -88,25 +88,25 @@ impl TexasHoldEm {
}

/// Remove a player from the game.
pub fn remove_player(&mut self, player: &mut Player) -> Option<Player> {
pub fn remove_player(&mut self, player_identifier: &Uuid) -> Option<Player> {
if self.players.is_empty() {
eprintln!("Unable to remove player. The table is empty.");
return None;
}

if self.players.get(&player.identifier).is_none() {
if self.players.get(&player_identifier).is_none() {
eprintln!(
"Unable to remove player. {} is not at the table.",
player.name
"Unable to remove player. The identifier {} is not at the table.",
player_identifier
);
return None;
} else {
// Remove player from seat
self.seats.retain(|x| *x != player.identifier);
self.seats.retain(|x| x != player_identifier);
}

// Remove and return player
self.players.remove(&player.identifier)
self.players.remove(&player_identifier)
}

/// Play a tournament consisting of multiple rounds.
Expand All @@ -125,13 +125,13 @@ impl TexasHoldEm {
}

pub fn remove_losers(&mut self) {
for (_, mut player) in self.players.clone() {
for (identifier, player) in self.players.clone() {
if player.chips == 0 {
println!(
"{} is out of chips and was removed from the game.",
player.name
);
self.remove_player(&mut player);
self.remove_player(&identifier);
}
}
}
Expand Down

0 comments on commit e6950df

Please sign in to comment.