GameState ($0)

parameter type description
$0 Object = {}
$0.artificialIntelligenceViewEventHandler any
$0.firstPlayerId any

Examples

const gameState = new GameState();

Instance Members

currentPlayer ()

Returns

number : The numeric representation ( 0 for white player or 1 for black player) of the current player.

currentPlayerObject ()

Returns

object : The object representation of the current player.

fenString ()

Returns

string :

log ()

Returns

array :

aiSettings ()

Returns

array :

newGame ($0)

parameter type description
$0 Object = {}
$0.gameId any

Returns

undefined :

export ()

Returns

string : The current game state as stringified JSON.

import (unparsedGameData, options)

parameter type description
unparsedGameData string
options object = {}
options.resumeGame any (default false)
options.noConsoleOutput any (default false)

Returns

undefined :

updateTimePlayed ()

Returns

undefined :

pause ()

Returns

undefined :

resume ()

Returns

undefined :

nextTurn ()

Returns

undefined :

recordMove (move)

parameter type description
move any

Returns

undefined :

getFirstPiece ($0)

parameter type description
$0 Object
$0.type any
$0.player any

Returns

(Piece | undefined) :

getPieceAt ($0)

parameter type description
$0 Object
$0.x any
$0.y any

Returns

(Piece | undefined) : The piece at the coordinates.

Examples

const piece = getPieceAt({ x: 2, y: 1 });

hasPieceAt ($0)

parameter type description
$0 Object
$0.x any
$0.y any

Returns

boolean : true if there is a piece at the coordinates; otherwise, false .

Examples

const isPiece = hasPieceAt({ x: 4, y: 5 });

removePiece (pieceToRemove)

parameter type description
pieceToRemove any

Returns

undefined :

Examples

removePiece({
     id: '297a7c98-da21-4309-8751-9e187f51259b',
     type: 'pawn',
     x: 1,
     y: 3,
     player: 0
});

select ($0)

parameter type description
$0 Object
$0.x any
$0.y any

Returns

boolean :

unselect ()

Returns

undefined :

isSelectedSquare ($0)

parameter type description
$0 Object
$0.x any
$0.y any

Returns

boolean : true if the coordinates correspond to a selected tile; otherwise, false .

isPawnCapturing ($0)

parameter type description
$0 Object
$0.x any
$0.y any
$0.vectorX any
$0.vectorY any
$0.direction any

Returns

boolean :

isPawnMoving ($0)

parameter type description
$0 Object
$0.x any
$0.y any
$0.vectorX any
$0.vectorY any
$0.firstMove any
$0.direction any

Returns

boolean :

isEnPassant ($0)

parameter type description
$0 Object
$0.x any
$0.y any
$0.vectorX any
$0.vectorY any
$0.direction any

Returns

boolean :

isBishopPattern ($0)

parameter type description
$0 Object
$0.vectorX any
$0.vectorY any

Returns

boolean :

isBishopMoveFree ($0)

parameter type description
$0 Object
$0.origin any
$0.destination any
$0.vector any

Returns

boolean :

isRookPattern ($0)

parameter type description
$0 Object
$0.vectorX any
$0.vectorY any

Returns

boolean :

isRookMoveFree ($0)

parameter type description
$0 Object
$0.origin any
$0.vector any

Returns

boolean :

isKingPattern ($0)

parameter type description
$0 Object
$0.vectorX any
$0.vectorY any

Returns

boolean :

isCastlePattern ($0)

parameter type description
$0 Object
$0.vectorX any
$0.vectorY any

Returns

boolean :

performCastle ($0)

parameter type description
$0 Object
$0.castleVectorX any
$0.selectedPiece any
$0.destination any
$0.from any

Returns

boolean :

isPiecePattern ($0)

parameter type description
$0 Object
$0.destination.x any
$0.destination.y any
$0.origin any
$0.type any
$0.player any
$0.firstMove any

Returns

boolean : Whether the pattern corresponds to the piece

isKingInCheck (kingProjection)

parameter type description
kingProjection any

Returns

boolean :

isGameEnd ($0)

parameter type description
$0 Object
$0.player any (default this.currentPlayer)

Returns

(boolean | string) :

isLegalMove ($0)

parameter type description
$0 Object
$0.destination any
$0.origin any
$0.type any
$0.player any
$0.firstMove any

Returns

boolean :

moveSelectedPiece ($0)

parameter type description
$0 Object
$0.x any
$0.y any

Returns

boolean :

ArtificialIntelligence ()

Examples

const eventHandler = (payload) => console.log(payload);
artificialIntelligence.init({ eventHandler });

Static Members

isIgnoredMessage (message)

Returns whether this event should be emitted or not.

parameter type description
message object

Returns

boolean :

responseParser (message)

Parses UCI output into an event.

parameter type description
message string

Returns

object :

Instance Members

init ($0)

Initializes Stockfish-js.

parameter type description
$0 Object
$0.eventHandler any (default ()=>{})
$0.debugLevel any (default STOCKFISH_DEFAULT_DEBUG_LEVEL)

Returns

instance :

startGame ()

Using this method before playing is required to support more than one game.

Returns

undefined :

sendRawCommand (command)

Sends a command to Stockfish-js.

parameter type description
command string

Returns

undefined :

onMessage (message)

Handles messages sent by Stockfish-js.

parameter type description
message string

Returns

undefined :

emitEvent ($0)

Sends payloads to the event handler.

parameter type description
$0 Object
$0.debugLevel any
$0.payload ...any

Returns

undefined :

computeNextMove (move, fenstring)

Asks to Stockfish-js to compute the best response to this move.

parameter type description
move string
fenstring (string | undefined)

Returns

undefined :

setOption ($0)

Changes an option of the chess engine.

parameter type description
$0 Object
$0.name any
$0.value any