#poker #cards #card-game #game #casino #texas-hold-em

casino_poker

提供牌型排名和德州扑克游戏后端的库

6个版本

0.1.5 2024年8月14日
0.1.4 2024年8月13日
0.1.3 2024年7月22日

#269 in 游戏开发

Download history 8/week @ 2024-07-08 310/week @ 2024-07-15 151/week @ 2024-07-22 5/week @ 2024-07-29 272/week @ 2024-08-12

437 每月下载量
用于 casino_games

MPL-2.0 许可证

195KB
4K SLoC

crates.io Poker Test

casino_poker

提供牌型排名和德州扑克游戏后端的库。

注意: 此库仍在开发中。虽然更新时的稳定性是一个目标,但暂时可能偶尔会有破坏性更改。

用法

牌型排名与高牌

fn main() {
    use casino_cards::card;
    use casino_cards::card::{Card, Rank, Suit};
    use casino_poker::hand_rankings::{get_high_card_value, rank_hand, HandRank};
    let ace_of_diamonds = card!(Ace, Diamond);
    let two_of_diamonds = card!(Two, Diamond);
    let three_of_diamonds = card!(Three, Diamond);
    let four_of_diamonds = card!(Four, Diamond);
    let five_of_diamonds = card!(Five, Diamond);
    let seven_of_diamonds = card!(Seven, Diamond);
    let eight_of_diamonds = card!(Eight, Diamond);

    let cards_to_rank: Vec<Card> = vec![
        ace_of_diamonds,
        two_of_diamonds,
        three_of_diamonds,
        four_of_diamonds,
        five_of_diamonds,
        seven_of_diamonds,
        eight_of_diamonds,
    ];

    // high_card == Card { rank: Ace, suit: Diamond, face_up: true }
    let high_card = get_high_card_value(&cards_to_rank);

    // hand_rank == StraightFlush([Card { rank: Ace, suit: Diamond, face_up: true }, Card { rank: Two, suit: Diamond, face_up: true }, Card { rank: Three, suit: Diamond, face_up: true }, Card { rank: Four, suit: Diamond, face_up: true }, Card { rank: Five, suit: Diamond, face_up: true }])
    let hand_rank: HandRank = rank_hand(cards_to_rank);
}

德州扑克

use poker::games::texas_hold_em::TexasHoldEm;

const MINIMUM_TABLE_BUY_IN_CHIPS_AMOUNT: u32 = 100;
const MAXIMUM_TABLE_PLAYERS: usize = 10;
const SMALL_BLIND: u32 = 1;
const BIG_BLIND: u32 = 3;
const LIMIT: bool = false;

fn main() {
    let mut texas_hold_em_1_3_no_limit = TexasHoldEm::new(
        MINIMUM_TABLE_BUY_IN_CHIPS_AMOUNT,
        MAXIMUM_TABLE_PLAYERS,
        SMALL_BLIND,
        BIG_BLIND,
        LIMIT,
    );

    // A Player can be created without chips.
    let mut player1 = texas_hold_em_1_3_no_limit.new_player("Player 1");

    // But the Player must have the minimum_table_buy_in_chips_amount before they can be added to the table.
    player1.add_chips(100);

    // add_player() returns a Result, which can be handled.
    match texas_hold_em_1_3_no_limit.add_player(player1) {
        Ok(()) => {}
        Err("The player does not have enough chips to play at this table.") => {
            eprintln!("The player does not have enough chips to play at this table.")
        }
        Err(_) => {
            eprintln!("Unable to add player to the table. Reason unknown.");
        }
    }

    // A Player can also be created with chips.
    let player2 = texas_hold_em_1_3_no_limit.new_player_with_chips("Player 2", 100);

    // You can try to add a player without handling the result.
    texas_hold_em_1_3_no_limit.add_player(player2).unwrap();

    // A tournament can be played, which iterates through rounds until there is only one player remaining.
    texas_hold_em_1_3_no_limit.play_tournament();

    // Or a single round can be run.
    // The dealer's seat index must be provided in order to determine the order of dealing and the small and big blinds.
    let dealer_seat_index: usize = 0;
    texas_hold_em_1_3_no_limit.play_round(dealer_seat_index);
}

依赖项

~0.8–1.3MB
~28K SLoC