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

@table-games-engine/core

v0.1.3

Published

Deterministic turn-based game engine: state, actions, priority, seeded RNG, player views.

Readme

@table-games-engine/core

The deterministic, in-process engine for turn-based table games: state, actions, priority, triggers, seeded randomness and per-player views. Game logic is written against its types.

Most game authors don't install this directly: it comes with @table-games-engine/game-kit, which scaffolds a game that already depends on it. Games import types and helpers from it:

import { ok, reject, resolved, type ActionHandler, type GamePlugin } from '@table-games-engine/core';

const fireBolt: ActionHandler = (ctx, frame) => {
  const actor = 'actor' in frame ? frame.actor : frame.controller;
  const target = ctx.getActivePlayers().find((p) => p !== actor);
  if (!target) return reject('rule-violation');          // illegal move: nothing changes
  return resolved([
    { domain: 'player', operation: { type: 'add-resource', playerId: target, resource: 'life', delta: -2 } },
    { domain: 'turn', operation: { type: 'advance' } },  // end the turn
  ]);
};

Install

npm install @table-games-engine/core

ESM only.

What a game provides

A GamePlugin has id, version, manifest, requiredMechanics, setup, actionHandlers, winConditionChecker and legalMoves(state, playerId). legalMoves returns every concrete move the player may submit now, and [] when they do not hold priority or the game is over. Handlers must be pure: return mutations, never modify ctx.state.

Helpers for handlers:

  • resolved(mutations, events?) - a successful result.
  • reject(reason) - an illegal move ('rule-violation', 'condition-failed', 'targets-illegal'); state does not change.
  • ok(value) - generic Result success constructor (err(error) is its failure counterpart). setup returns ok({ state }).

Running the engine

Use these to run matches yourself (in tests, simulators, servers):

import { setupMatch, driveAction, rulesFromPlugin, computePlayerView } from '@table-games-engine/core';
  • setupMatch and driveAction start a match from a GamePlugin and apply one player input.
  • createEngine(manifest, initialState, handlers) is the lower-level facade (applyAction, resolveTopFrame, getState).
  • computePlayerView(state, manifest, playerId) returns what one player may see.
  • Randomness: seedRng, nextRandom, randomInt, randomPick, randomShuffle. Inside handlers use ctx.random*.
  • Lower-level building blocks are also exported (applyMutation, applyTransition, validateAction, resolveTopFrame, scanTriggers, advanceTurn, advancePhase, checkWin, priority helpers).

Determinism

The same initial state, manifest, handlers and inputs always produce the same final state. The engine never calls Math.random or Date.now; all randomness flows through MatchState.rng (xorshift32).

Licence

Apache-2.0