]> git.beaudet.xyz Git - poker-eval.git/commitdiff
feat: add wasm-bindgen build option and live example
authorMA Beaudet <ma@beaudet.xyz>
Wed, 3 Nov 2021 21:34:36 +0000 (22:34 +0100)
committerMA Beaudet <ma@beaudet.xyz>
Wed, 3 Nov 2021 22:24:57 +0000 (23:24 +0100)
Cargo.toml
README.md
src/constants.rs
src/lib.rs

index aa4afb0eb52c04fde071ce837785b2120747022e..3275a2f989dbef96590b7d8ba321c87f67757ec5 100644 (file)
@@ -3,8 +3,12 @@ name = "poker-eval"
 version = "0.1.0"
 edition = "2021"
 
+[lib]
+crate-type = ["cdylib", "rlib"]
+
 [features]
 parallel = ["rayon"]
 
 [dependencies]
 rayon = { version = "1.5.1", optional = true }
+wasm-bindgen = "0.2.78"
index 3613140129d81083f04de0f87f7a5b55eb60b9c2..fbeadbea8e2794ba418b455cdb47b79382f33cb0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -2,5 +2,7 @@
 
 Poker hand evaluator
 
-Based on Kevin L. Suffecool poker hand evaluator.
-<http://suffe.cool/poker/evaluator.html>
+This project can be built using wasm-pack.\
+An example is available [here](https://poker-eval.beaudet.xyz).
+
+Based on Kevin L. Suffecool [poker hand evaluator](http://suffe.cool/poker/evaluator.html)
index 3b54d48bd8988c194caa6e935a6a1857c7bfa6a4..419a1c510fd49791fd386cdab4f00821774579e3 100644 (file)
@@ -16,7 +16,7 @@ pub const VALUE_STR: [&str; 10] = [
     "Four of a Kind",
     "Full House",
     "Flush",
-    "Staight",
+    "Straight",
     "Three of a Kind",
     "Two Pair",
     "One Pair",
index d2e951d9af3d4f954c9137733f8efd87bc902d07..99e31afd68cc4042816b1091c163d8e536d17462 100644 (file)
@@ -15,6 +15,8 @@ use constants::{
     PERM7, PRIMES, STRAIGHT, STRAIGHT_FLUSH, THREE_OF_A_KIND, TWO_PAIR, UNIQUE5,
 };
 
+use wasm_bindgen::prelude::*;
+
 ///  Initializes a deck of 52 cards as an integer vector of lenght 52.
 ///
 /// The order in which the cards are returned is not random.
@@ -132,6 +134,7 @@ fn find_fast(mut u: u32) -> u32 {
 /// assert_eq!(eval_from_str("4s 4d 4h 4c 5d"), 140);
 /// assert_eq!(eval_from_str("Ts 9s 8s 7s 6s 7h 6d"), 5);
 /// ```
+#[wasm_bindgen]
 pub fn eval_from_str(s: &str) -> u32 {
     let cards = s.split(' ').map(|c| card_from_str(c)).collect::<Vec<_>>();
     match cards.len() {
@@ -187,6 +190,7 @@ pub fn eval_7hand(hand: &[u32; 7]) -> u32 {
 /// assert_eq!(eval, 1433);
 /// assert_eq!(hand_rank(eval), FLUSH);
 /// ```
+#[wasm_bindgen]
 pub fn hand_rank(i: u32) -> u32 {
     match i {
         6186..=7462 => HIGH_CARD,