Skip to content
erdem6
Projects
2025Engineer

Chess, from scratch

Chess with all its rules and no chess library: board model, move generation, check and mate detection, and a minimax search with alpha-beta pruning over a tile-based board. Java first, then ported to JavaScript so it runs in the browser. You can play it on this site.

Board model, per-piece move generation, check and mate detection, pawn promotion. No chess library; every rule is written by hand.

The opponent is a minimax search with alpha-beta pruning over a tile-based board representation. Pruning is what makes the difference between a search that finishes and one that does not. It lets the engine stop evaluating a line the moment it is provably worse than something already found.

The part that fought back the most was the "you can't leave your king in check" filter: for every candidate move I copy the board, play the move, and look at whether the king is safe.

The Java core lives on desktop; the JS build runs on this site with no backend at all. I still poke at it. Castling and en passant are next on the list.

Chose
Wrote every rule by hand, including the legality filter for check.
Rejected
A chess library, which would have skipped the only interesting part.

You’re white. Touch a piece.

  • Minimax with alpha-beta pruning
  • No libraries, rules written by hand
  • Playable on this site
  • Java core + a JS port
JavaJavaScriptMinimaxGame Logic