Light mode

chess networking

I should start by saying that this is unlike me. Two posts in a month is somewhat of a record around here. But it's black history month, and I've been drinking way too much coffee. Plus, with all these agents automating away my busywork, I've found myself with more free time to do my favorite thing: tinker.

is what I would've written if I had posted this in February like I originally planned. Instead, its May and I'm finally getting back to finishing this up.

Disclaimer: This is the first time I'm doing a bit of a technical deep dive here which is pretty different than the other kinds of writing I typically do. So if there's words in here that look like a different language, that's because it is.

Despite all the work AI has done on my behalf, I'm far more excited about what it can teach me. For the longest time, I've wanted to marry my interest in AI from a technical perspective, with my love for chess. If I could find a way to blend the two, I'd have the chance to play an unfair game. But I knew nothing about how to make those two ideas converge. That is, until I realized that AI can help me fill the gaps along the way.

I've played nearly 14,000 games of chess on chess.com over the past 3 years. A good chunk of it is bullet, but the other half is mainly blitz, which for the uninitiated just means I typically play games with small amounts of time to think. I've always wondered: what if I could take all those games and train a neural network to play like me? How closely could I model my own style? Would it teach me things about my play that are non obvious to me? What if I made it available here? Then anyone could play me and I could learn from those games as well.

Thanks to AI, anything is possible. Below is a summary of everything I learned. And if you want to skip all this and get to the part where you play me, click here

So to start, I explained my plan to Claude and asked what options were available to me. It suggested 3 ranging in varying levels of difficulty. I chose the easiest, which was to use a supervised learning model called a CNN (Convolutional Neural Network) to train on all the games that I played. The basic goal was Given some position, what move am I most likely to make next?.

To explain how the model (a bunch of numbers) "learns" how to answer that question, it's helpful to give some context around what the model sees.

In very simple terms, the network only sees numbers, just like your computer does when showing this screen. We have to give those numbers some meaning in order to make use of them. Every position gets converted into a stack of 13 layers, each one a grid of 1s and 0s. A layer's job is to answer a single question about the state of the board. For example, a single layer might be responsible for telling you where all the black pawns are. Another might tell you what square the white queen is on. When you put all these layers together, you can reconstruct the entire position. And then one last layer answers the question: Whose turn is it?

From there, we can begin the training process.

Before I explain the algorithm, I think it would be helpful to explain some of the terms used

Weights - These are.... you guessed it. Just numbers. But the value we assign to them is that they tell us directionally how to find the answer to the question we're asking. For example, if you have a scale and want to know which two objects are heavier, the one with more weight will have more "influence" over the scale. So too do the weights in a model.

Probability Distribution - This tells us the likelihood of an independent event occurring represented as numbers. All the events in the probability distribution should sum to 1.

Loss function - Functions are just things that take some input and give some output. In this case, it takes in the probability that I made a particular move, and outputs another number that tells me "how wrong" that guess was. The lower the number, the better.

(e.g) probability distribution of a:

  1. coin flip [.5, .5]
  2. fair dice roll [.166, .166, .166, .166, .166, .166]
  3. unfair dice roll [.24, .126, .126, .126, .126, .126]

Okay, back to regularly scheduled programming (I've always wanted to make that joke)

The very high level algorithm is:

  1. Show the model a board position.
  2. Output a probability distribution over the 4096 possible from -> to square combinations.
  3. Check which move I actually played.
  4. Calculate how "wrong" the model was using this thing called a "loss function"
  5. Adjust the weights to make the right answer slightly more likely.
  6. Repeat.

That's it. From there, the model can start to find patterns in the noise.

Learnings

Overall, while I was pleased with the output, I quickly realized what limitations there are with such a constrained model of my games.

For starters, the bot has ~600 fewer ELO points than I do which was pretty surprising. (The math for figuring that out isn't super rigorous mainly because my own ELO is pretty nebulous).

It manages to play a lot of the same openings that I do, but will play the same order irrespective of what my opponent is doing. That would work if I played something like the London, which is known for being a pretty "systematic" opening with few chances for your opponent to do something that surprises you. Instead I play a variation known as the Jobava London, which requires a lot more precision in how you respond. Tangibly, it means that if you do suboptimal things in the opening that "punish" my opening choice, my bot self won't respond. (I will though, so don't play w/ me)

Just when I start to doubt its ability to make sensible moves, it will surprise me by making a capture of a piece I didn't think it would recognize is hanging (free to take without consequence).

It doesn't seem to know how to checkmate. My hunch is that for each of these games, even though I've won a majority of them, I win often on time, and the mates I do get are not consistent enough for the model to "learn" what those positions are. Not to mention, finding mate requires an understanding of multiple positions ahead of where you currently are. It makes sense that a model that can only consider the position in front of it, can't "reason" about the future. It's just data that it doesn't have.

All in all, it gave me a glimmer of hope that this marriage of "just enough" knowledge and an LLM can get you pretty far if you're willing to consider all the different knobs it lets you turn. A year ago, I could never have imagined I'd be able to do anything like this and now, I was able to build something over the course of a weekend.

There's some educational study that looks at just how much information you should expose to a learner to give them the best chance of understanding that subject. Too much information, and you risk overloading them. Too little and no real learning takes place. Instead, the sweet spot is something that sits just above their current understanding. Hard enough to push them in the right direction, but easy enough to be tractable. With AI, I think more of us will be capable of finding that balance.

Replay edits
PastNo text change27034 / 27034Future
Subscribe to get notified when I post new content.