npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

poker-wasm

v1.3.0

Published

WASM range vs range equity for NLHE

Downloads

64

Readme

power-range-rs

This is a rust port of the algorithm in https://github.com/conradbkay/poker-utils for calculating the equity of a Hold'em range vs a second range

Benchmarks

The benchmark randomizes the board and both ranges for each trial

For hand evaluation it's using the twoplustwo algorithm/lookup table, but it only evaluates the union of both range's (so a max of 1326 evaluations), so even swapping in a 10x slower evaluator wouldn't harm performance much.

Usage

Installing from npm

npm install poker-wasm

Note: This package is built with --target nodejs which automatically loads the WASM module. No manual initialization needed!

NLHE Equity Calculation

Calculate equity for a Hold'em range vs another range:

import * as rvr from 'poker-wasm';
import fs from 'fs';

// Load the hand evaluation data file
const handRanksData = fs.readFileSync('./HandRanks.dat');
const calculator = new rvr.EquityCalculator(handRanksData);

// Create ranges
const heroRange = new rvr.HoldemRange();
const vsRange = new rvr.HoldemRange();

// Add hands to ranges (cards are 0-51)
// For example, AA = [51, 50], KK = [47, 46], etc.
heroRange.set_hand(new Uint8Array([51, 50]), 1.0); // AA with 100% weight
heroRange.set_hand(new Uint8Array([47, 46]), 1.0); // KK with 100% weight

vsRange.set_hand(new Uint8Array([43, 42]), 1.0); // QQ
vsRange.set_hand(new Uint8Array([39, 38]), 1.0); // JJ

// Set ranges once (avoids repeated memory transfers)
calculator.setHeroRange(heroRange);
calculator.setVsRange(vsRange);

// Calculate equity on a flop
const board = new Uint8Array([0, 12, 28]);
const results = calculator.equity_vs_range(board);

// Results contain equity for each hand in hero's range
results.forEach(result => {
  const { combo, equity } = result;
  console.log(`Hand: [${combo}]`);
  console.log(`  Win: ${equity.win.toFixed(3)}`);
  console.log(`  Tie: ${equity.tie.toFixed(3)}`);
  console.log(`  Lose: ${equity.lose.toFixed(3)}`);
});

Omaha Monte Carlo Flop Equity

Calculate PLO equity using Monte Carlo simulation on the flop:

import * as rvr from 'poker-wasm';
import fs from 'fs';

// Load the hand evaluation data file
const handRanksData = fs.readFileSync('./HandRanks.dat');
const calculator = new rvr.EquityCalculator(handRanksData);

// Create an Omaha range (4 hole cards per hand)
const omahaRange = new rvr.OmahaRange();

// Add Omaha hands to the range
omahaRange.addHand(new Uint8Array([51, 50, 47, 46]), 1.0); // AAKK double suited
omahaRange.addHand(new Uint8Array([43, 42, 39, 38]), 1.0); // QQJJ

// Set range once (avoids repeated memory transfers)
calculator.setOmahaRange(omahaRange);

// Hero's hand (4 cards)
const heroHand = new Uint8Array([35, 34, 31, 30]); // TT99

// Flop (3 cards)
const flop = new Uint8Array([0, 1, 2]); // 2s 2h 2d

// Calculate equity using Monte Carlo with 1000 runouts
const numRunouts = 1000;
const runoutResults = calculator.omahaMonteCarloFlop(
  heroHand,
  flop,
  numRunouts
);

// Results contain equity for each sampled runout
console.log(`Sampled ${runoutResults.length} runouts`);
runoutResults.slice(0, 10).forEach((result, i) => {
  console.log(`Runout ${i}: Board [${result.board}]`);
  console.log(`  Win: ${result.equity.win.toFixed(3)}`);
  console.log(`  Tie: ${result.equity.tie.toFixed(3)}`);
  console.log(`  Lose: ${result.equity.lose.toFixed(3)}`);
});

// Calculate average equity across all runouts
const avgEquity = runoutResults.reduce(
  (acc, r) => ({
    win: acc.win + r.equity.win / runoutResults.length,
    tie: acc.tie + r.equity.tie / runoutResults.length,
    lose: acc.lose + r.equity.lose / runoutResults.length,
  }),
  { win: 0, tie: 0, lose: 0 }
);

console.log('\nAverage Equity:');
console.log(`  Win: ${avgEquity.win.toFixed(3)}`);
console.log(`  Tie: ${avgEquity.tie.toFixed(3)}`);
console.log(`  Lose: ${avgEquity.lose.toFixed(3)}`);