
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
wasm-chess
Advanced tools
A minimal, fast chess engine written in Rust and compiled to WebAssembly. Perfect for chess applications, games, and educational projects.
wee_alloc
npm install tiny-chess-wasm
import { WasmChess } from 'tiny-chess-wasm';
// Create a new game (starts with standard opening position)
const chess = new WasmChess();
// Or load from FEN string
const chess = new WasmChess("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
// Get legal moves for a piece at position (row, col)
const moves = chess.getMoves(1, 4); // Get moves for white pawn at e2
// Make a move
// chess.movePiece(moves[0])
chess.movePiece({
from_row_idx: 1,
from_col_idx: 4,
to_row_idx: 3,
to_col_idx: 4,
is_passant: false,
is_castle: false,
piece: "WhitePawn"
});
// Get current position as FEN
const currentFen = chess.toFen();
// Check game result
const result = chess.getGameResult();
if (result === "WhiteCheckmate") {
console.log("White wins!");
}
new WasmChess(fen?: string)
fen
(optional): FEN string for initial position. Defaults to standard starting position.getMoves(row: number, col: number): Move[]
Get all legal moves for a piece at the specified position.
getPseudoMoves(row: number, col: number): Move[]
Get all pseudo-legal moves (may leave king in check).
movePiece(move: Move): void
Execute a move and update the game state.
validateMove(move: Move): boolean
Check if a move is legal without executing it.
toFen(): string
Get the current position as a FEN string.
getGameResult(): GameResult | null
Get the game result or null
if game is ongoing.
squareToChessNotation(row: number, col: number): string | null
Convert a square to chess notation (e.g., "e4", "a1").
squareFromChessNotation(notation: string): Square | null
Convert a chess notation to a square (e.g., "e4", "a1").
export type Board = (PieceType | null)[][];
export type ParsedFen = {
board: Board;
state: ParsedFenState;
}
export type ParsedFenState = {
en_passant_square: Square | null;
on_turn: Player;
castle_white_short: boolean;
castle_white_long: boolean;
castle_black_short: boolean;
castle_black_long: boolean;
half_moves: number;
full_moves: number;
}
export type Square = {
row: number;
col: number;
}
export type Move = {
from_col_idx: number;
from_row_idx: number;
to_col_idx: number;
to_row_idx: number;
is_passant: boolean;
is_castle: boolean;
piece: PieceType;
}
export type Moves = Move[];
export type GameResult = "WhiteCheckmate" | "BlackCheckmate" | "Stalemate" | "InsufficientMaterial" | "FiftyMoveRule" | "ThreefoldRepetition" | null;
export type Player = "White" | "Black";
export type PieceType =
| "WhitePawn" | "WhiteRook" | "WhiteBishop" | "WhiteKnight" | "WhiteQueen" | "WhiteKing"
| "BlackPawn" | "BlackRook" | "BlackBishop" | "BlackKnight" | "BlackQueen" | "BlackKing";
Static utility functions for working with FEN strings:
import { parseFen, stringifyFen } from 'tiny-chess-wasm';
// Parse FEN to game object
const parsedGame = parseFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
// Convert game object back to FEN
const fenString = stringifyFen(parsedGame);
The engine uses a 0-indexed coordinate system:
Example: Square "e4" = { row: 3, col: 4 }
MIT © Daniel Bilek
FAQs
A minimal chess engine written in Rust and compiled to WebAssembly.
The npm package wasm-chess receives a total of 18 weekly downloads. As such, wasm-chess popularity was classified as not popular.
We found that wasm-chess demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.