0.2.10 • Published 2 years ago

chess_typescript v0.2.10

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

A minimal Chess Engine fully written in Typescript.

  • All moves in chess
  • Move validation
  • FEN support
  • The board is a single-dimensional array (chessGame.board.tiles)
  • Move history
  • Scalable
  • Challenging AI

Usage:

  • DENO
import { ... } from 'https://deno.land/x/chess_typescript/mod.ts'
  • NODE
npm i chess_typescript
import { ... } from 'chess_typescript'

Example: Easy AI vs Monkey AI

// import ....

const main = async () => {
	const chessGame = ChessGame.newStandardGame();
	const easyAI = new AI.EasyAI(chessGame);
	const monkeyAI = new AI.MonkeyAI(chessGame);

	// if we didn't set the piece type on promote, the piece will turn into a queen
	chessGame.onBlackPromote = () =>  chessGame.mover.promoteLastMoveTo(Utils.randomFromArray([Type.bishop, Type.queen, Type.knight, Type.rook]));

	console.log(chessGame.board.toString());
	/**
		♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ 
		♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ 




		♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ 
		♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ 
	 */

	let mv = 0;

	while (!chessGame.gameOver) {
		console.clear();
		// easyAI as white, and monkeyAI as black
		const move = mv++ % 2 == 0 ? easyAI.getMove() : monkeyAI.getMove();
		if (move) {
			chessGame.mover.moveStrict(move.from, move.to);
			// NEEDED
			chessGame.mover.next();
		}
		console.log(move);
		console.log(chessGame.board.toString());
		await Utils.sleep(500);
	}

	console.log(chessGame.gameOverReason + '!');
};

main().catch((err) => console.error(err));
0.2.10

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago