You are browsing as a guest. Sign up (or log in) to start making projects!

playing chess through a CNN

  • 1 Devlogs
  • 55 Total hours

chesscnn — an AlphaZero-style chess engine that plays from a neural network instead of hand-coded rules. A convolutional neural net (PyTorch: residual tower with separate policy + value heads) reads the board as a 19-plane tensor and outputs move probabilities + a position score, and a PUCT Monte-Carlo Tree Search uses those to choose moves. It comes with a full training stack (self-play, replay buffer, PGN bootstrap, arena/Elo), a CLI, and a Streamlit web app where you play the engine and watch its eval bar, principal variation, and policy heatmap live. ~9,000 lines of Python, 53 passing tests; python-chess guarantees every move is legal.

Ship #1

Made chesscnn — a chess engine that picks its moves from a convolutional neural network instead of hand-written rules, AlphaZero-style. The net (PyTorch, a residual tower with two heads) looks at the board as a stack of 19 image-like planes and outputs both a move-probability map and a single "who's winning" score. A PUCT Monte-Carlo Tree Search then uses those to actually play. There's a CLI and a Streamlit web app where you can play it and watch its eval bar, its predicted line, and a heatmap of where it wants to move.
Challenging: encoding chess moves for the network was the rabbit hole — every possible move has to map to one of 4,672 output slots (the 8×8×73 scheme), and promotions/castling/en-passant all have edge cases. I round-tripped 219k moves to prove the mapping never collides. The other hard part was getting it to play well without a giant training run — a freshly-initialized net plays nonsense, so I blend the network's evaluation with a classical hand-crafted one and let the search do the heavy lifting.
Proud of: it plays real openings out of the box (it'll walk into a Ruy Lopez or a Pirc), it found a tactic in testing (won a hanging queen), and it went 0 losses across 14 games vs a random-mover. ~9,000 lines of Python with 53 passing tests, and a full training stack (self-play → replay buffer → trainer → arena/Elo) if you want to make it stronger.

To test it: clone github.com/advaycode/CNN1, pip install -r requirements-app.txt, then streamlit run chesscnn/app.py and play it in your browser.

  • 1 devlog
  • 55h
Try project → See source code →

Followers

Loading…