A chess model made to be bad at chess
Another {Programming, Games, Apps, and Society} project! This one was a team project, with [Daniel Lago] and Ricardo, please check them out :).
Inspiration
When we were brainstorming what we wanted to do for the project, I brought up a chess bot, specifically because I had just watched the Tom7 [30 Chess Engines] video, which is awesome. Ricardo then suggested that we should make the bot as bad as possible, and that's where we began!
Overview
For our tech stack, we chose {Python} with tensorflow for the actual AI part, and Tkinter for the UI.
The main principle behind the actual "AI" part of this project is that there's a model that takes in a custom matrix $input$ that has the dimensions $(1, 768)$. The pieces are mapped like this $rook = [0,0,0,0,0,1]$, $pawn = [1,0,0,0,0,0]$, etc. By training this model, we can give any chess board a score in "centipawns", and that can be used to actually play the game.
The model then has the following architecture: 700 neurons, 800 neurons, 400 neurons, 20% dropout, 200 neurons, 1 neuron (output). All are using "relu" activation, that is a rectified linear, where $x = \begin{cases} x &\text{if } x \ge 0 \\ 0 &\text{otherwise} \end{cases}$. The activation function basically says that when the sum of weights and biases input to the neuron is less than zero, it outputs zero, and above zero it just outputs the sum.
We trained this model on a bunch of chess games from the [lichess elite database], which is a compilation of games from people who have an ELO on lichess of 2400+. We ran those games through stockfish, the best chess engine "on the market" (it's open source), and used the board-evolution pairs as the x-y pairs for our algorithm. The accuracy wasn't perfect, and didn't get much better (it was stable around 1.5%), but with the way our algorithm worked, we needed to get close to the actual evaluation, not be perfectly on target.
The total training time took about 5 hours, and the preprocessing came out to about 2 hours.
UI
The model was only for evaluation, so we need to actually plug it into something, which I made using a TKinter canvas! It just plots the board, and tracks clicks to translate them to moves.
When you click on the first square, the python chess module can actually give you legal moves from that square, so I color those a nice shade of green based on the great board colors Ricardo chose.
The AI then moves once you move, and it optimizes your score while minimizing it's own, to ideally make the worst move.
Demo
Real-world uses
Obviously AI is a huge industry right now. I have large apprehensions about the current trends of "genAI", on it's legality, ethics, and environmental impact.
However, the core concepts of neural networks are extremely useful, and have many valid use cases, like gesture recognition, and many things in the medical field. I remain skeptical of people who claim that they are the peak of AI, though, and I personally think something like the Expert Systems of old will be far more useful than any LLM if we're working towards AGI. And in many cases, things like the [$1 Unistroke Gesture Recognizer], which are human-made and tuned algorithms, are more efficient and effective than a NN.
Source code
I would love to release the source, but currently it's all kinds of janky and not-documented right now, as well as a mess, so I'll try to get it ready, and if you really want it, email me.
Links
incoming(1) | pgas