Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chesslib/ai

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chesslib/ai

Simple Chess AI for @chesslib/core

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

@chesslib/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.

Install:

npm install @chesslib/ai

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

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

API (Basic)

import { ChessAI } from "@chesslib/ai";
import { Chessboard, COLORS, Positions } from "@chesslib/core";
var chessboard = Chessboard.fromPosition(Positions.default);

// Create AI that find the best moves for BLACK for the chessboard with 2 players
var ai = new ChessAI(chessboard, COLORS.BLACK, 2);
// Returns the 5 best moves with search depth 3
var moves = ai.getBestMoves(3, 5);
ai.doMoveFEN({
  from: "a2",
  to: "a4"
});

For more please see examples folder

WebWorkers

Simply include worker.js in your application.

import { Chessboard, COLORS, Positions } from "@chesslib/ai";
import { ChessAIWorker } from "@chesslib/ai";
var chessboard = Chessboard.fromPosition(Positions.default);

let AIWorker = new ChessAIWorker("./worker.js");
// Gets the 210 best moves for BLACK for the given chessboard with 2 players and depth: 5
AIWorker.exec("getBestMoves", chessboard.getBoard(), COLORS.BLACK, 5, 10);
AIWorker.on("moves", moves => {
    // Received Moves array of 
    // {
    //   from: "a2",
    //   to: "a4"
    // }
});

The example use of the AI is available in the repo under examples/ folder.

License:

Apache 2.0

Got an issue or question?

Open an issue!

FAQs

Package last updated on 28 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc