Code Bullet: I created an AI to Play Chess
In this AI video ...
Using mini-max I created an AI to play chess.
Okay, so we’re gonna want to move these pieces around. So first, let’s start by being able to move any piece to any space.
Next is the queen. She can move horizontally and vertically. Okay, that’s enough. I don’t know why I’m telling you all this. I’m 98% sure you guys know how to play chess. So I’ll just speed through the next few. Bishops and rocks were easy because the logic was done for the queen.
Knights move weirdly that can just jump ship which is great because at the moment all the pieces can do that. Pawns are actually the hardest because they can do whatever they bloody want like move to one the first time and attacked diagonally and stuff and yeah, that’s that’s all of them.
Now we need to alternate between white and black turns and we are done. Hell yeah.
Okay, so added some sprites for the pieces so they’re not just letters and I’m really happy with how it turned out. So you can see the game is now done and if you want to move on sorry that was as long as I could last with a straight face … it was so stupid. All right, so scale David just down a bit so the game is actually usable. Okay, now we got the game happening now we just need some friends to come over and play with pft.
Who needs friends when you can make your own? I’m so alone.
Okay, let’s talk AI. Evan, you should use neural networks. Yeah, it’s a good idea if you want to waste your life waiting for it to train. Now screw that. Today, we’re gonna be using an algorithm called mini max. Alright, to help explain mini max, we’re gonna play a little game. It’s a shit game, but just me it’s important. So we have this tree. There are two players play a is trying to reach the highest number possible and play a bass trying to reach the lowest number possible. Each player takes turns to pick a direction to go down the tree. For example, player A chooses left and player B chooses right, then player A goes left and player B goes right, which gets to a score of six. So the question is assuming that player B is perfectly logical and plays the best moves possible, then which move should you make first as player Pause the video if you want to figure it out for yourself. So the trick is to work backwards, start from the bottom and figure out if player B was at each intersection on the bottom layer, which direction would they choose to remember B is trying to minimize the score. So for the bottom left, they would choose the right direction as it is the lower of the two. This means that the red player should consider the value of that intersection to be two as assuming the Player B plays logically, there is no way of reaching that nine we do this for the rest of the intersections in that layout. Then we look one layer up and think if player a was at at each of these intersections, which action would they take. And looking at the leftmost one again, we now know that going left will result in a two and going right will result in a minus one. So we choose two, go up another layer and then it’s B’s turn and finally you are left with the choice of going left to reach a two or going right to reach a one. If you can’t figure out which direction to go now then there’s no helping you. And that’s great. No but what does this have to do with just I’m glad you asked otherwise the segway would be difficult. At a time, chess is just a big game of mini max.
The complete transcript will be published soon.