Chessops supports 8 different chess variants, each with unique rules and gameplay mechanics. All variants extend the base Position class and provide specialized implementations for their specific rules.
Supported Variants
Crazyhouse Drop captured pieces back on the board
Atomic Captures cause explosions that destroy surrounding pieces
Antichess Lose all your pieces to win, captures are forced
King of the Hill Get your king to the center to win
Three-check Give check three times to win
Horde White has 36 pawns vs Black’s normal army
Racing Kings Race your king to the 8th rank, no checks allowed
Standard Chess Classic chess rules (Chess class)
Common API
All variant classes share a common interface:
Creating Positions
import { Crazyhouse , Atomic , KingOfTheHill } from 'chessops/variant' ;
// Create default starting position
const crazyhouse = Crazyhouse . default ();
const atomic = Atomic . default ();
const koth = KingOfTheHill . default ();
Creating from Setup
import { Atomic } from 'chessops/variant' ;
import { parseFen } from 'chessops/fen' ;
const setup = parseFen ( 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' ). unwrap ();
const result = Atomic . fromSetup ( setup );
if ( result . isOk ) {
const pos = result . value ;
// Use position
} else {
console . error ( 'Invalid setup:' , result . error );
}
Playing Moves
const pos = Crazyhouse . default ();
// Make a move
pos . play ({ from: 12 , to: 28 }); // e2-e4
// Clone before playing (immutable pattern)
const newPos = pos . clone ();
newPos . play ({ from: 52 , to: 36 }); // e7-e5
Checking Game State
// Check if variant-specific win condition is met
if ( pos . isVariantEnd ()) {
const outcome = pos . variantOutcome ();
if ( outcome ?. winner ) {
console . log ( ` ${ outcome . winner } wins!` );
} else {
console . log ( 'Draw' );
}
}
// Standard checks work too
if ( pos . isCheckmate ()) {
console . log ( 'Checkmate!' );
}
if ( pos . isStalemate ()) {
console . log ( 'Stalemate!' );
}
Variant Selection
Use the defaultPosition helper to create positions by variant name:
import { defaultPosition } from 'chessops/variant' ;
import { Rules } from 'chessops/types' ;
const variant : Rules = 'atomic' ;
const pos = defaultPosition ( variant );
// Works for all variants
const variants : Rules [] = [
'chess' ,
'crazyhouse' ,
'atomic' ,
'antichess' ,
'kingofthehill' ,
'3check' ,
'horde' ,
'racingkings'
];
Validation
Each variant has custom validation rules:
import { Atomic } from 'chessops/variant' ;
import { Result } from '@badrap/result' ;
const result = Atomic . fromSetup ( setup );
if ( result . isErr ) {
// Handle PositionError
const error = result . error ;
console . log ( error . message );
}
Variant-specific rules are enforced during setup validation and move generation.
Next Steps
Crazyhouse Learn about pockets and drop moves
Atomic Chess Understand explosion mechanics