Socket
Socket
Sign inDemoInstall

@samcjparry/ts-chess

Package Overview
Dependencies
395
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @samcjparry/ts-chess

## Introduction


Version published
Weekly downloads
2
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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);

// 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.

FAQs

Last updated on 22 May 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc