How I made (and got beaten by) a Chess playing bot.

Photo by GR Stocks on Unsplash

How to make a Chess-destroying AI overlord

Okay, maybe that title was a little exaggerated.

Step 1 - Scoring the Chess Board

As any great philosopher (or anyone with common sense) would say:

  1. Advancing your pieces closer to the opposing side (while maintaining the safety of your own pieces)
  2. Threatening the other side’s pieces as much as possible (even if they take one of your pieces, you should be able to take theirs in return)

Step 2 - Making the CNN (not the reporting station)

CNNs (convolutional neural networks) are perfect for this problem — they can process visual data, and extract valuable insights that we can use for our chess bot.

  1. Converts the input to a matrix
  2. Applies “filters” to detect patterns
  3. Processes those patterns numerically (this is where the patterns turn into our output!)
  4. Gives us our output! (in this case, we want a score evaluating any given move)

Step 3 - Miniature Maximization of Minuscule Maximum Minimum Functions

(say that 3 times fast)

A minimax tree!
The entire algorithm, put together.

Step 4 - Getting beaten by my own creation

Luckily for us, this is pretty easy. All we need to do is take a board, send it to our CNN and minimax, extract the move, and execute it!

Not bad, but really confusing for people trying to play against the AI.
Game.py — the function that lets us play the game!
The moves are entered in the terminal on the left side, and the game is hosted using pygame on the right.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aditya Dewan

Aditya Dewan

55 Followers

Building companies. Machine Learning Specialist @Actionable.co. Philosophy x Tech.