Skip to content

Latest commit

 

History

History
82 lines (54 loc) · 3.51 KB

README.md

File metadata and controls

82 lines (54 loc) · 3.51 KB

POKER FACE - ♥️♦️♣️♠️

github build status crates.io docs.rs Downloads Project Status: Active – The project has reached a stable, usable state and is being actively developed.

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));

Execute

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

Contribution

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!