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

simple-chess-engine

v3.1.0

Published

A Multiplayer chess engine

Downloads

5

Readme

Simple-Chess-Engine

simple-chess-engine is a multiplayer chess engine which keeps track of the board and produces valid possbile moves.

Features

  1. Accepts algebraic notation
  2. Lists possible valid moves
  3. Check detection
  4. Checkmate detection
  5. Stalemate detection
  6. Supports special moves (Castling)
  7. Supports undo
  8. Load custom board new

API

  • Create Game
  • Get Game Status
  • Get Possible Moves
  • Move Piece
  • Get Complete Board
  • Undo
  • Load Custom Board
  • Reset Game
  • Debug Board

Usage

const SimpleChessEngine = require('simple-chess-engine');
const game = new SimpleChessEngine();
/**
 * Returns the current status of the game
 * 
 * @returns {object}
 {
     "nextPlayer": "white",
     "isCheck": false,
     "isCheckmate": false,
     "isStalemate": false
 }
 */
game.getStatus();
/**
 * Returns all the valid possible moves of a piece at the given position
 * @param {string} position
 * 
 * @returns {array}
 ["A3", "C3"]
 */
game.getPossibleMoves('B1');
/**
 * Used to move a piece from source position to destination position
 * @param {string} source
 * @param {string} destination 
 * 
 * @returns {object}
 {
     "success": true | false,
     "status" : {
         "nextPlayer" : 'white' | 'black',
         "isCheck"    : true | false,
         "isCheckmate": true | false,
         "isStalemate": true | false
     }
 }
 *
 * NOTE :: In order to get the updated board, use the getBoard() method.
 */
game.makeMove('B1', 'C3');
/**
 * Used to undo any previosly made move
 * 
 * @returns {object}
 {
     "nextPlayer" : 'black' | 'white',
     "isCheck"    : true | false,
     "isCheckmate": true | false,
     "isStalemate": true | false
 }
 *
 * NOTE :: In order to get the updated board, use the getBoard() method.
 */
game.undo();
/**
 * Used to return the complete board
 * 
 * @param {object} opts 
 * Supported opts:
 *  format: 'JSON' =>(Currently only JSON format is supported, any requested formats might be considered)
 * 
 * @returns {object}
 * 
 {
     "A8": {
         "color": "black",
         javascriptiece": "rook"
     },
     "B8": {
         "color": "black",
         "piece": "bishop"
     },
     ...
 }
 */
game.getBoard();
let content = JSON.stringify({
    A1: { color: "white", piece: "king" },
    C1: { color: "black", piece: "king" },
    A2: { color: "white", piece: "rook" }
});
let opts = { firstPlayer: 'white' };
/**
 * Used to load custom board
 * @param {string} content => Stringified JSON Object
 * @param {object} opts
 * 
 * Supported opts:
 *  firstPlayer = 'white' | 'black'
 * 
 * @returns {object}
 *  Success Case
    {
        "success": "true",
        "status": {
            "nextPlayer": "white",
            "isCheck": false,
            "isCheckmate": false,
            "isStalemate": false
        }
    }
 *  Failure Case
    {
        "success": "false",
        "reasons": [...]
    }
 */
game.loadBoard(content, opts);
let opts = { custom: true };
/**
 * Used to reset the board
 * @param {object} opts
 * 
 * Supported opts:
 *  custom = true | false (resetGame with custom=true will reload the custom board which was previousy loaded (if any))
 * 
 * NOTE :: resetGame with custom=false will remove custom board from memory
 * NOTE :: In order to get the updated board, use the getBoard() method.
 */
game.resetGame();
/**
 * Logs the complete chess board to the console
 */
game.displayBoard();

If you find this useful, you can support me by donating here...

Donate Donate (Supports GPay, Paytm, PhonePe, BHIM UPI, Credit Cards, Debit Cards, Netbanking...)