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
- So first of all, you'll need to create a new
Game
:
import { Game } from "ChessGame";
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);
Moving a piece
- The current colour's move can be found by running:
import { isWhiteMove } from "ChessGame";
console.log(isWhiteMove);
The game will alternate the current colour at the end of the turn. This IS a boolean.