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

duk-board-engine

v1.0.0

Published

A generic and modular engine for developing board games on the web.

Downloads

32

Readme

🎮 BoardEngine

A generic and modular JavaScript engine for developing board games on the web. Build interactive, turn-based board games with an easy-to-use API and flexible styling.

✨ Features

  • 🎯 Easy Setup - Create a board grid in just a few lines of code
  • 👥 Player Management - Register players and manage turns
  • ♟️ Piece System - Spawn, move, and remove pieces dynamically
  • 🎨 Flexible Styling - Customize cells and pieces with CSS classes
  • 📱 Interactive - Built-in cell click handling and event system
  • 🔧 Modular - Export and reuse components in your own projects
  • 📦 Lightweight - Minimal dependencies (Vite for building)

📦 Installation

Via NPM

npm install duk-board-engine

From Source

git clone <repository-url>
cd BoardEngine
npm install

🚀 Quick Start

Basic Setup

import { BoardEngine } from 'duk-board-engine';

// Create an 8x8 board
const game = new BoardEngine('board', 8, 8);

// Style the board
game.colorizeCells((row, col) => {
    return (row + col) % 2 === 0 ? 'light-cell' : 'dark-cell';
});

// Handle cell clicks
game.onCellClick = (row, col) => {
    console.log(`Cell clicked: ${row}, ${col}`);
};

HTML Setup

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="path/to/engine.css">
</head>
<body>
    <!-- This is where your board will be rendered -->
    <div id="board"></div>
    
    <script type="module" src="app.js"></script>
</body>
</html>

📚 API Documentation

Constructor

new BoardEngine(containerId, rows, cols)

Creates a new board instance.

  • containerId (string): ID of the HTML element to contain the board
  • rows (number): Number of rows in the board
  • cols (number): Number of columns in the board

Properties

  • container: Reference to the DOM element containing the board
  • rows: Number of rows
  • cols: Number of columns
  • state: 2D array representing the board state
  • players: Object containing registered players
  • currentTurn: ID of the current player's turn
  • onCellClick: Callback function for cell clicks

Player Management

registerPlayer(playerId, playerName, attributes)

Register a player in the game.

game.registerPlayer('white', 'Player 1', { canEat: 0 });
game.registerPlayer('black', 'Player 2', { canEat: 0 });

getPlayer(playerId)

Retrieve a player's information.

const player = game.getPlayer('white');
console.log(player.name); // 'Player 1'

updatePlayer(playerId, attributeKey, newValue)

Update a player's attribute.

game.updatePlayer('white', 'canEat', 1);

Turn System

setTurnSystem(initialTurn)

Set the initial turn.

game.setTurnSystem('white');

switchTurn(nextTurn)

Switch to the next player's turn.

game.switchTurn('black');

Board Manipulation

colorizeCells(callback)

Apply CSS classes to cells based on a callback function.

game.colorizeCells((row, col) => {
    if ((row + col) % 2 === 0) return 'light-marble';
    return 'dark-marble';
});

getCellElement(row, col)

Get the DOM element of a specific cell.

const cellElement = game.getCellElement(0, 0);

Piece Management

spawnPiece(row, col, pieceId, playerOwner, customClasses, customProperties)

Create a new piece on the board.

game.spawnPiece(
    0, 0,                      // row, col
    'piece-1',                 // pieceId
    'white',                   // playerOwner
    ['king'],                  // customClasses (optional)
    { health: 100 }            // customProperties (optional)
);

movePiece(fromRow, fromCol, toRow, toCol)

Move a piece from one cell to another.

if (game.movePiece(0, 0, 1, 1)) {
    console.log('Piece moved successfully');
}

removePiece(row, col)

Remove a piece from the board.

if (game.removePiece(1, 1)) {
    console.log('Piece removed');
}

clearBoard()

Clear all pieces from the board and reset game state.

game.clearBoard();

🎮 Examples

Tic Tac Toe

A complete implementation of Tic Tac Toe is included in examples/tictactoe/.

Features:

  • 3x3 grid
  • Turn-based gameplay
  • Win detection
  • Game restart functionality

Run the example:

npm run dev
# Navigate to http://localhost:5173/examples/tictactoe/

Checkers

A full implementation of Checkers is included in examples/checkers/.

Features:

  • 8x8 board with alternating colors
  • Piece selection and movement validation
  • King promotion
  • Capture/jump system
  • Turn indicator
  • Game restart

Run the example:

npm run dev
# Navigate to http://localhost:5173/examples/checkers/

🎨 Styling

The engine comes with a base stylesheet at src/styles/engine.css. Customize it with CSS variables:

/* Override board dimensions */
.board-container {
    --board-rows: 8;
    --board-cols: 8;
}

/* Style cells */
.engine-cell {
    width: 60px;
    height: 60px;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
}

.engine-cell.light-cell {
    background-color: #ffffff;
}

.engine-cell.dark-cell {
    background-color: #333333;
}

/* Style pieces */
.engine-piece {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: #ff0000;
}

.engine-piece.selected {
    box-shadow: 0 0 10px rgba(0, 0, 255, 0.5);
}

🛠️ Development

Installation

npm install

Development Server

Start the Vite development server:

npm run dev

The server will be available at http://localhost:5173.

Build for Production

npm run build

Build output will be in the dist/ directory.

Preview Build

npm run preview

📖 Project Structure

BoardEngine/
├── src/
│   ├── index.js                 # Main export file
│   ├── core/
│   │   └── BoardEngine.js       # Core engine class
│   ├── components/
│   │   ├── Cell.js              # Cell component (extensible)
│   │   └── Piece.js             # Piece component (extensible)
│   └── styles/
│       └── engine.css           # Base styles
├── examples/
│   ├── tictactoe/               # Tic Tac Toe example
│   │   ├── index.html
│   │   ├── app.js
│   │   └── styles.css
│   └── checkers/                # Checkers example
│       ├── index.html
│       ├── app.js
│       └── styles.css
├── package.json
├── vite.config.js
└── README.md

💡 Usage Tips

  1. State Management: The state property holds your game data. Use it to track piece information:

    game.state[row][col] = { id: 'piece-1', owner: 'white', king: true };
  2. Custom Attributes: Add any custom attributes to pieces using the customProperties parameter:

    game.spawnPiece(0, 0, 'p1', 'white', [], { health: 100, attack: 10 });
  3. CSS Classes for Visual States: Use CSS classes to represent game states:

    game.getCellElement(row, col).classList.add('valid-move');
  4. Turn Management: Keep track of turns with the built-in system:

    game.setTurnSystem('white');
    game.switchTurn('black');

🤝 Contributing

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

👨‍💻 Author

Diego Dukón (dieduk89)


🎓 Getting Help

  • Check the examples directory for sample implementations
  • Review the API documentation above
  • Inspect the base CSS file for styling reference

Happy game developing! 🎮✨