Coding Adventure: Chess

My attempt at creating a little chess playing program!
Think you can beat it? Give it a go over here:

Watch the sequel here:

If you’d like to support the creation of more videos (and get early access to new content), I’d greatly appreciate the support here:

Project Source:

Learning Resources:

Chapters:
00:00 The Board and Pieces
03:20 Generating Moves
06:54 A Random Adversary
07:52 Optimization and Testing
12:11 Search and Evaluation
17:43 Easy Endgames
20:00 The Transposition Table
23:03 Openings
25:09 Game One
26:06 Game Two
27:01 Game Three
28:05 Game Four

Music:
Devoted Mind by Wild Colors
Intuition by Lincoln Davis
Wonderland by Shimmer
Selfless by Eleven Tales
Floating Point by Roie Shpigler
Nobility by Wicked Cinema
A Quiet Place by Jordan White
Air by Assaf Ayalon
Heart Wide Open by Sounds Like Sander
Thoughts by Anbr
Deep Blue Sea by Sivan Talmor
Flight of the Inner Bird by Sivan Talmor
Kings and Queens by Wicked Cinema

485 Comments

  1. Sorry king and queen are well placed, it's just pictures were switched. But there are 2 importants rules that are not coded : roque and en passant captures.

  2. 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 😀 all thanks to your inspiration. Thank you. 🙂

  3. You could let your program run against different levels of chess bots and see how good it is 😀

  4. 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!!❤

  5. Hi, which function are you using for kill the pawn. Please Reply Fast🙏

  6. I am surprised that after scrolling through the comments for quite some time, I have yet seen one to point out the solution for the puzzle at 2:28 xD also, seeing that genius way to represent a chess position in a machine already blew my mind

  7. tiny pile of polydimethylsiloxane pulp says:

    0:31 hey, can i ask, what softare did you use to get that board? The ui looks like VSCode, what extension did you use?

  8. I saw someone suggest pitting your Chess AI against different bots of varying levels. That's what I'm gonna do!!

  9. Bro which software you are using for displaying the chess board and it's pieces

  10. Of course now you can use a large language model of recorded chess tournaments in the FEN format to program the AI, right?

  11. How to Add different Ai Mode? (Easy, Normal and Hard)

  12. what about trying tries to optimize the searching of a move ?

  13. 8:30 couldn't you just check (not in chess terms lol) if the king would be in check or not, for example after you moved a pinned piece and if it actually would be a position where the king is in check, just make the player not able to play that move? i thought it would be a better solution instead of implementing a new "pinned piece" solution, although the downside is that it would have to check every move before confirming it and actually showing it on the screen, maybe i'm just lazy lol.

  14. It is amazing how far an approach with some search optimization goes based on heuristic and some minimal opening game library.

  15. For the little puzzle:
    1. Nf6+ and Kg8
    2. Qe8+ and Qf8
    3. Qf8 mate

  16. I tried coding a chess ai, but the move ordering wasn't as effective as it was in your implementation.
    I tried the same things, like material exchange, moving to squared attacked by pawns, and promotion, but was only able to get it down to around 150ms with 220,000 positions.

    Edit: I used the same position you had set up

  17. Hey, Can I use your chess project in my game? I just need a chess bot for it but I'm not good at programming such things:(

  18. I feel like I've commented this before but, you know you have to put "to" or "and" after "try"? You can't "try do" something; you have to "try and do" (most idiomatic) it or "try to do" it.

  19. I am a bit confused. Firstly, what language is this being written in? Some version of C maybe? Also what application is this being written on? The computer console? Xcode? Programiz? Lastly, how is it generating a graphic? I feel like the assumption that we would just know this off the bat was made.

  20. I think better way would be doing whole game in else if and checking every possible position

  21. the social network the social network says:

    This video is very helpful, but one confusion,
    what editor and language are you using?
    Thanks;

  22. Can we please get the cat more screentime in upcoming ?
    Also I can say this enough, your videos have been beyond helping for years and years, thank you so much for the effort you put into these video sebastian. it's helping us tons. thank you!

  23. 2:30 KnightF7 – king G1 – Queen E1+ – Queen F1 – Queen x F1 ++

  24. 26:13 , i think i know how to solve that problem, correct me if im wrong, we can add the depth according to the endgame weight so when the endgame is more closer we can search more deeply?

  25. 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.

  26. Aren't there special rules about castling, like you can't castle through squares that are checked or something? Is that in here?

  27. I’ve always wanted to program a chess game but haven’t thought about it in a while. You just reignited the desire.

  28. 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

  29. Im following this in Javascript, and my new favorite screensaver is "Random bot v.s. Random Bot", it makes me feel good about my chess skills

  30. @SebastionLague how are the list of openings valid?

  31. "I'm rapidly losing faith in my ability to code anything…" (Ouch)

  32. "Turns out chess programming is quite the rabbit hole."
    Yeah… no joke man.
    You issued this challenge and this is basically all I've thought about for a week. lmfao

  33. 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: https://sebastian.itch.io/chess-ai
    And source code for the project is over here: https://github.com/SebLague/Chess-AI

Leave a Reply

Your email address will not be published. Required fields are marked *