Hey everyone, hope you enjoy the video! Quick note - I noticed some slightly distracting compression issues after uploading, where squares of the chess board would sometimes blur together and flicker a bit. The only solution I could find was upscaling to 4k, so if you have the bandwidth I'd recommend watching in 1440 or 2160p. By the way if you'd like to play against the AI, you can find downloads here: sebastian.itch.io/chess-ai And source code for the project is over here: github.com/SebLague/Chess-AI
@@louisrobitaille5810 yea, basically the two main responses to 1. e4 are e5 and the Sicilian. Although the Caro Kann and French exist, at supercomputer level, they are somewhat disputed. Thus, c5 or e5 are likely to be the best responses.
11:00, i LOVE those moments in coding when you think you prevented every imaginable edge case and not by creativity but sheer rule following, the program manages to find another edge case that you are baffled by its existence...
I now firmly believe that if a piece captures your rook at a time when you otherwise could have castled, you should be able to respond by castling with the capturing piece. Assuming it's a bishop or knight, of course, anything else that would be checkmate. I have no idea what impact this rule change would have on the game but I want to find out!
It would only affect the game in very specific cases. If your oponent captures your rook, they probably broke through your defense, and it wouldn't be a good idea to castle on that side of the board.
I accidentally had a bug like this on a chess game I made-- it checked that you had not moved the rook, but didn't check if that rook was still on the board. I found out about it when the AI used it to get out of a lost position
hey, 29:06 I HAVE made it till the end, and let me tell you that The video, the jokes you throw in, the creativity you've put into this is all amazing... It really takes so much of time to firstly code such a game where they are endless possibilities + make it all alone + making the youtube video for it and grinding to all the information for the game, studying it... greaat work!!!! Hope your hardwork pays off!!❤
Yea, but I dont quite agree with the quote. What if we use the integer (which is basically a hash of the position) to find possible transposition candidates, and then check the candidates by using the FEN-String? We basically get the speed of the hash and the uniqueness of the FEN.
@@UnboxTheCat you don’t need to reverse it, you just store the FEN alongside your real data, like a dictionary you would have buckets instead of a single element in case of a collision
This video was the reason why I picked up chess 8 months ago. Thank you for making this video and giving me an awesome new hobby which I am still entirely obsessed over. :)
When God coded our solar system, he also had problems with drag'n'drop. Which even resulted in loss of a planet. Why else do you think we now have an asteroid belt between Mars and Jupiter, instead of Phaeton.
@@cinegraphics If he wanted to hide his bugs, we wouldn't enjoy the video and it would be like a perfect coding which is unnatural like an Indian tutorial or something. We humans struggle in the slightest things no matter what skills we acquired so far.
I like to play a little game called "How will Sebastian implement this coding adventure into his Solar System simulation?" So far I'm not sure about this one.
Maybe when a planet goes to generate plants it would use a grid mesh over the surface of the planet. Then each type of plant would have a sort of value and you cant have too much value in a certain sized area, and due to environmental constraints certain plants cant spawn in certain areas. Maybe the way it goes about spawning them in would follow a similar pattern of looking ahead in time with spawning to maximize the total value of plants on the planet? This is about the best I can come up with and I'm not sure it makes much sense. . .
2:44 +pick a pice and put it somewhere -Okay, i pick a piece and put a copy of it somewhere +No, you have to delete the piece -Oh, okay, delete the piece, gotcha +No, not like that
Years ago, on Scratch, the big trend was chess projects. There were a lot of really good ones, that constrained both sides to legal moves. There was one thing nobody had managed, though - an AI opponent. This was a whole thing, Scratchers talking about if it was even possible, etc. Then, a user named Midecah showed up. No previous projects, no avatar, nothing. Midecah uploads the best chess project anyone had ever seen on Scratch. It had a detailed description, pseudo-3d chess pieces... and an AI opponent. Hell, it even had a _loading bar._ It was a bit buggy, but the scope of the project made that a bit of an inevitability. Midecah hasn't uploaded anything since, nor have they responded to comments or anything. They just... showed up at the perfect time, gave us the holy grail of the current trend, and rode off into the sunset. Godspeed, Midecah, Godspeed.
For context, "Years ago" is MANY years ago. Midecah made their AI in 2009. It's also broken as of Scratch 3.0, but you can still play it in Forkphorus: forkphorus.github.io/#569176
19:00 The fact that the AI was smart enough to solve the King and Queen vs King and Pawn on a winning square for the King and Queen made me very happy. But a better test would be to give it the Bishop pawn and allow the AI to decide to stalemate or resign and see if it does either in that position.
@@user-dh8oi2mk4f A properly written one wont, but thats why you run tests in the first place: if it does resign in a position where it can force a draw then theres a bug in the code.
Can we just talk about how he’s really good in chess. For being a developer and seeing him actually beating the bot and making really nice moves, I’m impressed a lot lol
The fact that I watched this whole video while knowing not a single thing about coding just shows how much I love chess (Honestly, I didn't watch the whole video and I didn't search for this)
This channel is gold. Its not only the great explanations and step by step development that someone can replicate for learning, but also including mishaps and nice accents of humor.
2:28 The mate in 3 here is white's G5 knight to F7 check, black's king to G8, white's queen to E8 check, black's queen to F8, and then white's queen takes black's queen on F8 to deliver the checkmate
I swear, a few weeks ago I wrote a pretty basic chess program... fast forward to now, you talked about this castling with opponents pieces glitch you had... a small voice went off in my head, saying "ha, rookie mistake! wait... this glitch isn't on your game of chess, right... ". Sure enough, after testing my game of chess again, I had the exact same glitch.
I’m not a programmer, nor am I much of a chess fan, but I was amazed how you managed to make this seemingly boring topics quite interesting. Well done.
It’s nice to see your failures too, sometimes when I make stupid mistakes on what seems like an easy task I wonder “do others make these mistakes or am I just dumb”😂
Yes. For this reason I love videos that not only show projects but also the adventure behind them with all the ups and downs. It reminds me that pros are still people who still make mistakes. When I inevitably compare myself to them it's not just "they are so much better than me" but more like "be patient like them and dig into it until you succeed like them".
The best instructional video on chess programming ever!! Reasonably short, with all basic staff in place with proper level of detail to give the idea of what is this journey about... Bravo!
@@nitroflap Go would need to use a widely different stratagy for AI as it's not even remotely viable to do an brute force search as in chess. The game tree is unreasonable amounts larger. More novel ideas needs to be introduced.
@@nitroflap Until recently, it was thought to be impossible for AIs to beat human professionals at Go. But Machine Learning algorithms make it easier. This, however, isn't Machine Learning but simply bruteforcing. So it is not the same idea.
I absolutely love the iterative deepening idea! I was equally confused and angry at first, but when you brought up alpha beta pruning again, a little light bulb went off in my brain. These counterintuitive solutions and aha moments are some of my favorite things!
Great video! You should plot the ELO rating of your Chess program against each upgrade you make, e.g random moves, to basic heuristics, to the king safety and knights preferred squares etc. Might take some work but would make for a very interesting follow up video (:
Hello Sebastian Lague, I have a question: Can I use your atmosphere shader (from that solar system trilogy you made) for my game? I promise to put your name in the credits
2:28 1.Nf7+ folowed by Kg8 forced move, as the black queen is pinned to the king and no other piece can take the Knight 2.Qe8+, after goes completely ceremonial Qf8, the only move, desperately blocking the check, when crushing 3.Qxf8# comes in, defended by a Knight on d7. Quite easy, yet very satisfying puzzle
Had to come down here to make sure I got that right and I wasn't missing anything. The threat of Rh6 definitely narrows the options to forced checks, but it pays to be sure.
Hey, I downloaded this a while ago when I was binge watching your videos and just got around to playing a few games. Great work and this has amazing potential. I'm primarily a bullet player rated around 2200. I don't study openings or anything and I just play for fun. When I tried to keep up and match your program's speed, I ended up in losing positions shortly after the opening (probably 20-30 moves). I had to stop and think a few times to win which would have cost me the game if it was bullet. In my opinion, this is a great tool to help players practice openings or get into speed chess. If you're still working on this, I'd recommend adding a timer just for the players benefit since the computer moves very quick (I'm playing on a i7-7700). Also, an option to pre-move which is standard for online chess. Another feature could be to add a checkbox to give more weight to uneven trades (for example, trading a minor piece for 2 pawns if it creates a passed pawn) or a checkbox to give less weight to trades which will make it more challenging for players to plan ahead. Avoiding trades is a pretty common strategy that some players use in online games so it would be good practice.
@@gentleasp6589 nobody asked but I'm gonna go ahead and tell you that I have a crazy high elo. Without study of course. Lmao who needs studying to get a crazy high rating imagine having such low iq.
are you sure you're actually 2200... that's Candidate Master level, i don't think anyone could hit that without studying openings... unless you're some sort of chess prodigy... 2200 is reeeeaaaally high so if this is true(I doubt it) get into chess and actually learn openings and defenses...
I watched this video 3 years back, never knew I would go on to pursue computer science and would be building a chess engine project myself. Thankyou Sebastian for this wonderful video! It was sooo insightful and interactive. Keep up the good work, sir!
I've always been curious to see how someone would go about creating a Chess "AI", so I really enjoyed this video and would love to see a few more episodes, if you're still motivated to work on this project of course!
The idea of using iterative deepening to control branch order for alpha-beta pruning is something I've never considered before, but that's actually a super clever trick. Now I feel like my prof should've talked about that in class.
This is so insightful, I'm actually looking into completing my Honors degree in AI and I would love to build this as a project. Really good inspiration. Keep up the work.
I’ll need to learn how to play Go first! :D The extra bit is just so I can have ‘no colour’ as an option. Was mildly useful in some cases to be able to represent a pure piece type, with no colour associated.
i really dont understand anything form this video but I love doing stuff with you rambeling in the background, I find your voice very soothing. sometimes I come to check what you are actually saying and there are some gem moments in these videos!! keep up the good work :D))
Honestly that checkmate at 7:48 is pretty nice for a random match. Checkmate by a knight, with every other friendly piece on the board contributing to keeping the king pinned. The other knight guards f6, the rook guards d4 to f4, the queen takes care of d4 to d6, and e6 and f5 are taken care of by the bishop (and the mating knight also guards f4)
Wow, this is so cool 🔥 As a software engineer I can truly appreciate the amount of work that went into this. One day agadmator might do the coverage between your engine and others 😀
@@qwerty1233787 I don’t think that’s an issue. He could decently easily get a functional table base it would just take a while for his computer to calculate it so I don’t see an issue with just copying it.
@@mastery4667 A tablebase is by definition always flawless, and not depending on his computer's search depth - you just *look up* the position in a table, as the name says.
Iterative deepening algorithm blew me away in the same manner. Move ordering and alpha beta stepping in together to solve the “search as far as you can in any given amount of time” problem!!
A way to make the pawn structure thing better is by making it more favorable to have pawns in the center when there are more peices and try to get them to protect eachother
This is truly a wonderful video! So informative and well made, I actually come back to re-watch it every so often, just for the pure entertainment value. :) Aside from that... it has inspired me to try my hand at creating a chess engine of my own, in C++ and from scratch - I'm calling it "DLC-LUNA" and I'm pretty happy with the results so far. About a month's worth of work was put into the project, and I'm at a point where it can easily defeat a 1500-1600 ELO StockFish bot. Now, of course that's not really "good" by any means... more like, pretty much average. But it's more than I ever hoped to achieve in this short amount of time anyway. The last thing I'd need to add would be an opening book... and from there, it's basically just computing speed optimization. But as I said: I didn't even expect myself to get _anything_ done to begin with, so this is already a huge success :D all thanks to your inspiration. Thank you. :)
I've been following along with your chess videos, and slowly implementing some of the various features myself in Java (Didn't end up staying with Java though). In between watching the video and reading your code, I'm always astonished about the little details that you change along the way. The one that stood out to me the most in this video is where you changed the number for the pieces after realizing that bit-wise operators would work easier if the sliding pieces were one higher than what you initially set them to, which is a very clever change. Anyhow, thank you for the little kick of motivation to refine some of my lackluster coding skills! I hope to get a bot that can at least beat me.
This gave me flashbacks to my undergrad dissertation, writing a '3D' chess variant with time as the third dimension. Figuring out the legality of moves was really horrible code, because you could do things like moving a piece back in time to take a piece that would go on to threaten the king in the present. So figuring out if a move actually got you out of check took ages.
@@SebastianLague Also, I'd be much more interested to see your AI against those: ua-cam.com/video/DpXy041BIlA/v-deo.html At least for the lols PS. I'd suggest watching the video at x1.5 or x1.75
Wow, that's a really impressive chess program you've created! I wouldn't even know how to get started on a project like this! I'm pretty sure all I'd be able to manage is to do is to program a game involving two human players in which the computer makes sure all moves are legal. I'm not familiar with alpha-beta pruning or anything like that. Good job!
Wow, that was quite a complete and sophisticated look at how to do chess programming. I think you got all of the techniques in chess programming in there. One thing I used to consider was piece mobility as a factor in the evaluation function. The thing that chess bots can't do as yet is strategy. I think it's called the horizon effect. I was very sceptical at the start when you managed to start programming the functions in the most inefficient way but you improved all of them as the program developed.
Um... wut? Modern Chess bots are very strong tactically. Clearly, you haven't played Stockfish or Komodo. The horizon effect is mitigated through: 1) deeper search 2) selective search (such as quiescence search) Modern Chess engines search 20+ plies deep within a second and they can go ~10 plies deeper selectively.
@@georgechristoforou991 search techiques null move pruning, reverse futility pruning, prob cut, singular extensions, late move pruning, futility pruning, static exchange evaluation pruning, and a more advanced version of late move reductions Eval includes a bunch of stuff like mobility, pawn structure, king safety, and nnue later down the line
Hey everyone, hope you enjoy the video! Quick note - I noticed some slightly distracting compression issues after uploading, where squares of the chess board would sometimes blur together and flicker a bit. The only solution I could find was upscaling to 4k, so if you have the bandwidth I'd recommend watching in 1440 or 2160p.
By the way if you'd like to play against the AI, you can find downloads here: sebastian.itch.io/chess-ai
And source code for the project is over here: github.com/SebLague/Chess-AI
Thank you
damn you upscaled a video to 4k just so we could see the chess board better
Nice more C O N T E N T.
Awesome!
Are you going to make more videos on the procedural moons and planets? It was my favourite series
The sad thing about playing against your own creation is that you feel depressed whether you win or lose.
No, I would be very happy to lose.
@@thedude4039 XDD
Imagine how Gary Kasparov feels.
@Eric Lee then the ai needs to get better xD
@@brockmann4815 or u are stronk as magnus carlsen
Being able to castle with an opponents piece after it takes a rook is definitely something that should be become an official variant.
Yea, when he showed that I couldn't help but think: Neat, I want that.
That was the funniest thing I've seen in my life
I thoight so too haha
Definetely!
We can only hope that they will implement that on the next patch.
I love that castling bug. It's such a great example of computers doing exactly what you tell them to, for better or for worse.
Computers often do what you tell them to do, but not what you want them to do.
No, more like it's highlighting your own inadequacy in logical thinking
@@512TheWolf512 did you ever try programming, snowflake
@@512TheWolf512 Here's your trophy for never making a mistake.
@@zarblitz eyy why the aggression?
7:00 "Plays moves completely at random", Whips out Sicilian Defence
Computer knows something
Tbf, a LOT of "set of moves" in chess that have names, so you're bound to land on something, no matter what you do 🤷♂️.
@@louisrobitaille5810 but the Sicilian is particularly potent. It might possibly be the best response from black to e4.
@@louisrobitaille5810 yea, basically the two main responses to 1. e4 are e5 and the Sicilian. Although the Caro Kann and French exist, at supercomputer level, they are somewhat disputed. Thus, c5 or e5 are likely to be the best responses.
Some weird closed Sicilian variation
Maybe the real treasure was the bugs we made along the way.
If that's true then my code is Montecristo
I feel the bugs teach us more than most of the other aspects of programming
@@ghostriley22 programming is all about solving problems, so bugs are really important
@@sethsrc792 yes but everybody hates them
-Bugsnax, probably
"Let's pit the computer against itself."
*computer draws*
Ah, I see it's already reached grandmaster level.
World champion level*
🤣🤣🤣
Good form Pablo
lol
@@CosplayZine No one ever coded a HunterxHunter-Game or even Mod.
Tht makes me sad.
“This program plays random moves”
Program: *Sicilian defense 2.Nc6*
And it hang mate so proof that the Sicilian defense is bad
@@laytonjr6601 somebody did too
@@laytonjr6601 sicilian is the best kid
@Bacon Hair wow so toxic 3 years old
2...Nc6*
I was also surprised...
An AI that plays random moves starts with a classical Sicilian, I think this AI has a future.
The first thing to learn is to not hang mate in 1
Nope, still chess yet.
I thought that was the old Sicilian
**immediately follows it with h5**
Amazing job (1) programming, (2) explaining the programming, and (3) still finding the time to make the horse whistle in your video
11:00, i LOVE those moments in coding when you think you prevented every imaginable edge case and not by creativity but sheer rule following, the program manages to find another edge case that you are baffled by its existence...
Bot: I did exactly what you told me to, papa!
Programmer: [trying not to sound annoyed] I know you did, sport.
so true
then u smash ur head into a wall
"dangit he got me again"
love? more like hate
@@Seven-ez5ux this is what separates true programmers from posers
Lets start with a computer who plays completely randomly
Computer: *busts out with the Sicilian defence*
I now firmly believe that if a piece captures your rook at a time when you otherwise could have castled, you should be able to respond by castling with the capturing piece. Assuming it's a bishop or knight, of course, anything else that would be checkmate. I have no idea what impact this rule change would have on the game but I want to find out!
It would only affect the game in very specific cases. If your oponent captures your rook, they probably broke through your defense, and it wouldn't be a good idea to castle on that side of the board.
@@matiasgarciacasas558 do it for science
I accidentally had a bug like this on a chess game I made-- it checked that you had not moved the rook, but didn't check if that rook was still on the board. I found out about it when the AI used it to get out of a lost position
Okay, I just got to that part of the video, lol, guess I had the exact same bug
@@matiasgarciacasas558 This. If your opponent is taking your rook on its home square, you're probably losing big time.
Because of the colors in the thumbnail I thought this would be a Code Bullet's video.
Me too 😂
Wat? Pesterenan here???????
Tbf he did a chess video a while ago
Jup, same here. 😅
me too
“This bot plays moves at random”
*plays first 2 moves of the mainline Sicilian defence, the most popular defence among gms*
Then, it hangs mate in 1 so by average, it's a good bot
What that means is, Sicilian = random bullshit go!
hey, 29:06 I HAVE made it till the end, and let me tell you that The video, the jokes you throw in, the creativity you've put into this is all amazing... It really takes so much of time to firstly code such a game where they are endless possibilities + make it all alone + making the youtube video for it and grinding to all the information for the game, studying it... greaat work!!!! Hope your hardwork pays off!!❤
21:37 "If we want the speed, we have to live in fear". That quote is at least depth 6.
Yea, but I dont quite agree with the quote. What if we use the integer (which is basically a hash of the position) to find possible transposition candidates, and then check the candidates by using the FEN-String? We basically get the speed of the hash and the uniqueness of the FEN.
@@UnboxTheCat you don’t need to reverse it, you just store the FEN alongside your real data, like a dictionary you would have buckets instead of a single element in case of a collision
damn. the minute you 'tagged' is the time that pope John Paul 2 died (sorry for bad english)
@@sebaaa15 xD wanted to write same thing lol
these guys are too smort im outie
This face reveal surprised me. Who knew a cat could code?
Im not a cat
@@juliendev2191 Im here live
He's also a lawyer on the side.
Even worst, the cat gave up. I thought it was still a winning postition
It’s not a cat...you could see his face...
This video was the reason why I picked up chess 8 months ago. Thank you for making this video and giving me an awesome new hobby which I am still entirely obsessed over. :)
When he makes a bot that plays randomly, but then it plays the Sicilian Defense 😐
HA C5 IS FOR FOOLS
I thought he was trolling when it went c5 Nc6
Wait, he coded you a few monthes ago...
@@rafexrafexowski4754 ha nice.
Yeah i was a bit suspicious at first
"I'll go ahead and fix that quickly"
"I'm rapidly losing faith in my ability to code anything"
Story of any programmers life while debugging
truth, that's my mind sometimes in work
"I'll debug it quickly"
... 3 hours later... "... it works."
@@oliveryt7168 except there are 60 more bugs
Let zuckerburg read this and he’ll show you his 180billion
I am also a fellow Junior Dev programmer can confirm
I love how the iterative search being faster is so counterintuitive, but ends up making sense when you hear the explanation
*Builds a universe with simulated gravity, procedural Planetary Features and light refracting effects*
*struggles with drag and drop*
Too accurate, drag and drop is a nightmare. Especially in UI space where hierarchy order determines draw depth
When God coded our solar system, he also had problems with drag'n'drop. Which even resulted in loss of a planet. Why else do you think we now have an asteroid belt between Mars and Jupiter, instead of Phaeton.
Sounds about right
you need state machines for the latter. Only nerds know state machines.
@@cinegraphics If he wanted to hide his bugs, we wouldn't enjoy the video and it would be like a perfect coding which is unnatural like an Indian tutorial or something. We humans struggle in the slightest things no matter what skills we acquired so far.
Hey, it's coding man with the nice accent.
guy sounds like male Tibees
Yeahhh!
and the nice cat too
Not with thicc Indian accent huh?
@@daorklis5305 how is that an Indian accent
27:50 yes the explanation made sense and it's fascinating, I still can't believe so much optimization comes from the extra pruning
I like to play a little game called "How will Sebastian implement this coding adventure into his Solar System simulation?"
So far I'm not sure about this one.
Secret chess minigame on hidden planet.
He could make some sort of evil empire ruled by AI that presents chess as a riddle game the main character has to win to save the galaxy.
@@jaimefernandez3444 So... No game no life? Basically?
Maybe when a planet goes to generate plants it would use a grid mesh over the surface of the planet. Then each type of plant would have a sort of value and you cant have too much value in a certain sized area, and due to environmental constraints certain plants cant spawn in certain areas. Maybe the way it goes about spawning them in would follow a similar pattern of looking ahead in time with spawning to maximize the total value of plants on the planet?
This is about the best I can come up with and I'm not sure it makes much sense. . .
A minigame? or maybe an easter egg for viewers? Either way, I can't wait for new SSS videos (Wink Wink Sebastian)
2:44
+pick a pice and put it somewhere
-Okay, i pick a piece and put a copy of it somewhere
+No, you have to delete the piece
-Oh, okay, delete the piece, gotcha
+No, not like that
Don't you love how obedient computers are
@@OrangeC7 Computers are just smartasses that purposely do exactly what you say and not what you want them to do just to annoy you.
@@Ethan-lx1vv haha lol yeah - like the kid that you tell to 'zip it' and they proceed to redo up their flies.
I love the content presentation you came up with.
I'm abysmal at coding, but I still found this super fascinating.
Completely random adversary goes ahead and plays a Sicilian.
Lol I thought that was funny
Time stamp pls?
Exactly 😂
I was searching for that comment...!
True, I was like wtf.
Years ago, on Scratch, the big trend was chess projects. There were a lot of really good ones, that constrained both sides to legal moves. There was one thing nobody had managed, though - an AI opponent. This was a whole thing, Scratchers talking about if it was even possible, etc.
Then, a user named Midecah showed up. No previous projects, no avatar, nothing. Midecah uploads the best chess project anyone had ever seen on Scratch. It had a detailed description, pseudo-3d chess pieces... and an AI opponent. Hell, it even had a _loading bar._ It was a bit buggy, but the scope of the project made that a bit of an inevitability.
Midecah hasn't uploaded anything since, nor have they responded to comments or anything. They just... showed up at the perfect time, gave us the holy grail of the current trend, and rode off into the sunset. Godspeed, Midecah, Godspeed.
Wow, what a story! At first I was thinking that making a really good chess game is easy but then I heard of the Loading Bar...
Should probably post the scratch AI I made. It's probably like 800 elo but it's still a fun opponent
For context, "Years ago" is MANY years ago. Midecah made their AI in 2009. It's also broken as of Scratch 3.0, but you can still play it in Forkphorus: forkphorus.github.io/#569176
That's amazing. Scratch has such an impressive development community hidden under the childish surface, kinda like roblox.
@@cabbler they definitely are children though "under the surface"
19:00 The fact that the AI was smart enough to solve the King and Queen vs King and Pawn on a winning square for the King and Queen made me very happy. But a better test would be to give it the Bishop pawn and allow the AI to decide to stalemate or resign and see if it does either in that position.
It’s never going to resign. It can always just take the pawn and get a fraw
@@user-dh8oi2mk4f A properly written one wont, but thats why you run tests in the first place: if it does resign in a position where it can force a draw then theres a bug in the code.
@@efulmer8675 engines don’t resign
Not unless you specifically program a resign system in
@@user-dh8oi2mk4f I know that. Engines don't write themselves yet.
Can we just talk about how he’s really good in chess. For being a developer and seeing him actually beating the bot and making really nice moves, I’m impressed a lot lol
he's not good he made many mistakes
@@gustavopineda9681 he's pretty decent he was playing quite well
26:53 that bishop sacrifice was pretty sweet tbh. It won him the game
@@adozer17 I mean compared to other non-chess content creators I'd say he's pretty ok
@@adozer17 see you're comparing him to high stat players. For the normal population 1200 elo is quite decent
The fact that I watched this whole video while knowing not a single thing about chess just shows how much I love your videos
:)
Can’t agree more
+1
The fact that I watched this whole video while knowing not a single thing about coding just shows how much I love chess (Honestly, I didn't watch the whole video and I didn't search for this)
I don't even code and I love Coding Adventures :D
I like how you calmly explain the bugs that probably took you hours and hours to find
I am actually learning a programming language at the moment, and seeing what you can do with programming gives me so much motivation.
Keep going!
L
@@Auriacularia why say L?
@@gachastorys5129 I have no idea why I said that
@@gachastorys5129 sooo ask my past self
This channel is gold. Its not only the great explanations and step by step development that someone can replicate for learning, but also including mishaps and nice accents of humor.
2:28 The mate in 3 here is white's G5 knight to F7 check, black's king to G8, white's queen to E8 check, black's queen to F8, and then white's queen takes black's queen on F8 to deliver the checkmate
I swear, a few weeks ago I wrote a pretty basic chess program... fast forward to now, you talked about this castling with opponents pieces glitch you had... a small voice went off in my head, saying "ha, rookie mistake! wait... this glitch isn't on your game of chess, right... ". Sure enough, after testing my game of chess again, I had the exact same glitch.
A year later. Last month I made my chess program that has the same problem lmao
3:11 Sebastian is now officaly the best chess player in world.
I’m not a programmer, nor am I much of a chess fan, but I was amazed how you managed to make this seemingly boring topics quite interesting. Well done.
It’s nice to see your failures too, sometimes when I make stupid mistakes on what seems like an easy task I wonder “do others make these mistakes or am I just dumb”😂
Yes. For this reason I love videos that not only show projects but also the adventure behind them with all the ups and downs. It reminds me that pros are still people who still make mistakes. When I inevitably compare myself to them it's not just "they are so much better than me" but more like "be patient like them and dig into it until you succeed like them".
You also don't see all the coding mistakes here, it's typing out the final good code most of the time
@@Henrix1998 My guess is that's so when somebody follows the video to recreate the project and learn from it, they don't copy the bad code.
both
We're all dumb
5:41 Cat decides to forfeit the game as the first move, interesting choice.
i heard magnus studied him closely
I really appreciate the official FIDE stream intermission/commentary music being played at 16:00. Nice touch.
The best instructional video on chess programming ever!! Reasonably short, with all basic staff in place with proper level of detail to give the idea of what is this journey about... Bravo!
Thanks!
1 Year of complete silence later:
"Coding Adventure: Go AI"
The same idea.
@@nitroflap Go would need to use a widely different stratagy for AI as it's not even remotely viable to do an brute force search as in chess. The game tree is unreasonable amounts larger. More novel ideas needs to be introduced.
@@stuffofmaking I know that, I'm a go player.
@@nitroflap Until recently, it was thought to be impossible for AIs to beat human professionals at Go.
But Machine Learning algorithms make it easier. This, however, isn't Machine Learning but simply bruteforcing.
So it is not the same idea.
@@the.invincible.9542 Well yeah, but we, in theory can create a really good Go AI, without ML.
Most amazing thing to me was how the AI suddenly became really good at simple endgames as soon as you added that endgame tweak.
The way you elongate the final syllable of some words makes you sound like an old school film villain/vampire/evil wizard
(it's awesome)
3:10 the classic Lague Opening, king takes king is a master chess maneuver
I absolutely love the iterative deepening idea! I was equally confused and angry at first, but when you brought up alpha beta pruning again, a little light bulb went off in my brain. These counterintuitive solutions and aha moments are some of my favorite things!
Finally... This made my day even before watching...
Same
i came before watching this
@@pomi1298 idk if i understand that correctly but if I do, that's disgusting
Programming language..?
@@Shadow__X ???
Great video! You should plot the ELO rating of your Chess program against each upgrade you make, e.g random moves, to basic heuristics, to the king safety and knights preferred squares etc. Might take some work but would make for a very interesting follow up video (:
I remember coding my chess engine when I was a sophomore and came across several problems that you mentioned. So fun.
I just love 11:00 it´s interesting how a small mistake in programming makes such weird moves possible.
Hello Sebastian Lague, I have a question: Can I use your atmosphere shader (from that solar system trilogy you made) for my game? I promise to put your name in the credits
For sure. Good luck with your game!
@@SebastianLague Thanks : )
@Anmol Pandey no worries, I will : )
So where's the development process at till date?
I'm very curious to play your game :)
@@pranitp.29 sorry man, gave up on it due to college
2:28
1.Nf7+ folowed by Kg8 forced move, as the black queen is pinned to the king and no other piece can take the Knight
2.Qe8+, after goes completely ceremonial Qf8, the only move, desperately blocking the check, when crushing 3.Qxf8# comes in, defended by a Knight on d7.
Quite easy, yet very satisfying puzzle
Had to come down here to make sure I got that right and I wasn't missing anything. The threat of Rh6 definitely narrows the options to forced checks, but it pays to be sure.
10 minutes in, and I'm starting to fall in love again with programming and chess. This is beautiful.
Hey, I downloaded this a while ago when I was binge watching your videos and just got around to playing a few games. Great work and this has amazing potential. I'm primarily a bullet player rated around 2200. I don't study openings or anything and I just play for fun. When I tried to keep up and match your program's speed, I ended up in losing positions shortly after the opening (probably 20-30 moves). I had to stop and think a few times to win which would have cost me the game if it was bullet. In my opinion, this is a great tool to help players practice openings or get into speed chess. If you're still working on this, I'd recommend adding a timer just for the players benefit since the computer moves very quick (I'm playing on a i7-7700). Also, an option to pre-move which is standard for online chess. Another feature could be to add a checkbox to give more weight to uneven trades (for example, trading a minor piece for 2 pawns if it creates a passed pawn) or a checkbox to give less weight to trades which will make it more challenging for players to plan ahead. Avoiding trades is a pretty common strategy that some players use in online games so it would be good practice.
"I'm primarily a bullet player rated around 2200. I don't study openings and I just play for fun."
Lmao what an arrogant lie
@@zakir2815 isn’t 2200 crazy high? Idk anything about chess
@@gentleasp6589 nobody asked but I'm gonna go ahead and tell you that I have a crazy high elo. Without study of course. Lmao who needs studying to get a crazy high rating imagine having such low iq.
are you sure you're actually 2200... that's Candidate Master level, i don't think anyone could hit that without studying openings... unless you're some sort of chess prodigy... 2200 is reeeeaaaally high so if this is true(I doubt it) get into chess and actually learn openings and defenses...
@@samimartinez1409 lmao he's probably 2200 on Lichess
I watched this video 3 years back, never knew I would go on to pursue computer science and would be building a chess engine project myself. Thankyou Sebastian for this wonderful video! It was sooo insightful and interactive. Keep up the good work, sir!
I've always been curious to see how someone would go about creating a Chess "AI", so I really enjoyed this video and would love to see a few more episodes, if you're still motivated to work on this project of course!
11:08 - I honestly laughed out loud at this part
Me too, it took me by such surprise! When you look at it, it makes so much sense, but it's just not what you expect.
I still am 😂😂😂
Meh
you have a terrible sense of humor
HmMmMmMmMmMm
The idea of using iterative deepening to control branch order for alpha-beta pruning is something I've never considered before, but that's actually a super clever trick. Now I feel like my prof should've talked about that in class.
This is so insightful, I'm actually looking into completing my Honors degree in AI and I would love to build this as a project. Really good inspiration. Keep up the work.
Chess: has pieces of two colors
Sebastian: Let's use two bits for that
Great Coding Adventure! When is your Go AI coming? :)
Thought the same, but I think he uses it for the extra state of no color
I’ll need to learn how to play Go first! :D The extra bit is just so I can have ‘no colour’ as an option. Was mildly useful in some cases to be able to represent a pure piece type, with no colour associated.
@@SebastianLague What was the need for those no color/pure pieces? I think a lot of us were puzzled by that as well.
@@zarhockk or it can have both colours, schrödingers piece
Also, it's useful if you wanna have 3-player chess. Or even 4-player.
Hell, give it a whole byte so we can have last man standing.
i really dont understand anything form this video but I love doing stuff with you rambeling in the background, I find your voice very soothing. sometimes I come to check what you are actually saying and there are some gem moments in these videos!! keep up the good work :D))
"Completely at random"
"Opens with the sicillian"
I never understand these, but they're always so interesting I can't help but watch them.
Honestly that checkmate at 7:48 is pretty nice for a random match. Checkmate by a knight, with every other friendly piece on the board contributing to keeping the king pinned. The other knight guards f6, the rook guards d4 to f4, the queen takes care of d4 to d6, and e6 and f5 are taken care of by the bishop (and the mating knight also guards f4)
Catastrophically misjudging almost every situation? Sounds like my chess.
Wow, this is so cool 🔥 As a software engineer I can truly appreciate the amount of work that went into this.
One day agadmator might do the coverage between your engine and others 😀
Very impressive and clean execution, definitely will try refactoring some code in my game based on this!
I just realized how Sebastian spaces the parentheses in his method calls... I can never un-see that now... I want to die...
What have you done! Now I see it too! 😖
Came down here to say this 😆
I don't know code - what's wrong with it?
@@blockedblock5203 It doesn't really matter. It's more like programmers ocd. Imagine of someone put a space before every period .
For endgame, if there are 7 pieces or less the optimal set of moves to win has been found, basically it has been solved.
Yeah but he doesn't want to use 3rd party data since that kinda defeats the point
@@qwerty1233787 but he does in the opening
@@skovecka that's true. But I think it's another thing to use data accrued by a 3rd party engine.
@@qwerty1233787 I don’t think that’s an issue. He could decently easily get a functional table base it would just take a while for his computer to calculate it so I don’t see an issue with just copying it.
@@mastery4667 A tablebase is by definition always flawless, and not depending on his computer's search depth - you just *look up* the position in a table, as the name says.
I wish I found your channel a year ago. It would have helped me so much in my Artificial Intelligence classes 🤣
Alternate title: How I created lichess
this channel is just toooooo underrated
One of the best endgame tutorials I’ve seen, thanks
Programming told as an adventure story - what a nice concept!
This is so cool! I would definitely recommend throwing some machine learning at it. It's easier that it sounds and has pretty insane results.
That binary encoding of pieces has just solved an issue I was stuck on for months with my masters project.
THANK YOU!
Iterative deepening algorithm blew me away in the same manner. Move ordering and alpha beta stepping in together to solve the “search as far as you can in any given amount of time” problem!!
7:49 Ah yes, a very common endgame situation.
A way to make the pawn structure thing better is by making it more favorable to have pawns in the center when there are more peices and try to get them to protect eachother
11:10 That queen's reaction is gold
"The computer thinks its doing fine until it realizes it needs to start sacking pieces to prevent a checkmate". same computer same..
This is truly a wonderful video! So informative and well made, I actually come back to re-watch it every so often, just for the pure entertainment value. :) Aside from that... it has inspired me to try my hand at creating a chess engine of my own, in C++ and from scratch - I'm calling it "DLC-LUNA" and I'm pretty happy with the results so far. About a month's worth of work was put into the project, and I'm at a point where it can easily defeat a 1500-1600 ELO StockFish bot. Now, of course that's not really "good" by any means... more like, pretty much average. But it's more than I ever hoped to achieve in this short amount of time anyway. The last thing I'd need to add would be an opening book... and from there, it's basically just computing speed optimization.
But as I said: I didn't even expect myself to get _anything_ done to begin with, so this is already a huge success :D all thanks to your inspiration. Thank you. :)
I was disappointed to see that making another Chess AI vid lost the poll. Looking forward to more of this!
Sebastian: makes computer which makes moves at random
Computer: "Sicilian defense it is"
Me: *shook*
I've been following along with your chess videos, and slowly implementing some of the various features myself in Java (Didn't end up staying with Java though). In between watching the video and reading your code, I'm always astonished about the little details that you change along the way. The one that stood out to me the most in this video is where you changed the number for the pieces after realizing that bit-wise operators would work easier if the sliding pieces were one higher than what you initially set them to, which is a very clever change.
Anyhow, thank you for the little kick of motivation to refine some of my lackluster coding skills! I hope to get a bot that can at least beat me.
when you "sneakily" took his king with yours i lost it haha
When it took the rook and got eaten backwards by the pawn i lost my shit
@Miroslav Blagoev The way the pawn calmly moves backwards to kill the king
Same
wait I need time stamps for these I missed a lot of the video ;-;
This gave me flashbacks to my undergrad dissertation, writing a '3D' chess variant with time as the third dimension. Figuring out the legality of moves was really horrible code, because you could do things like moving a piece back in time to take a piece that would go on to threaten the king in the present. So figuring out if a move actually got you out of check took ages.
Have you played "5D Chess With Multiverse Time Travel"? It's on Steam.
You never made that video about "chess quantizers" that you promised on Suckerpinch's video about 30 weird chess algorithms!
@@LeoStaley whoa that's a deep cut, I'd forgotten about that
Everything on this channel is perfect. I learned a lot from you, thanks a lot.
When this is ready, you should match this ai against the one by CodeBullet
That'd be fun! Do you happen to know if CB's version is available anywhere?
@@SebastianLague github.com/Code-Bullet/Chess-AI though there's this issue opened: "A fully-advanced pawn remains a pawn" so... I'd abstain lol
@@SebastianLague Also, I'd be much more interested to see your AI against those: ua-cam.com/video/DpXy041BIlA/v-deo.html
At least for the lols
PS. I'd suggest watching the video at x1.5 or x1.75
his chess was.. strange
@@guiorgy suckerpinch Sebastian Lague crossover? that would be amazing
Best coding channel on UA-cam, no contest. Love this dude.
I think the other designs are from the anarchy chess community, a community that develops chess mods (both for improving the game and just memeing)
I like how the first random bot decided to coincidentally play the Sicilian defense
"Negative Infinity, because what could be worse than losing a game of chess?"
I've been coding for 3 weeks and 90% of this goes over my head, but I am trying hard! Great stuff and very interesting!
Wow, that's a really impressive chess program you've created! I wouldn't even know how to get started on a project like this! I'm pretty sure all I'd be able to manage is to do is to program a game involving two human players in which the computer makes sure all moves are legal. I'm not familiar with alpha-beta pruning or anything like that. Good job!
That castling of the knight made me chuckle way harder than it should, and it's 03:11.. Why am I watching chess AI at this time.
Wow, that was quite a complete and sophisticated look at how to do chess programming. I think you got all of the techniques in chess programming in there. One thing I used to consider was piece mobility as a factor in the evaluation function. The thing that chess bots can't do as yet is strategy. I think it's called the horizon effect.
I was very sceptical at the start when you managed to start programming the functions in the most inefficient way but you improved all of them as the program developed.
Um... wut? Modern Chess bots are very strong tactically. Clearly, you haven't played Stockfish or Komodo. The horizon effect is mitigated through:
1) deeper search
2) selective search (such as quiescence search)
Modern Chess engines search 20+ plies deep within a second and they can go ~10 plies deeper selectively.
He’s not even close to getting all the techniques. He’s barely scratched the surface
@@user-dh8oi2mk4f Can you give some examples of methods he has not mentioned
@@georgechristoforou991 search techiques null move pruning, reverse futility pruning, prob cut, singular extensions, late move pruning, futility pruning, static exchange evaluation pruning, and a more advanced version of late move reductions
Eval includes a bunch of stuff like mobility, pawn structure, king safety, and nnue later down the line