1.0.2 • Published 2 years ago

@samcjparry/ts-chess v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

TypeScript Chess Engine

Introduction

  • Hello! Welcome to my chess engine. This was my exploration into object orientated programming using TypeScript.
  • When creating this project, I tried to stick to SOLID principles as much as possible, but this was my first time so go easy on me.

How To Use

  • You can add the package as a dependency using npm:
npm install @samcjparry/ts-chess
  • Or using yarn:
yarn add @samcjparry/ts-chess
  • Then first of all, you'll need to create a new Game:
import { Game } from "@samcjparry/ts-chess";

const game = new Game();
  • If you want to create a new game with custom pieces, you will have to create an array with the pieces you want and pass it as an argument when you create the game:
  • ACHTUNG MINEFIELD - The colours 'White' and 'Black' are represented by the numbers 0 and 1 respectively. This is because I wanted to use an enum. I'm aware that if something is one of two things it should be a boolean but this is my engine so sue me.
const pieces = [
  { piece: "Kg4", colour: 0 },
  { piece: "Nd3", colour: 1 },
  { piece: "d4", colour: 1 },
];

const game = new Game(pieces);

// Will spawn a white king on square g4, a black knight on square d3, and a black pawn on square d4
  • Also worthy of note is that I use standard chess notation as much as possible, so...

    • Named pieces are notated thus:
      • K - King
      • Q - Queen
      • R - Rook
      • N - Knight
      • B - Bishop
    • Pawns aren't notated, so if you just pass in a square it will generate a pawn in that square.

Moving a piece

  • The current colour's move can be found by running:
import { isWhiteMove } from "ChessGame";

console.log(isWhiteMove); // logs true/false

The game will alternate the current colour at the end of the turn. This IS a boolean.