A compelling testament to the power of autodidacticism, turning a classic computational challenge into a narrative of raw persistence and logic. It proves that the most profound way to demystify complex AI is through the obsessive, hands-on process of building it from scratch.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
I Locked Myself in a Room Until My Chess Engine Beat MeAdded:
Have you ever wondered how much you could get done if you truly had nothing else to do but work? Maybe you've wondered how much time and mental effort it would actually take to get that personal project done. Well, I'm about to find out. That's right. I've decided that I'm not leaving my room for as long as it takes. Days, weeks, until I code an entire chess engine from scratch that is strong enough to beat me in a game of chess. And just to make sure that I suffer, I want to see if I can implement the entire thing without AI.
Check this room out. It is completely empty. It's really tiny and there's nothing in it. But today is March 5th.
It is 6:29 p.m. and I'm ready to get started. So, let's get to it.
To get a chess engine working, I need to design four systems of escalating complexity from the ground up. Some of these systems, like the search function, were way harder to implement than I ever expected. Before we can make an AI, we need to make chess the game. To start, I needed to decide how I was going to represent the position of my chessboard.
All right, let me give you the status update. What's up? Future Luke here. I'm just a hobbyist beginner programmer. I really have no idea what I'm doing, but I've been having a ton of fun just teaching myself to code and playing around with projects like this. So, if you're a dev, I'm sorry for some of the things you're about to see. Check it out. this big old list here, this big old list of lists. This is going to be our board representation. So my board is just a bunch of lists. It's eight lists that altogether make up one bigger list.
And the numbers in these lists represent the chess pieces. Positive numbers are white pieces and negative numbers are black pieces. Believe it or not, I'm already doing things the wrong way. If you look at a chess programming wiki, it'll tell you that the most efficient way to make a chess engine is with something called bitboards. But I don't know how to use those. So, we're using lists instead. The issue here is that lists take up much more memory than bitboards. Choosing to use these is going to slow down our chess engine's ability to think ahead by quite a bit.
This decision would prove to become a giant problem later on. Anyways, my early project was shaping up to have two major systems. The board class holds all the numbers. The game class loops forever and renders the screen. So, the first several hours of my day were spent working on setting up these two systems.
Making a for loop that renders the board. Making a system that highlights the selected piece. Making a function that moves a piece from one position to another in the board representation.
I've basically got two scripts here.
I've got a board representation script.
And I've got the game itself script, which runs all the Pi game stuff. Then we have our click handling here. It doesn't actually have any rules restricting any squares yet. That's all to come. But, um, you can move any piece anywhere as long as it's an unoccupied square, which is cool. Big progress.
Here's my game. I'm going to keep at it.
>> I spent the rest of day one just coding up an absolute storm. I locked in until 1 in the morning trying to get all the basic movement rules implemented. I started with the pawn, which somehow was one of the most complicated pieces on the board. At a high level, the pawn's movement is simple. It goes forward one square. If it's still on its starting square, then it can go forward two.
That's it. But that means I need separate cases for black and white pawns because we need to index in the negative direction for a white pawn move and a positive direction for a black pawn move. Then there was the knight. The knight low-key kind of easy because its movement is so specific. It just moves in L's. So I use a list of legal knight moves to validate the selected square and check if it's legal. But the really interesting part was the long range pieces because bishops, rooks, and queens all work with the same basic idea. Pick a direction, keep stepping in that direction, and stop when something gets in the way. So instead of coding those pieces completely separately, I wrote one helper function that keeps stepping in a direction over and over again until it either runs off the board or hits a piece. This function is kind of my baby and it did a lot of heavy lifting. Shout out to this incredible blog for introducing the idea. So for the bishop, I call the recursion function passing diagonal directions as an argument. For the rook, I pass over straight directions and for the queen, it gets all the directions. It felt really good to write one function and get so much use out of it in my game.
Then there was the king. Easy. The king logic is basically just a list of eight legal squares. Done. Surely this piece won't have any special rules or edge cases later on, right? By the end of all that, I had the basic movement logic for every piece implemented. Anyways, let's check back in with our buddy Luke to see how things are going. All right, guys.
I've been grinding, but I'm about to call it a night. It's 1:17 in the morning. So, I've been coding for a long, long, long time today. But, I've made a ton of progress. I wrote almost 300 lines of code. gonna call it a wrap, but I need to show you guys the items I unlocked for completing a day of coding.
Hold on. What the heck is this guy talking about? To entice myself to continue with the project, I get to unlock an item and add it to my empty empty room for each day of coding that I complete. The longer that I stay and work on this chess engine, the more luxuries that I'll unlock that are going to help me be more productive. I've unlocked a pillow and a blanket, no bed.
I'm going to see if I can get any sleep.
I'm sure it's going to be a great night's sleep. and I will see you guys tomorrow for some more coding. Good night. So with that, I went to sleep for the first night and dreamed a little dream about recursion.
I put this under my back for like lumbar support. Slept with that light on.
Good morning. How'd you sleep?
Oh, you slept like a baby. Nice. Me, too. Me, too. All right, it is it is 12:52. Getting a late start today, but I needed to try to get any of the sleep that I could. That was a rough night.
So, let's just get right to it. As I set out for day 2, I took a look at what I had to work with. It was kind of a sad site, but at least I have a pillow to sit on now. The first thing I worked on for day two was a function called get legal moves. And it's exactly what it sounds like. Input the piece you want to check. Check the movement rules based on the piece type and get back a list of squares that it's allowed to move to.
Next, I added capturing. Since movement was already kind of working, capturing was mostly just one extra check. If the destination square is occupied by the enemy, the move is actually legal. The pawn, however, was the one exception because pawns move forward but capture diagonally. So, I had to add in some extra logic for those cases. I didn't need to do much reworking to make capturing logic work because if we just make the square that's occupied by the enemy piece legal, the enemy piece will just get overwritten when we move our piece to that square. Then, I added a turnbased system that prevents the players from moving the black pieces on a white turn and vice versa. So, that was a good couple of hours of work there. I got a couple more rules left that I still need to implement, and then we're pretty much there. The game's done and we can start working on the bot. So, I'm going to see if I can lock in and figure out all the special rules.
>> And lock in. I did. By the end of the day, the game was almost done. Chess has a few special rules that you might not know about. Castling is a special move where the king and the rook move at the same time. If neither piece has moved yet, and there are no pieces between them, the king can slide two squares towards the rook and the rook jumps over the king. Onbant is also just odd. If a pawn moves forward two squares from its starting position and lands right next to an enemy pawn, that enemy pawn can capture it as if it had only moved one square. So, I had to track when a pawn makes a two square move and then temporarily mark that square as capturable for exactly one turn. Phew.
Okay, I think I got it all in. Okie dokie. End of day two. I can't think anymore. So, I'm going to call it on this. The time is 12:40, but that means that I completed another day of coding. So, we get to unlock something. Aren't you curious what it could be? Well, the time has come. We're gonna find out. So, let's just say I'm going to get a good night's sleep tonight. We'll leave it at that.
You have no idea how excited I am to sleep on this bed. Um, we started today just with basic movement and we have done a lot of work since then. So, tomorrow if we are able to just take care of pawn promotion and king checks, then I'm going to be able to move on to getting to work on the AI itself. I'm excited to do that. But in the meantime, I'm really excited to get some rest. I'm so tired. I haven't sat on a piece of furniture in 2 days. I'm going to sleep like a baby. I will see you guys tomorrow.
I spent the first several hours of day three trying to get my king check function working. Stop the video. It turns out there was no reason for me to lock myself in my room for any of this.
I could have had this chess engine done in minutes. This is Warp and this video is sponsored by them. Warp is an agentic coding environment. Basically a terminal but equipped with all of the best AI agents on the market and built for the way that developers actually work. You run your AI agent, Claude Code, Codeex, whatever you're into inside of Warp and it basically turns you into a 10x a 100x developer. So check this out. I fired up Claude code inside of Warp, gave it a short little prompt to create a chess game and Pyame using a miniax implementation and watched it go. While it's running, I can see every diff that it makes in a code review panel and approve it myself. I can drop inline commands and have it iterate all without ever even leaving the terminal and I don't even have to sit here and watch it. Warp has a unified notifications UI that pings you whenever your agents need attention. You can just set it loose and go touch grass. Warp is not a replacement for claw code. It's a better place to run Claude code. Over a million clawed code and codec sessions have already been run in Warp. There are 700,000 developers that use it every single month. And look at that, a full chess engine in just minutes. You can download Warp for free at warp.dev. Link is in the description. All right, welcome to day three. It is 100 p.m. Let me tell you what I've been working on.
Watch. I'm going to bring the queen into a square where it attacks the king. And you can see that the king turns red, indicating that it's in check. This is great, but it doesn't actually prevent the player from making moves that continues to leave them in check. So, that's got to be the next solve.
Basically, I built this function here.
It's called king check. Um, and what it basically does is the king pulls like a reverse uno check on all of the enemy piece types. So now that I have a king check function, I have to be careful about how I move forward. There are all sorts of weird cases in chess that make moves illegal. So for example, a pin is when a piece technically could move according to its movement rules, but doing so would expose your king to an attack. So even though the move looks legal, it actually is not. And this is why king checks are tricky to code. So instead of writing a special rule for all the edge case scenarios that can leave a king in check, I decided to use a simpler approach. After every move is generated when we run get legal moves, we also check at the very end if we've left the king in check. And if we have, we simply just undo the move. All right, good news, guys. The plan worked. Check this out. I bring the bishop out, leave the black king in check. Try to make a move that leaves him in check. Try to make a move over here that leaves him in check. Won't let you. We just need to add in pawn promotion and then we can move on to working on the AI. Next, I needed to find a way to implement pawn promotions. In a game of chess, if you push your pawn all the way to the end of the board, you're allowed to promote that pawn into any other piece type. And this proved to be really, really hard to figure out. But after hours of banging my head against a brick wall, I got it done. Promotions forced me to change how moves are handled completely. My whole system up to this point used to revolve around each square representing one possible move for a piece. So now when we generate legal moves, we have this one weird unique edge case where there can actually be multiple legal moves for one square. So I had to rework how we generate legal moves, rework how I hand off piece moves from the game to the board, and create a graphical representation menu for upgrading the pieces. That was so much more work than I thought it would be. All righty, we're almost there with the game. That was a complete pain in my ass, but pawn promotions are in. And I had to add some systems and I had to rework a lot of stuff to get it there, but it is there.
many many many hours to get done, but it is done now. Great news, the game is all done. Oh Okay, so checkmates.
Every turn, the engine generates all legal moves for the active team by scanning the board and running each piece through the get legal moves function. The important detail here is that this function already removes any moves that would leave the king in check. So every single move that it returns is actually playable. So after a move is made, the engine checks if the player has any legal moves left. If the list of legal moves is empty, then the game is over. All right, team. We got it done. This was another brutal one. This took hours and hours. It's dark outside now. So, it is 6:32. Still got some hours left in the day. So, I guess without further ado, we will dive into figuring out making a CPU. I'm very tired and I want to stop. I would really like to just put on a show or some YouTube and and chill out for a bit, but that's not what we're here to do. So, we're going to keep on. By the time I finished adding all this bloat into my get legal moves function, this is how long it was. Oh my god. So, I spent the rest of day three working on making an evaluate function that would become a critical part of making the chessbot.
But for finishing day three, I was bestowed with another gift to furnish my room with. Yeah. So, I can already tell this thing is going to boost my productivity by at least 200%. So, tomorrow we're going to get it done. We got to implement a minmax algorithm and we got to finish our evaluation function. So, exciting things to come.
Good morning, Kings. Welcome to day four. I'm going to be honest with you. I have not been sleeping well the past couple nights. I don't know what it is, but I think when you code 14 hours a day, it makes it really hard to unwind and get some actual rest. I just had a shower and I'm feeling a little rejuvenated. I'm clean at the very least. So, um, we got the game working, so I'm just going to pick up where I left off and see what we can get done.
All right, it's day four. I'm tired, but we're finally doing the thing that I came here to do, build the AI. I had a plan going into this. To start, what we need is an evaluation function. If you play chess online, you've probably seen this evaluation bar on the left side of the screen. I basically need to make something like that, but way, way, way dumbed down. We need to write a function that receives the state of the board as an input, determines which team is winning, and outputs an evaluation score. I watched this video by Bartek Spitza. So, sorry if I'm butchering your name. Anyways, the video was an incredible resource for understanding conceptually how to implement this kind of function. Check it out after this video, of course. Anyways, we can start measuring which team is doing better by simply assigning values to the different piece types and adding up all the pieces that are on the board. But here's the thing, not all pieces are placed equally. So, we need to add in some logic that considers what part of the board is best suited for the different piece types. All right, I've got the evaluation function working. So with all this in place, you can take a look. I run my game. And what I'm doing right now is I'm just printing the evaluation from the evaluation function to the terminal every single move. So we move the pawn to the center. Right now, white is controlling a center square. It's got a pawn out. It's bishop is controlling way more squares than the black bishop.
So naturally, the white team has a slightly higher evaluation. Right now, we're at 0.9. But say I bring my queen out here with the white team. Now I'm controlling much more squares. So, we're temporarily up to a higher evaluation for white, but black captures. Um, and then all of a sudden, things swing way over towards the black team. Also, chair is fantastic. I love sitting down. Happy with the progress, got to say. But, man, today I'm feeling so fried. I'm just I am so drained. I've been coding nonstop for so long. And I feel like we're making fast progress. I feel like this is the fastest I've ever gotten a big project done like this. But, oh my god, it's not fun. All right. So, now that I have an evaluate function, we need to hook it up to a search script. At first, all the search script did was run the evaluation function once and find the move that leads to the highest evaluation. This doesn't actually consider what the opposing team might do in response, so it's really not any good yet, but I couldn't help myself but just jump right into a game. The first iteration of the bot is complete. I'm going to play my first game of chess against my own creation and see if it can beat me. All right, we're going to jump into this game here. Here I'm going to play my typical opening E4. Black responds with E6, which is an interesting move. Yeah, I'm really kind of like a uh Italian system opening. Oh, looks like the black team just hung their queen. Yeah. So, as expected, I won the first game pretty easily. But it felt so great to even have a system that's capable of choosing a move. Even on the most basic level, I was really proud of what I'd come up with. So, I spent the rest of day four trying to tighten up my existing system and debug a couple of problems that I've found as I was developing.
>> It's late. I'm going to call it a night.
See you tomorrow.
>> It's going to be hard to put into words just how back we are, but let me just say this. We are so back. All right, day five. I think I feel like we're getting close. I'm hoping this is going to be the last day. We shall see, though. But before we jump into any coding, some of you may have noticed I haven't unlocked anything for completing day four. Well, that's because I wanted to go to bed.
But it's time to put it together. So, let's see what we got.
All right, folks. Here it is. Voila.
Everything I could ever need to get this project finished. My productivity is going to be through the roof now that I have all these fancy things. Got two monitors. I've got a keyboard, a mouse, a desk to sit at, a desk I can even wait for it, a desk I can even stand at. So, the goal now is to lock in and see this through to the finish. Um, if I can get this done today, I'm going to be stoked. I think I'm close. Let's see what I can do. All right. Now that I've got this sick productivity setup, surely my code quality will improve, right? Let's talk about miniax. Miniax is basically how we're going to get the engine to think several moves ahead. It starts by looking at every legal move it can make from the current position and then for each of those moves, it imagines the opponent responding with their best move based on my evaluation function. Then it repeats. It looks at all of its options again and then all the opponent's responses. And it keeps doing that over and over again until it reaches a set depth which we pass in as an argument.
Once it gets to the end of that line, it uses the evaluate function to score the final position. So if I set the depth to five, the engine is basically playing out thousands and thousands of fake future chess positions. The problem is that this gets out of hand insanely fast because the chess engine needs to scan potentially millions of positions to find the best move and my code is really not very efficient. Remember, I'm an amateur. But for real, this this has been a pain in my ass. Um, it's been very confusing to implement for me at least. But, uh, we got it done. We got it done. So, let's go and run our game here. We're going to officially have our second face off with my chess engine.
Let's see how it does. Let me play my typical opening. E4. Okay, so game two was kind of a bust. The search function is just way too slow right now to realistically be played at depth six.
>> It just made a move that took 20 minutes. It took 20 minutes to decide to play D5. So that's not going to cut it.
So I had to go back through and make a lot of changes to my miniax implementation. I was in so deep with this function and I spent hours trying to make it run faster and I could just not figure out how to optimize it. I was spending so much time with the chess programming wiki, but I was strung out at this point and running on fumes. So, as shameful as it is, I had to take a few hints from AI from this point forward.
All right, so I now know exactly what I need to move forward. It's called alpha beta pruning. So, remember our miniax algorithm, alpha beta pruning is basically just a way to keep it from wasting time. If it's already found a line that's really strong and it starts looking at another line that clearly isn't going to beat it, then there's no reason to keep scanning the positions further down the decision tree. So, it doesn't it just cuts off that whole branch and moves on. And that means that the chess engine can search deeper without having to fully analyze every possible continuation. So, let's run this at depth 5 instead and see how things go. That's right. No more messing around, folks. It's go time. We've come a long way. game logic, rendering, evaluation functions, reworking the search script over and over and over again. It's all leading up to this moment. Can I earn my freedom by losing a game of chess?
Let's see if we can get a fried liver going. Okay, so they do block the attack, which is what you want to see here. Okay, so it's attacking my bishop.
I'll just back the bishop up. I think that was probably 10 minutes between moves. It's forcing my knight away from the center, which is smart. That's a good sign. Okay, so we actually just won a pawn on me. I kind of didn't realize that I left that Hank. That's uh embarrassing, but it's also valid. Wow, it brought the rook up to attack my queen, which is just interesting. I don't know what the plan is with this, but just get my queen out of the way.
This is kind of crazy. I'm in hot water here. Um, the bot jibbaited me by giving me a free knight, but it turns out it had a revealed check and it's won my queen and it could have captured my queen this turn, but instead it brought the bishop out, pinned my queen, takes the pawn, and check. That's just mate.
Oh, wait. That's just mate. One.
No.
Oh my god. It got me. It got me. I did it. Oh, it only took 6 days. Took nearly 3 hours to get through this game because the bot was so slow. It's done. Count it. I'm going outside.
Related Videos
VALORANT's Latest 'Exclusive' Tier Bundle is Rough...
KangaValorant
17K viewsβ’2026-05-28
Flight Attendant Mocks Poor Looking Black Woman β Mid Air Announcement Exposes Her Real Power
SkyboundStories-b4r
184 viewsβ’2026-05-28
I FIXED My Friendβs Blown Turbo RX-8β¦ Then Sold It
Cameron-RX8
134 viewsβ’2026-05-28
NewsWatch 12 at 5: Top Stories
NewsWatch12
1K viewsβ’2026-05-28
Simon Jordan & Danny Murphy deliver PREDICTIONS for Arsenal's Champions League FINAL with PSG
talkSPORTArsenal
6K viewsβ’2026-05-28
Botting is OUT OF CONTROL in Classic WoW (Again)...
SolheimGaming
108 viewsβ’2026-05-28
The "AI Job Apocalypse" is CANCELLED!
WesRoth
9K viewsβ’2026-05-28
STREET FIGHTER 6 - INGRID Story Walkthrough @ 4K 60αΆ α΅Λ’ β
RajmanGamingHD
12K viewsβ’2026-05-28











