Skip to content

Commit

Permalink
REmove panic
Browse files Browse the repository at this point in the history
  • Loading branch information
bkushigian committed Oct 31, 2024
1 parent 7158131 commit 490f12a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn main() -> Result<(), String> {

// confirm that "7s" can be dealt
let card_7s = card_from_str("7s").unwrap();
assert!(game.possible_cards() & (1 << card_7s) != 0);
assert!(game.possible_cards()? & (1 << card_7s) != 0);

// deal "7s"
game.play(card_7s as usize)?;
Expand Down
10 changes: 5 additions & 5 deletions src/game/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ impl PostFlopGame {
/// The returned value is a 64-bit integer.
/// The `i`-th bit is set to 1 if the card of ID `i` can be dealt (see [`Card`] for encoding).
/// If the current node is not a chance node, `0` is returned.
pub fn possible_cards(&self) -> u64 {
pub fn possible_cards(&self) -> Result<u64, String> {
if self.state <= State::Uninitialized {
panic!("Game is not successfully initialized");
return Err("Game is not successfully initialized".to_string());
}

if !self.is_chance_node() {
return 0;
return Ok(0);
}

let flop = self.card_config.flop;
Expand Down Expand Up @@ -223,7 +223,7 @@ impl PostFlopGame {
}
}

((1 << 52) - 1) ^ dead_mask
Ok(((1 << 52) - 1) ^ dead_mask)
}

/// Returns the current player (0 = OOP, 1 = IP).
Expand Down Expand Up @@ -291,7 +291,7 @@ impl PostFlopGame {
}

let actual_card = if action == usize::MAX {
self.possible_cards().trailing_zeros() as Card
self.possible_cards()?.trailing_zeros() as Card
} else {
action as Card
};
Expand Down

0 comments on commit 490f12a

Please sign in to comment.