<aside> ♟️ This a guide on how to build a Chess engine from scratch, updated periodically as I further explore the space. This assumes some basic knowledge of Chess, search algorithms, and coding.
Want to know how chess engines work? Or how AI is now better than every human on earth in chess? Or maybe how you can beat your younger brother who is stupidly good at chess? This is the place.
<aside> 👋 This is getting a lot more traffic than I thought it would! This is one of my weekly projects, so if you like it, consider following me on Twitter or text WILL to (833)-225-6887 to get updates when I release something new.
Before you start on your engine, you need a board representation and some form of visualization. I’ve chosen Chess.js and Chessboard.js to start.
Of course, you could build this yourself, but that isn’t really the point of this project. If you’re interested in learning about chess engine board representations, lookup “bitboards” and go from there - lots of interesting ways move generation and board state can be handled with maximum efficiency.
In looking for a good library to work in, I found the Chess.js package. This is a great place to start. It handles all move generation, board state, FEN notation (will get to that in a sec if you don’t know what that is), etc.
chessboardjs.com " Homepage
These hook together so well it’s unbelievable. Being able to publish a website with your chess engine live in the browser is awesome. Here’s a link to a super simple starter repo you can download and run right now, which you’ll be able to follow along with the whole time.
👆 Download and run this, it’ll load up what we’re starting with.
It’s important to start with a good baseline, so we’ll start with an engine that only makes random legal moves. Yeah, it’s dumb, but it’s a great starting point for the rest of the project.
If you download the above repo, you’ll see this. All it does is generate random moves for each player. Run this code! Boom, we have our first engine.