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 🙏

© 2024 – Pkg Stats / Ryan Hefner

battlescripts

v1.5.0

Published

Battlescripts

Downloads

15

Readme

BattleScripts

The functionality of BattleScripts is defined entirely by JSON messages. This is just one possible implementation of an Engine. Because orchestration is done entirely through JSON messages without any dependence on language or implementation, other Engines could be written in other languages which perform the same function.

Engine Message Interfaces

MatchConfig

Passed into the Engine to instruct it to begin playing a match.

interface MatchConfig {
  game: Game,
  players: [ Player+ ],
  
  // Optional configuration options for the Game
  scenario?: Scenario,
  
  // Max number of loops to run through the Engine before error
  loopLimit?: Number,
  
  // Player timeouts in ms
  gameStartTimeout?: Number,
  turnTimeout?: Number,
  gameEndTimeout?: Number
}

MatchResults

Returned from the Engine. The results are an Array of results for each game. The state is an Array of games, each being an Array of individual game states.

interface MatchResults {
  results: [ GameResults* ],
  state: [ [ GameState* ] ],
  log: [ [ String* ] ]
}

MatchResultsSummary

The output of tally() takes raw results and computes a summary.

interface MatchResultsSummary {
  matchWinners: [ PlayerId* ],
  gameWinners: [ [ PlayerId* ] ],
  scores: [ Number* ],
}

Engine <---> Game Message Interfaces

GameDirective

The Game returns this as the "command" to the Engine to control flow. This is the core of the Game's interaction with the Engine.

interface GameDirective {
  // Game returns state with every Directive.
  // It can be optionally rendered now or later.
  state: GameState,

  // Request that one or more players take a turn.
  // Pass each player a game state that is specific to them.
  getTurn?: {
    PlayerId: GameState
  },

  // Return true if the game is over the loop should terminate  
  gameOver?: Boolean,
  
  // If gameOver==True, then results must be returned.
  results?: {
    // Each player will get an integer score with a game-defined max.
    // The highest score(s) is the winner(s)
    // The Game decides how many points to award.
    PlayerId: Number
  },
  
  // Info from the game, which might be displayed to the user in a UI.
  log?: String | [ String* ]
}

PlayerTurns

After requesting moves from players, the Engine passes this message to the Game to process the moves.

interface PlayerTurns {
  PlayerId: PlayerTurn
}

Opaque Types

These are game-defined types that may contain any data or structure as decided and documented by the Game being played.

type GameState;
type Move;
type Scenario;

Engine <---> Player Message Directives

PlayerGameStart

Passed to the player when a game is ready to start.

interface PlayerGameStart {
  gameState: GameState,
  knowledge?: PlayerKnowledge
}

PlayerTurnRequest

Passed to the Player when they are asked to take a turn.

interface PlayerTurnRequest {
  gameState: GameState,
  playerState: PlayerState
}

PlayerTurn

Passed from the Player to the Engine to take a turn. The playerState attribute is optional if the player wishes to persist state between turns.

interface PlayerTurn {
  move: Move,
  playerState?: PlayerState
}

PlayerGameEnd

Passed to the Player when the game is over to inform of the results.

interface PlayerGameEnd {
  results: GameResults,
  gameState: GameState,
  playerState: PlayerState
}

Opaque Types

These are player-defined data structures. Knowledge is passed from the player to itself between games so it can change its behavior over multiple games. PlayerState is within a single game only, passed to each turn and optionally updated.

type PlayerKnowledge;
type PlayerState;

Method API's

The Host environment is responsible for passing a Game and one or more Player objects to the Engine. The Engine is agnostic about how these objections function, as long as they satisfy the interfaces below.

interface Engine {
  match(MatchConfig): MatchResults,
  tally(MatchResults): MatchResultsSummary
}

interface Player {
  onGameStart(PlayerGameStart): PlayerState,
  onTurn(PlayerTurnRequest): PlayerTurn | Move,
  onGameEnd(PlayerGameEnd): PlayerKnowledge?
}

interface Game {
  create(Scenario): GameState,
  start(): GameDirective,
  onTurn(PlayerTurns): GameDirective
}