Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

ChessInstance

interface ChessInstance {
ascii(): string;
board(): Array<Array<{
type: PieceType;
color: PieceColor;
square: Square;
}
| null
>
>
;
clear(): void;
delete_comment(): string | undefined;
delete_comments(): Comment[];
fen(): string;
game_over(): boolean;
get(square: Square): Piece | null;
get_comment(): string | undefined;
get_comments(): Comment[];
header(...args: string[]): {
[key: string]: string | undefined;
}
;
history(options?: {
verbose?: false | undefined;
}
): string[];
history(options: {
verbose: true;
}
): Move[];
history(options?: {
verbose?: boolean | undefined;
}
): string[] | Move[];
in_check(): boolean;
in_checkmate(): boolean;
in_draw(): boolean;
in_stalemate(): boolean;
in_threefold_repetition(): boolean;
insufficient_material(): boolean;
load(fen: string): boolean;
load_pgn(pgn: string, options?: {
newline_char?: string | undefined;
sloppy?: boolean | undefined;
}
): boolean;
move(move: string | ShortMove, options?: {
sloppy?: boolean | undefined;
}
): Move | null;
moves(options: {
legal?: boolean | undefined;
verbose: true;
square?: string | undefined;
piece?: PieceType;
}
): Move[];
moves(options?: {
legal?: boolean | undefined;
verbose?: false | undefined;
square?: string | undefined;
piece?: PieceType;
}
): string[];
moves(options?: {
legal?: boolean | undefined;
verbose?: boolean | undefined;
square?: string | undefined;
piece?: PieceType;
}
): string[] | Move[];
pgn(options?: {
max_width?: number | undefined;
newline_char?: string | undefined;
}
): string;
put(piece: Piece, square: Square): boolean;
remove(square: Square): Piece | null;
reset(): void;
set_comment(comment: string): void;
square_color(square: Square): SquareColor;
square_color(square: string): SquareColor | null;
turn(): PieceColor;
undo(): Move | null;
validate_fen(fen: string): {
valid: boolean;
error_number: number;
error: string;
}
;
}

§Methods

§
ascii(): string
[src]

Returns a string containing an ASCII diagram of the current position.

@return

A string containing an ASCII diagram of the current position.

§
board(): Array<Array<{
type: PieceType;
color: PieceColor;
square: Square;
}
| null
>
>
[src]
§
clear(): void
[src]

Clears the board of all pieces.

§
delete_comment(): string | undefined
[src]
§
delete_comments(): Comment[]
[src]
§
fen(): string
[src]

Returns the FEN string for the current position.

@return

the FEN string for the current position.

§
game_over(): boolean
[src]

Returns true if the game has ended via checkmate, stalemate, draw, threefold repetition, or insufficient material. Otherwise, returns false.

@return

True if the game has ended via checkmate, stalemate, draw, threefold repetition, or insufficient material. Otherwise, returns false.

§
get(square: Square): Piece | null
[src]

Returns the piece on the square

@param square

the square to get the piece on.

@return

null if no piece is on that square, or it is not a valid square. Otherwise a piece object.

§
get_comment(): string | undefined
[src]
§
get_comments(): Comment[]
[src]
§
history(options?: {
verbose?: false | undefined;
}
): string[]
[src]

Returns a list containing the moves of the current game. Options is an optional parameter which may contain a 'verbose' flag. See .moves() for a description of the verbose move fields.

@param options

an optional parameter which may contain a 'verbose' flag.

@return

a list of all moves of the current game. They will be strings if not passed the verbose flag.

§
history(options: {
verbose: true;
}
): Move[]
[src]

Returns a list containing the moves of the current game. Options is an optional parameter which may contain a 'verbose' flag. See .moves() for a description of the verbose move fields.

@param options

an optional parameter which may contain a 'verbose' flag.

@return

a list of all moves of the current game. They will be strings if not passed the verbose flag.

§
history(options?: {
verbose?: boolean | undefined;
}
): string[] | Move[]
[src]

Returns a list containing the moves of the current game. Options is an optional parameter which may contain a 'verbose' flag. See .moves() for a description of the verbose move fields.

@param options

an optional parameter which may contain a 'verbose' flag.

@return

a list of all moves of the current game. They will be strings if not passed the verbose flag.

§
in_check(): boolean
[src]

Returns true or false if the side to move is in check.

@return

true or false if the side to move is in check.

§
in_checkmate(): boolean
[src]

Returns true or false if the side to move has been checkmated.

@return

true or false if the side to move has been checkmated.

§
in_draw(): boolean
[src]

Returns true or false if the game is drawn (50-move rule or insufficient material).

@return

true or false if the game is drawn (50-move rule or insufficient material).

§
in_stalemate(): boolean
[src]

Returns true or false if the side to move has been stalemated.

@return

true or false if the side to move has been stalemated.

§
in_threefold_repetition(): boolean
[src]

Returns true or false if the current board position has occurred three or more times.

@return

true or false if the current board position has occurred three or more times.

§
insufficient_material(): boolean
[src]

Returns true if the game is drawn due to insufficient material (K vs. K, K vs. KB, or K vs. KN); otherwise false.

@return

True if the game is drawn due to insufficient material (K vs. K, K vs. KB, or K vs. KN); otherwise false.

§
load(fen: string): boolean
[src]

The board is cleared, and the FEN string is loaded. Returns true if the position was successfully loaded, otherwise false

@param fen

the fen formatted string to load

@return

true if the position was successfully loaded, otherwise false

§
load_pgn(pgn: string, options?: {
newline_char?: string | undefined;
sloppy?: boolean | undefined;
}
): boolean
[src]

Load the moves of a game stored in Portable Game Notation.

@param pgn

the pgn should be a string in Portable Game Notation.

@param options

An optional object which may contain a string newline_char and a boolean sloppy.

@return

The method will return true if the PGN was parsed successfully, otherwise false.

§
move(move: string | ShortMove, options?: {
sloppy?: boolean | undefined;
}
): Move | null
[src]

Attempts to make a move on the board, returning a move object if the move was legal, otherwise null. The .move function can be called two ways, by passing a string in Standard Algebraic Notation (SAN), Or by passing .move() a move object (only the 'to', 'from', and when necessary 'promotion', fields are needed).

@param move

Must be either a string in Standard Algebraic Notation (SAN), or a move object (only the 'to', 'from', and when necessary 'promotion', fields are needed)

@param options

An optional sloppy flag can be used to parse a variety of non-standard move notations:

@return

The move as a full object is returned if the move was valid, and the chess board's state changes. If the move was invalid, null is returned and the state does not update.

§
moves(options: {
legal?: boolean | undefined;
verbose: true;
square?: string | undefined;
piece?: PieceType;
}
): Move[]
[src]

Returns a list of legal moves from the current position. The function takes an optional parameter which controls the single-square move generation and verbosity.

@param options

an optional parameter which controls the single-square move generation and verbosity.

@return

The list of all valid moves, either in SAN format, or as verbose objects.

§
moves(options?: {
legal?: boolean | undefined;
verbose?: false | undefined;
square?: string | undefined;
piece?: PieceType;
}
): string[]
[src]

Returns a list of legal moves from the current position. The function takes an optional parameter which controls the single-square move generation and verbosity.

@param options

an optional parameter which controls the single-square move generation and verbosity.

@return

The list of all valid moves, either in SAN format, or as verbose objects.

§
moves(options?: {
legal?: boolean | undefined;
verbose?: boolean | undefined;
square?: string | undefined;
piece?: PieceType;
}
): string[] | Move[]
[src]

Returns a list of legal moves from the current position. The function takes an optional parameter which controls the single-square move generation and verbosity.

@param options

an optional parameter which controls the single-square move generation and verbosity.

@return

The list of all valid moves, either in SAN format, or as verbose objects.

§
pgn(options?: {
max_width?: number | undefined;
newline_char?: string | undefined;
}
): string
[src]

Returns the game in PGN format. Options is an optional parameter which may include max width and/or a newline character settings.

@param options

optional object which may include max width and/or a newline character settings.

@return

the current game state in PGN format.

§
put(piece: Piece, square: Square): boolean
[src]

Place a piece on the square where piece is an object with the form { type: ..., color: ... }. put() will fail when passed an invalid piece or square, or when two or more kings of the same color are placed.

@param piece

the piece to put somewhere on the game board.

@param square

the square on the chess board to place the piece at.

@return

true if the piece was successfully placed, otherwise, the board remains unchanged and false is returned.

§
remove(square: Square): Piece | null
[src]

Remove and return the piece on square.

@param square

the square to remove the piece from, e.g. "b6"

@return

null if no piece was removed, otherwise an object with the removed piece's type and color.

§
reset(): void
[src]

Reset the board to the initial starting position.

§
set_comment(comment: string): void
[src]
§
square_color(square: Square): SquareColor
[src]

Returns the color of the square ('light' or 'dark').

@param square

the square to check if it is light or dark.

@return

"light" if a light square, "dark" if a dark square, or null if not a valid square.

§
square_color(square: string): SquareColor | null
[src]

Returns the color of the square ('light' or 'dark').

@param square

the square to check if it is light or dark.

@return

"light" if a light square, "dark" if a dark square, or null if not a valid square.

§

Returns the current side to move.

@return

"b" if Black is the side to move, otherwise "w" for White.

§
undo(): Move | null
[src]

Take back the last half-move, returning a move object if successful, otherwise null.

@return

the move object that was undone if successful, otherwise null.

§
validate_fen(fen: string): {
valid: boolean;
error_number: number;
error: string;
}
[src]

Returns a validation object specifying validity or the errors found within the FEN string.

@param fen

the fen formatted string to validate