Skip to content

davidlacarta/chess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 Cannot retrieve latest commit at this time.

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status npm version

Chess board

Chess board logic

const chess = new Chess();
const chess = new Chess(
  "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
);

chess.toFen();

// rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

chess.getSquare("e2");

// { square: 'e2', piece: { type: 'p', color: 'w' } }

chess.getMoves("b1");

// [{ square: "c3", piece: null }, { square: "a3", piece: null }];

chess.move("e2", "e4");
chess.toAscii();

// ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜
// ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟
//
//
//         ♙
//
// ♙ ♙ ♙ ♙   ♙ ♙ ♙
// ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖
const chess = new Chess();

chess.move("e4"); // SAN (Standard Algebraic Notation)
chess.toAscii();

// ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜
// ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟
//
//
//         ♙
//
// ♙ ♙ ♙ ♙   ♙ ♙ ♙
// ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖
const chess = new Chess(
  "r1bqkbnr/ppp2ppp/2np4/4p3/2B5/4PN2/PPPP1PPP/RNBQK2R w KQkq - 2 4"
);

chess.toAscii();

// ♜   ♝ ♛ ♚ ♝ ♞ ♜
// ♟ ♟ ♟     ♟ ♟ ♟
//     ♞ ♟
//         ♟
//     ♗
//         ♙ ♘
// ♙ ♙ ♙ ♙   ♙ ♙ ♙
// ♖ ♘ ♗ ♕ ♔     ♖

chess.castlingKing();
chess.toAscii();

// ♜   ♝ ♛ ♚ ♝ ♞ ♜
// ♟ ♟ ♟     ♟ ♟ ♟
//     ♞ ♟
//         ♟
//     ♗
//         ♙ ♘
// ♙ ♙ ♙ ♙   ♙ ♙ ♙
// ♖ ♘ ♗ ♕   ♖ ♔

chess.castlingQueen();

// throw "castling invalid";
const chess = new Chess(
  "r1bqkbnr/ppp2ppp/2np4/4p3/2B5/4PN2/PPPP1PPP/RNBQK2R w KQkq - 2 4"
);

chess.toAscii();

// ♜   ♝ ♛ ♚ ♝ ♞ ♜
// ♟ ♟ ♟     ♟ ♟ ♟
//     ♞ ♟
//         ♟
//     ♗
//         ♙ ♘
// ♙ ♙ ♙ ♙   ♙ ♙ ♙
// ♖ ♘ ♗ ♕ ♔     ♖

chess.target("e1");

// false

chess.target("e5");

// true

chess.targetKing();

// false
const chess = new Chess();

chess.getMovesTurn();

// [ { piece: { type: 'n', color: 'w' },
//     from: 'b1',
//     to: 'c3',
//     capture: null },
//   { piece: { type: 'n', color: 'w' },
//     from: 'b1',
//     to: 'a3',
//     capture: null },
//   { piece: { type: 'n', color: 'w' },
//     from: 'g1',
//     to: 'h3',
//     capture: null },
//   { piece: { type: 'n', color: 'w' },
//     from: 'g1',
//     to: 'f3',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'a2',
//     to: 'a3',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'a2',
//     to: 'a4',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'b2',
//     to: 'b3',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'b2',
//     to: 'b4',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'c2',
//     to: 'c3',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'c2',
//     to: 'c4',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'd2',
//     to: 'd3',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'd2',
//     to: 'd4',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'e2',
//     to: 'e3',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'e2',
//     to: 'e4',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'f2',
//     to: 'f3',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'f2',
//     to: 'f4',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'g2',
//     to: 'g3',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'g2',
//     to: 'g4',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'h2',
//     to: 'h3',
//     capture: null },
//   { piece: { type: 'p', color: 'w' },
//     from: 'h2',
//     to: 'h4',
//     capture: null } ]

About

Chessboard logic with movement check

Resources

Stars

Watchers

Forks

Packages

No packages published