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

@chesslib/core

v1.1.9

Published

A fast & universal chesslibrary with Basic AI support. This is the core part of the @chesslib bundle.

Downloads

16

Readme

@chesslib/core

A fast & universal chesslibrary with Basic AI support. This is the core part of the @chesslib bundle.

This library is required for

  • @chesslib/ai
  • @chesslib/game
  • @chesslib/plugin

Install:

npm install @chesslib/core

https://www.npmjs.com/package/@chesslib/core

Intro

Get all available moves

import { Chessboard, Positions, COLORS } from "@chesslib/core";

var board = Chessboard.fromPosition(Positions.default);

// Get all possible moves
var moves = board.getFENMoves();
if(board.tryMoveFEN(moves[0].from, moves[0].to))
{
    console.log("Move was valid");
}

Get all available moves for BLACK

// Get all possible moves for BLACK
var moves = board.getFENMoves(COLORS.BLACK);

Get all available moves for A2 Pawn?

// Get all possible moves for BLACK
var moves = board.getFENMovesatFEN("a2");

Validate if move is possible?

// Get all possible moves for BLACK
if(board.isValidMoveFEN("a2", "a4"))
{
	console.log("Move is valid");
}

Check if king was captured

// Get all possible moves
if(board.findPieces("K").length == 1)
{
	console.log("GAME OVER!");
}

For more please see examples folder

Chess AI

The AI is a simple implementation of a basic board evaluation. The AI is trying every moves possible confirming the board value is better for a given move. The search depth can be configured, and due to it's high CPU intensivity it is recommended to use it with webworkers in browsers, and run it as a seperate process or thread in nodejs if required.

AI REPO: https://github.com/azarus/chesslib-ai The example use of the AI is available in the repo under examples/ folder.

API

Chessboard

Thirdparty:

  • Add Move History

addHistory(piece: Piece, data: any);

  • Property Board Size

boardSize: {x: number, y: number}

  • Returns the character representation of a square by it's index

charIndex(index: number): string;

  • clones the board

clone(): Chessboard

Squares

  • clears a square

clearSquare(square: Square);

  • Spawns a piece on a square

createPiece(type: string, color: number | COLORS, square: Square);

  • Makes a move using a move object

doMove(move: MoveObject);

  • Makes a move using strings

doMoveFEN(move: { from: string, to: string});

  • Converts a FEN string to position

FENtoPosition(fen: string): {x: number, y: number};

  • Returns the square for a FEN string

FENToSquare(fen: string): SVGPathSegCurvetoQuadraticRel

  • Finds all pieces on the board

findPieces(pieceType: string, color: number | COLORS): Piece[]

  • Returns a board object (Usefull for chessboard visualization)

getBoard(): { BoardObject }

  • Set's the board from an object

setBoard(board: { BoardObject });

  • Returns the 2D Array representation of the board

savePositions(): any[]

  • Set's the board from a 2D Array

loadPositions(positions: any[]);

import { Chessboard, Positions } from "@chesslib/core";

var board = Chessboard.fromPosition(Positions.default);

// Get all possible moves
var moves = board.getFENMoves();
if(board.tryMoveFEN(moves[0].from, moves[0].to))
{
    console.log("Move was valid");
}

For more please see examples folder

Use the lib together with:

and

to create your game. Have happy coding :)

License:

Apache 2.0

Got an issue or question?