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 🙏

© 2026 – Pkg Stats / Ryan Hefner

banqi

v0.0.2

Published

Banqi engine for Node and Web (WASM)

Readme

banqi-minimax

High-performance game engine for Banqi (暗棋, Chinese Dark Chess) with Minimax and MCTS search algorithms, written in Rust.

Features

  • Minimax Search with alpha-beta pruning and transposition table
  • Monte Carlo Tree Search (MCTS) with Dirichlet noise and chance node enumeration
  • Depth-1 flip caching for dramatically faster expectimax evaluation
  • Parallel root evaluation via Rayon work-stealing
  • Customizable game variants (board size, piece counts, draw rules)
  • Two material evaluation modes: Static (simple counting) and Dynamic (scarcity-adjusted)

Usage

Add to your Cargo.toml:

[dependencies]
banqi-minimax = { git = "https://github.com/jacoblincool/banqi-minimax" }

Basic Example

use banqi::game::logic::make_test_state;
use banqi::game::variant::VariantSpec;
use banqi::minimax::{minimax_scores_one, EvalMode};

let spec = VariantSpec::standard();
let state = make_test_state(42, 16, &spec); // seed=42, 16 pieces revealed

let scores = minimax_scores_one(state, 3, &spec, EvalMode::Dynamic);
// scores[action] = expected value for each legal action

Arena (Self-Play)

Compare Static vs Dynamic evaluation:

cargo run --features cli --release --bin arena -- --games 10 --depth 3

Python (PyO3 + Maturin)

Build and install the local extension module:

maturin develop --features python

Example:

from banqi import BanqiGame, VariantSpec

variant = VariantSpec.standard()
game = BanqiGame.make_test(seed=42, reveal_count=8, variant=variant)
scores = game.minimax_scores(depth=2, eval_mode="dynamic")

Smoke test:

pytest python/tests/test_bindings_smoke.py

WebAssembly (wasm-bindgen + wasm-pack + Vite)

Run the browser minimax playground with Vite:

cd examples/wasm-web
pnpm install
pnpm dev

The Vite scripts call wasm-pack and generate examples/wasm-web/pkg/.

Build Node package and run smoke test:

wasm-pack build --target nodejs --out-dir pkg-node --out-name banqi . --features wasm
node examples/wasm-web/smoke-node.mjs

Architecture

State Representation

Game state is a fixed-size [i16; 66] array (132 bytes), passed by value (Copy):

| Index | Content | | ----- | ------------------------------------------------ | | 0-31 | Board cells (0=empty, 15=face-down, 1-14=pieces) | | 32 | Side to move | | 33 | No-capture ply counter | | 34 | Ply count | | 35 | Board size | | 36-49 | Unflipped piece pool (14 types) | | 50-63 | Captured piece counts (14 types) | | 64-65 | Player color assignments |

Search

  • Depth <= 3: Parallel root evaluation (Rayon) without transposition table
  • Depth > 3: Sequential evaluation with 4-way set-associative transposition table (262K entries)
  • Move ordering: Captures > Quiet moves > Flips (O(n) partition)
  • Flip caching: At depth 1, all flip actions share the same expected value since material evaluation is position-independent

Modules

| Module | Description | | --------------- | --------------------------------------------------- | | game::variant | Game variant configuration (VariantSpec) | | game::logic | Core game mechanics, legal actions, evaluation | | game::rng | Deterministic RNG (SplitMix64) | | minimax | Alpha-beta minimax with expectimax for chance nodes | | mcts | Monte Carlo Tree Search with UCB exploration |

Benchmarks

cargo bench --bench minimax

Typical results on Apple M1 Pro 2021 (depth 3, 16 revealed pieces):

| Metric | Value | | ------- | ------- | | Depth 2 | ~125 us | | Depth 3 | ~6.5 ms | | Depth 4 | ~6.3 s |

Development

# Run tests
cargo test

# Check Python bindings compile
cargo check --features python

# Check wasm bindings compile
cargo check --target wasm32-unknown-unknown --features wasm

# Run snapshot tests
cargo test --test minimax_snapshot

# Update snapshots after intentional changes
cargo insta review

# Run benchmarks
cargo bench

License

MIT