Skip to content

0x88.js is a JavaScript chess board class that utilises the 0x88 hexadecimal board representation.

Notifications You must be signed in to change notification settings

martinogden/0x88.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

0x88.js

0x88.js is a JavaScript chess board library. It takes care of:

  • Board and piece representation
  • Importing and exporting board states to FEN notation
  • Move validation
  • Board history and state

Basic usage

Instantiate board from a FEN string

> var fen = 'rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq e3 0 2'
>   , board = new Board(fen);

How many legal moves can the player currently make?

> var moves = board.moves();
> moves.length
30

Make a move

Let's choose the first move in the moves array

> var move = moves[0]
> board.do(move);
   + ------------------------ +
8  |  r  n  b  q  k  b  n  r  |
7  |  p  p  .  p  p  p  p  p  |
6  |  .  .  .  .  .  .  .  .  |
5  |  .  .  p  .  .  .  .  .  |
4  |  .  .  .  .  P  .  .  .  |
3  |  N  .  .  .  .  .  .  .  |
2  |  P  P  P  P  .  P  P  P  |
1  |  R  .  B  Q  K  B  N  R  |
*  + ------------------------ +
      A  B  C  D  E  F  G  H  

Undo move and return board to previous state using undo method

> board.undo();
> board.toString();
   + ------------------------ +
8  |  r  n  b  q  k  b  n  r  |
7  |  p  p  .  p  p  p  p  p  |
6  |  .  .  .  .  .  .  .  .  |
5  |  .  .  p  .  .  .  .  .  |
4  |  .  .  .  .  P  .  .  .  |
3  |  .  .  .  .  .  .  .  .  |
2  |  P  P  P  P  .  P  P  P  |
1  |  R  N  B  Q  K  B  N  R  |
*  + ------------------------ +
      A  B  C  D  E  F  G  H  

Print board FEN representation and verify it is the same as the initial FEN string

> board.fen();
'rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq e3 0 2'

Tests

Unit Tests

0x88.js has a suite of unit tests written using qUnit. You can run the test suite in the browser at ./tests/index.html

Performance Tests (perft & divide)

Count number of move possible from this position at depth n

> var fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';
> board.perft(1);
20
> board.perft(2);
400
> board.perft(3);
8902
> board.perft(4);
197281

Notes

It is very much work in progress at the moment, more features will be added soon!

Licence

Licensed for use under Attribution 3.0 unported.

About

0x88.js is a JavaScript chess board class that utilises the 0x88 hexadecimal board representation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published