Skip to content

Commit

Permalink
Merge pull request #54 from winstonrc/casino_poker-update-readme
Browse files Browse the repository at this point in the history
make hand_ranking public & update readme with example
  • Loading branch information
winstonrc authored Jul 19, 2024
2 parents 8f45c8f + d416639 commit 8edede9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/casino_poker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "casino_poker"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
license = "MPL-2.0"
description = "A library that provides the backend for playing poker games such as Texas hold 'em."
Expand Down
39 changes: 33 additions & 6 deletions crates/casino_poker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,39 @@ A library that implements the backend for playing poker games including Texas ho

## Usage

### Hand Ranking & High Cards

```rust
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);
}
```

### Texas hold 'em

```rust
Expand Down Expand Up @@ -61,9 +94,3 @@ fn main() {
}
```

## Todo

- Implement betting & folding
- Add computer opponent ai
- Implement [limit](https://en.wikipedia.org/wiki/Betting_in_poker#Fixed_limit)/[no-limit](https://en.wikipedia.org/wiki/Betting_in_poker#No_limit) logic
- Add training tools like calculating [pot odds](https://en.wikipedia.org/wiki/Pot_odds)
4 changes: 2 additions & 2 deletions crates/casino_poker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod hand_rankings;
pub mod player;
pub mod games {
pub mod texas_hold_em;
}
pub mod hand_rankings;
pub mod player;

0 comments on commit 8edede9

Please sign in to comment.