mrbot
v1.0.3
Published
A simple chess bot.
Readme
MrBot
MrBot is a very very simple chess bot. It uses the minimax algorithm to find the best move. It evaluates positions based on material value, castling (opening), PSTs, and more.
API
decodeScore(score: number): { isMate: boolean, isBook: boolean, mateInPlies: number?, mateInMoves: number?, isWinning: boolean, evaluation: number }Decodes a score/evaluation so that it can be worked with comfortably.
MrBot objects
class
MrBotThis class represents an instance of MrBot.
createSearch(chess: Chess): voidCreates a
Searchobject from the givenChessinstance.
async simpleSearch(o: { chess: Chess, ms: number?, depth: number? }): { move: string, evaluation: number, depth: number }?Runs a search on the Chess instance
chessformsmilliseconds with a max depth ofdepth.depth, if not given, is4.ms, if not given, is4500. Slightly buggy. Okay, let's be honest: it's very buggy and can sporadically returnnull.
Search objects
A search object represents a search. Multiple searches cannot happen in parallel.
start(maxDepth: number? = null): voidStarts the search.
maxDepthis the maximum depth it should search to.
stop(): voidStops the search.
oniteration: (o: { move: string, evaluation: number, depth: number }) => voidThis callback is called when MrBot finishes an iteration of iterative deepening.
Example
import { MrBot } from "mrbot";
import { Chess } from "chess.js";
const chess = new Chess();
const mrbot = new MrBot();
(async () => {
const result = await mrbot.simpleSearch({ chess, ms: 1000 });
console.log(result);
// { move: 'e2e4', evaluation: 34, depth: 4 }
})();