Skip to content

v1.0.0

Latest
Compare
Choose a tag to compare
@jhlywa jhlywa released this 11 Jan 00:45

v1.0.0

A big thank you to all the contributors that helped make this release possible! This is a major version update and there are many new features and breaking changes. Please read below for more info.

Typescript

chess.js has been rewritten in TypeScript. Exported types are as follows:

  • Chess class
  • Move class
  • Piece
  • Color
  • Square
  • PieceSymbol

New Methods

  • attackers(square, color) - returns a list of squares occupied by pieces of color that are attacking the given square
  • getCastlingRights(color) - returns { k: boolean, q: boolean } indicating castling rights for color
  • setCastlingRights(color, rights)
  • isAttacked(square, color) - returns true if square is attacked by color
  • isDrawByFiftyMoves()
  • moveNumber()
  • setHeader(key, value), removeHeader(key), getHeaders()
  • removeComment(), removeComments()

Breaking Changes

Exceptions instead of null

The following functions no longer return null when an error occurs. Instead, they now throw exceptions to provide the user with more detailed error information.

  • .load()
  • .loadPgn()
  • .move()
  • Chess() constructor

Function Names

The functions below have been converted to camel-case:

  • game_over -> isGameOver
  • in_check -> isCheck
  • in_checkmate -> isCheckmate
  • in_draw -> isDraw
  • is_stalemate -> isStalemate
  • in_threefold_repetition -> isThreefoldRepetition
  • insufficient_material -> isInsufficientMaterial
  • load_pgn -> loadPgn
  • set_comment -> setComment
  • get_comment -> getComment
  • get_comments -> getComments
  • delete_comment -> deleteComment
  • delete_comments -> deleteComments
  • validate_fen -> validateFen

Function Arguments and Return Values

The arguments and return values for the following functions have changed:

  • load_pgn(pgn, { sloppy: true }) becomes loadPgn(pgn) (strict defaults to false)
  • move('Nb7', { sloppy: true }) becomes moves('Nb7')
  • clear(true) should now be written as clear({ preserveHeader: true })
  • load(fen, true) should now be written as load(fen, { preserveHeader: true })
  • validateFen(fen) now returns { ok: boolean, error?: string }

Deprecations

  • The flags field in the Move object is deprecated. Use the new helper methods below to determine the move type:
    • .isCapture() - is the move a regular capture? NOTE: this is false for an en-passant
    • .isEnPassant() - is the move an en-passant capture?
    • .isBigPawn() - is the move a 2-rank pawn move?
    • .isPromotion() - is the move a pawn promotion?
    • .isKingsideCastle() - is the move a kingside castle?
    • .isQueensideCastle() - is the move a queenside castle?
  • The header function has been deprecated in favor of setHeader and getHeaders
  • The deleteComment and deleteComments functions have deprecated in favor of removeComment and removeComments

Improvements

  • Change .load to throw an exception when loading invalid FEN (@jhlywa - ac977ed )
  • Change .move to throw an exception on illegal move (@jhlywa - 8523db8)
  • Change .loadPgn to throw an exception when encountered error (@jhlywa - #TODO)
  • Allow the user to omit castling rights, en passant square, and move numbers when calling .load (@jhlywa - 8523db8)
  • Add isAttacked to determine attackers of a specific square (@jhlywa - 9b49454)
  • Validate king presence in validateFen (@jhlywa - a137478)
  • Allow spaces between the bracket and tag in PGN header (@jhlywa - 5f48a68)
  • Allow user to specify a promotion piece (when supplying a verbose move) even if the move is not a promotion (@jhlywa - 8e71084)
  • Add before and after FEN to Move object (@jhlywa - d42b0)
  • Add removeHeader method (@angarc - #388)
  • Fixed moves() when there are no kings (@neofight78 - #386)
  • Handle captures with missing ‘x’ (@neofight78 - #385)
  • Add methods for getting/setting castling rights (getCastlingRights, setCastlingRights) (@neofight78 - 7cb2d34)
  • Ensure put/remove functions update ep square (@neofight78 - #398 )
  • Make moveNumber accessible (@neofight78 - #399)
  • Add support for both ESM and CommonJS environments (@jorgecasar - #406)
  • Add check for invalid pawn placement in validateFen (@Manukyanq - #412)
  • Update castling rights and en passant square in .put() (@gavin-lb - 55181a9)
  • Add skipValidation option to .load (@jhlywa - e2ff91c)
  • Add isDrawByFiftyMoves (@HarshilPatel007 - #477)
  • Add type annotations (@HarshilPatel007 - #478)

Bug Fixes