# Simon Builds a Chess AI with Minimax

I’ve been terrible at keeping this blog up to date. One of Simon’s best project in December 2019 was creating a chess robot and I haven’t even shared it here.

We were joking how this is Simon’s baby and her name is Chessy. Simon also made an improved version with a drop-down menu allowing to choose 1 to 5 steps ahead difficulty level (warning: levels 4 and 5 may run quite slowly): https://chess-ai-user-friendly–simontiger.repl.co/

Simon’s original 2-steps-ahead game: https://chess-ai–simontiger.repl.co/ Code: https://repl.it/@simontiger/Chess-AI

While researching how to apply the Minimax algorithm, Simon has relied on Sebastian Lague’s Algorithms Explained – minimax and alpha-beta pruning; Keith Galli’s How does a Board Game AI Work? (Connect 4, Othello, Chess, Checkers) – Minimax Algorithm Explained; a Medium article on Programming a Chess AI: A step-by-step guide to building a simple chess AI by Lauri Hartikka; of course, The Coding Train’s challenge Tic Tac Toe AI with Minimax; and What is the Minimax Algorithm? – Artificial Intelligence by Gaurav Sen.

Simon contributed his chess robot to the MINIMAX coding challenge page on the Coding Train website:

And naturally we’ve had a lot of fun simply playing with Chessy as a family:

# MathsJam Antwerp 20 November 2019. A Blast and a Responsibility.

Today, Simon returned to a problem he first encountered at a MathsJam in summer: “Pick random numbers between 0 and 1, until the sum exceeds 1. What is the expected number of numbers you’ll pick?” Back in June, Simon already knew the answer was e, but his attempt to prove it didn’t quite work back then. Today, he managed to prove his answer!

The same proof in a more concise way:

At MathsJam last night, Simon was really eager to show his proof to Rudi Penne, a professor from the University of Antwerp who was sitting next to Simon last time he gave it a go back in June. Rudi kept Simon’s notes and told me he really admired the way Simon’s reasoning spans borders between subjects (the way Simon can start with combinatorics and jump to geometry), something that many students nurtured within the structured subject system are incapable of doing, Rudi said. Who needs borders?

Later the same evening, Simon had a blast demonstrating the proof to a similar problem to a larger grateful and patient audience, including Professor David Eelbode. The first proof was Simon’s own, the second problem (puzzle with a shrinking bullseye) and proof came from Grant Sanderson (3Blue1Brown) on Numberphile.

“Don’t allow any constraints to dull his excitement and motivation!” Rudi told me as Simon was waiting for us to leave. “That’s a huge responsibility you’ve got there, in front of the world”.

# Simon edits his sisters vlog and does the subtitles

Simon’s sister Neva has started a vlog and Simon, busy as he is, enjoys editing her videos. For the first 17-minute video he has also done all the subtitles (translating from Dutch to English), which was a project that took him two days and something like 7 hours of work! Neva, in her turn, has got Simon increasingly interested in environmental issues.

# Simon’s Random Number Generator

This one’s back from mid-October, forgot to post here.

Simon created a random number generator that generates a frequency, and then picks it back up. Then, it calculates the error between the generated frequency and the picked up frequency. This is one of my community contributions for a Coding Train challenge: https://thecodingtrain.com/CodingChallenges/151-ukulele-tuner.html

Link to the random number plots: https://www.wolframcloud.com/env/monajune0/ukalele%20tuner%20generated%20random%20number%20analysis.nb
Link to Daniel Shiffman’s live stream featured at the beginning of this vid: https://youtu.be/jKHgVdyC55M

# Make 24 with Teachable Machine in p5, ml5.

Simon has worked really hard for several days on his first machine learning community contribution! He has created this mini-series about building a game of Make 24 with Google’s Teachable Machine that he trained to recognise gestures as a game controller.

“It’s the first time I’m using ml5 from scratch! I’ve also built in a feature to enable the users to train their own models!”

Link to my ml5 project: https://editor.p5js.org/simontiger/full/McNY2_ay_
Code: https://editor.p5js.org/simontiger/sketches/McNY2_ay_

Link to my game of Make 24 without ml5/Teachable Machine: https://editor.p5js.org/simontiger/full/qH_ZSvup5
Code: https://editor.p5js.org/simontiger/sketches/qH_ZSvup5

# Brilliant Discussions

This is an example of the learning style that Simon enjoys most. He really likes doing the daily challenges on Brilliant.org. He later sometimes discusses them with other participants or even writes wikis!

# Why the Golden Ratio and not -1/the Golden Ratio?

Take any real number and call it x. Then plug it into the equation f(x) = 1 + 1/x and keep doing it many times in a row, plugging the result back into the equation.

At some point you will see that you arrive at a value that will become stable and not change anymore. And that value will be… φ, the golden ratio!

But this equation also has another answer, -1/φ. If you plug that value into the equation, it will be the same, too. The real magic happens once you have rounded the -1/φ down (or up), i.e. once what you plug into the equation is no longer exactly -1/φ. What happens is that, if you keep going, you will eventually reach… φ as your answer!

Simon saw this interesting fact in a video by 3Blue1Brown and then came up with a proof as to why it happens.

Simon also sketched his proof in GeoGebra: https://www.geogebra.org/classic/zxmqdspb

# Simon having fun solving math puzzles on Twitter.

While in Southern France, Simon really enjoyed solving this puzzle (he originally saw in a Brilliant.org vid). He was so happy with his solution he kept drawing it out on paper and in digital apps, and later shared the puzzle on Twitter. This sparked quite a few reactions from fellow math lovers, encouraged Brilliant to tweet new puzzles and now Brilliant follows Simon on Twitter, how cool is that!

# Drawing with Turtle

Here we are, on the day of my 40th birthday, while recording a lesson of drawing with turtle in Python. It was meant to be my birthday present, a beginner-friendly hour of code, in which Neva would also be able to take an active part. We ended up recording two beautiful sessions only to find out later that our screen capture video was irreparably corrupted (never record in mp4 in OBS). Simon was inconsolable. We also thought this webcam recording was gone but rediscovered it a day later. So nice to have it as a memory.

And I’m relieved to say that we have managed to redo the whole project from scratch today (sadly without Neva’s participation this time as she had better things to do, so I look rather redundant sitting there next to Simon giving the lesson). Once Simon is done with the editing (which is another two days of work I’m afraid), he will upload the hour of code on YouTube. He also plans to create a website for this project to enable his “students” to draw in a built-in application.

From our session today:

And here is an example of Simon drawing with turtle for his own pleasure, a Serpinski triangle in Python (a few days ago):

# The Brachistochrone

Simon believes that he has found a mistake in one of the installations at the Technopolis science museum. Or at least that the background description of the exhibit lacks a crucial piece of info. The exhibit that allows to simultaneously roll three equal-weight balls down three differently shaped tracks, with the start and the end at identical height in all the three tracks, supposes that the ball in the steepest track reaches the end the quickest. The explanation on the exhibit says that it is because that ball accelerates the most. Simon has noticed, however, that the middle track highly resembles a cycloid and says a cycloid is known to be the fastest descent, also called the Brachistochrone Curve in mathematics and physics.

In Simon’s own words:

You need the track to be steep, because then it will accelerate more – that’s right. But it also has to be quite a short track, otherwise it takes long to get from A to B – which is not in the explanation. It’s not the steepest track, it’s the balance between the shortest track and the steepest track.

Galileo Galilei thought that it is the arc of a circle. But then, Johan Bernoulli took over, and proved that the cycloid is the fastest.

The (only) most elegant proof I’ve seen so far is in this 3Blue1Brown video: https://www.youtube.com/watch?v=Cld0p3a43fU

There’s also a VSauce1 video, where they made a mechanical version of this (like Technopolis): https://www.youtube.com/watch?v=skvnj67YGmw