-import init, { eval_from_str, hand_rank } from './poker_eval.js';
+import init, { hand_rank, frequency, parse_cards, eval_hand } from './poker_eval.js';
async function run() {
await init();
}
const cards = parse_cards(inputText);
const result = eval_hand(cards);
const rank = hand_rank(result);
+ const freq = frequency(rank);
resultDiv.innerHTML = "Score: " + result + "<br />";
resultDiv.innerHTML += "Hand value: " + VALUE_STR[rank] + "<br />";
+ resultDiv.innerHTML += "Frequency: " + freq;
warningDiv.style.visibility = 'hidden';
warningDiv.innerHTML = "";
WASM_VECTOR_LEN = offset;
return ptr;
}
+
+let cachegetInt32Memory0 = null;
+function getInt32Memory0() {
+ if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
+ cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
+ }
+ return cachegetInt32Memory0;
+}
+
+let cachegetUint32Memory0 = null;
+function getUint32Memory0() {
+ if (cachegetUint32Memory0 === null || cachegetUint32Memory0.buffer !== wasm.memory.buffer) {
+ cachegetUint32Memory0 = new Uint32Array(wasm.memory.buffer);
+ }
+ return cachegetUint32Memory0;
+}
+
+function getArrayU32FromWasm0(ptr, len) {
+ return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
+}
/**
-* Wrapper over both five-card and seven-card hand evaluator from string.
+* @param {string} s
+* @returns {Uint32Array}
+*/
+export function parse_cards(s) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ var ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ var len0 = WASM_VECTOR_LEN;
+ wasm.parse_cards(retptr, ptr0, len0);
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var v1 = getArrayU32FromWasm0(r0, r1).slice();
+ wasm.__wbindgen_free(r0, r1 * 4);
+ return v1;
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+}
+
+function passArray32ToWasm0(arg, malloc) {
+ const ptr = malloc(arg.length * 4);
+ getUint32Memory0().set(arg, ptr / 4);
+ WASM_VECTOR_LEN = arg.length;
+ return ptr;
+}
+/**
+* Wrapper over both five-card and seven-card hand evaluator from a vector of cards.
*
* The evaluator orders hands from 1 to 7462.
*
* # Example
*
* ```
-* use poker_eval::{eval_from_str};
+* use poker_eval::{eval_hand, parse_cards};
*
-* assert_eq!(eval_from_str("4s 4d 4h 4c 5d"), 140);
-* assert_eq!(eval_from_str("Ts 9s 8s 7s 6s 7h 6d"), 5);
+* assert_eq!(eval_hand(parse_cards("4s 4d 4h 4c 5d")), 140);
+* assert_eq!(eval_hand(parse_cards("Ts 9s 8s 7s 6s 7h 6d")), 5);
* ```
-* @param {string} s
+* @param {Uint32Array} cards
* @returns {number}
*/
-export function eval_from_str(s) {
- var ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+export function eval_hand(cards) {
+ var ptr0 = passArray32ToWasm0(cards, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
- var ret = wasm.eval_from_str(ptr0, len0);
- return ret >>> 0;
+ var ret = wasm.eval_hand(ptr0, len0);
+ return ret;
}
/**
* # Example
*
* ```
-* use poker_eval::{eval_from_str, hand_rank, constants::FLUSH};
+* use poker_eval::{eval_hand, hand_rank, parse_cards, constants::FLUSH};
*
-* let eval = eval_from_str("Js 9s 7s 3s 2s");
+* let eval = eval_hand(parse_cards("Js 9s 7s 3s 2s"));
* assert_eq!(eval, 1433);
* assert_eq!(hand_rank(eval), FLUSH);
* ```
*/
export function hand_rank(i) {
var ret = wasm.hand_rank(i);
- return ret >>> 0;
+ return ret;
+}
+
+/**
+* @param {number} i
+* @returns {number}
+*/
+export function frequency(i) {
+ var ret = wasm.frequency(i);
+ return ret;
}
async function load(module, imports) {