Crates.io | poker-face |
lib.rs | poker-face |
version | 0.1.0 |
source | src |
created_at | 2023-09-17 08:39:10.5915 |
updated_at | 2023-09-17 08:39:10.5915 |
description | A hand evaluator for Texas Hold'em poker, using the Rust Match control flow construct. |
homepage | https://github.com/davassi/poker-face |
repository | https://github.com/davassi/poker-face |
max_upload_size | |
id | 974931 |
size | 40,413 |
Poker-Face is a rust virtusism exercise implementation of a Texas Hold'em poker engine. It evaluates the rank of a 5-card hand using the typical Rust match control flow construct. It determines the Rank of a 5 card hand examining the properties using Array Matching and Struct Matching MatchHandEvaluator.
Example of usage of the library, as a binary:
Poker Face 0.1.0 - 🦀 for ♠️ ♣️ ♥️ ♦️
Prehashing cards...
1. Let's shuffle a deck...
J♥️ 7♠️ 9♠️ 10♥️ 5♥️ K♦️ K♣️ K♥️ Q♦️ 6♥️ 3♥️ J♦️ 4♥️
A♦️ J♣️ 9♣️ 5♠️ 2♠️ 4♣️ 5♦️ 3♦️ 5♣️ 6♦️ J♠️ Q♠️ 4♠️
10♠️ 7♣️ 9♥️ 7♥️ 9♦️ 3♠️ A♣️ A♥️ 7♦️ 2♦️ 10♣️ 6♣️ 4♦️
K♠️ A♠️ 8♣️ 8♥️ Q♥️ 8♦️ 2♣️ 2♥️ 3♣️ Q♣️ 6♠️ 8♠️ 10♦️
2. Let's take (actually, borrow) 2 hands of 5 cards each from the deck
Player 1 has: J♥️ 7♠️ 9♠️ 10♥️ 5♥️
Player 2 has: K♦️ K♣️ K♥️ Q♦️ 6♥️
3. Let's evaluate the hands...
Sorted: J♥️ 10♥️ 9♠️ 7♠️ 5♥️
Sorted: K♥️ K♣️ K♦️ Q♦️ 6♥️
Player 1 has a [HighCard with a highcard of value J♥️]
Player 2 has a [ThreeOfAKind]
4. Celebrate the winner:
The winner is Player 2!
As a library, there are some handy macros (newcard!, hand!, assert_rank!) implemented to deal with cards, hands and ranks. Example:
assert_rank!(hand!["Ad","Kd","Qd","Jd","10d"], Rank::RoyalFlush);
assert_rank!(hand!["Kd", "Kh", "Kc", "Ks", "Qd"], Rank::FourOfAKind);
assert_rank!(hand!["2d", "2h", "Qc", "Qs", "Qd"], Rank::FullHouse);
or
assert_eq!(newcard!["Ah"], Card::new(14, Suit::Hearts));
To run it from cargo, just type:
cargo run -q --
or to build and install a release from the code:
cargo build --release
cargo install --path .
./target/release/poker-face
If you have any suggestions for features (i.e. more functionality to implement), or if you find any problems in the code, design, interface, etc., please feel free to share them on our GitHub.
I really appreciate your feedback!