The Fascinating Programming of a Chess Engine

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024

Комментарии • 481

  • @theluvjain
    @theluvjain 11 месяцев назад +434

    As a developer and a lifelong chess lover, this video made me happy! Your pacing was simple, easy to understand and though the ideas were complex, you demonstrated and explained them in a neat and organized fashion. Cheers my friend - looking forward to the next one!

  • @dantheok1
    @dantheok1 11 месяцев назад +1016

    the fact that this channel has 17 subscribers is bewildering, perplexing, and puzzling for me

    • @nameyname1447
      @nameyname1447 11 месяцев назад +57

      the fact that this channel has 125 subscribers is bewildering, perplexing, and puzzling for me

    • @galactoman5503
      @galactoman5503 11 месяцев назад +39

      the fact that this channel has 212 subscribers is bewildering, perplexing, and puzzling for me

    • @animationgaming8539
      @animationgaming8539 11 месяцев назад +27

      the fact that this channel has 217 subscribers is bewildering, perplexing, and puzzling for me.

    • @khytron06
      @khytron06 11 месяцев назад +20

      the fact that this channel has 287 subscribers is bewildering, perplexing, and puzzling for me

    • @AverageBishop-
      @AverageBishop- 11 месяцев назад +19

      the fact that this channel has 313 subscribers is bewildering, perplexing, and puzzling for me

  • @Pi7on
    @Pi7on 11 месяцев назад +83

    Damn, I felt like the video had just started, and then boom, it's already over.
    If you keep up the style/quality, you definitely have a future among the greats of video essays on programming/CS

    • @andrewsarroyo
      @andrewsarroyo 10 месяцев назад +1

      Yes, this whole video was mesmerizing. I was expecting at least twenty minutes. So good.

    • @Pi7on
      @Pi7on 3 месяца назад

      @@ahmoin freya Holmer, Tsoding, Sebastian Lague, mattkc, no boilerplate, 3blue1brown, fasterthanlime
      And these are just the ones that came to mind first, there are many others

  • @espian6506
    @espian6506 11 месяцев назад +172

    I love how walked through implementing the minimax algorithm - the whole explanation felt very natural in the way you explained it, and the animation adding the bits of code was lovely because that's exactly how implementation unfolds. Great work!

    • @Ermude10
      @Ermude10 10 месяцев назад

      Fully agree! The code editing animations is great!

  • @HansLemurson
    @HansLemurson 11 месяцев назад +12

    I give this video a high evaluation score for the youtube algorithm.

  • @murphleeman3347
    @murphleeman3347 11 месяцев назад +5

    Thank you for wishing me a happy day :) I also wish you and whoever reads this comment a happy day!

  • @davidb6477
    @davidb6477 11 месяцев назад +41

    I was confused by the King placement evaluation since those values would quickly have the opposite gradation as pieces are traded off. This type of value assumption based on board placement would have to be dynamically evaluated and not taken as a static truth.

    • @crahs8
      @crahs8 10 месяцев назад +14

      This is usually solved by having two king placement tables: one for opening/middle game and one for the endgame. One then computes something like a number for "endgame-ness" (might be based on the number of pieces left) that smoothly interpolates between the two tables.

  • @Lycro.
    @Lycro. 11 месяцев назад +30

    This was a very well made video! I couldn't believe in the amount of subscribers you had because your production is top notch!

    • @artillerybeacon5324
      @artillerybeacon5324 10 месяцев назад +3

      A lot of obscure channels with high quality videos have been appearing in my feed, and I'm all for it.

  • @diophantine1598
    @diophantine1598 11 месяцев назад +21

    I always enjoy hearing of new ways to apply bitwise operators.

  • @keephustling7527
    @keephustling7527 3 месяца назад +2

    I am seeing this after learning Hello world in Python

  • @gregorymorse8423
    @gregorymorse8423 11 месяцев назад +1

    The heuristic for evaluation is still primitive which is why neural networks have significantly improved modern engines. Also bishop pair, passed pawns, controling open files, etc should go into a strong heuristic. What is described here is primitive compared to state of the art. Also a position isn't merely 64 bits as having castling ability, move repetitions, 50 move rule, en pessante are also part of the game state. These nuances arent as important but they are amplified when engines play each other. Unless a mathematically perfect evaluation function is found such that chess is solved, maching learning is of course the most powerful modern statistical tool which is why it has become nearly universal in production engines. In general the strength of the eval function might be more important than efficient raw calculation as time is better spent. The interaction of pieces is more important than simple criterion. Its likely worth looking into how stockfish does the eval in non NNUE builds because it has one of the most nuanced heuristics imaginable.

  • @_.-.-_.-.--.-_.-
    @_.-.-_.-.--.-_.- 11 месяцев назад +1

    May I ask what video editor are you using to make those animations?
    Love it, kudos to your whole effort. Peace.

  • @OmarMoBadr2
    @OmarMoBadr2 11 месяцев назад +4

    Great video thank you, I thought you would show a demo at the end of the video, but anyway keep up the excellent work.

  • @NACHO55G
    @NACHO55G 7 месяцев назад +1

    Can you explain how does the neural network work? I have heard that Stockfish 16 uses one

  • @CalmaxFilm
    @CalmaxFilm 10 месяцев назад +11

    This video is ridiculously brillant... This is so clean, well explained, and the purpose is so exciting

  • @Agogogogogogkglgkfndjesk
    @Agogogogogogkglgkfndjesk 11 месяцев назад +2

    Great video. Can you please tell me what program/software do you use for creating these visuals/animations?

    • @BartekSpitza
      @BartekSpitza  11 месяцев назад +2

      Its almost all Motion Canvas along with some Davinci Resolve/After Effects :)

  • @gabrieltellesm
    @gabrieltellesm 11 месяцев назад +5

    Very nice video, and it shows that a lot of effort went into it. Congrats!

  • @jacokyle0160
    @jacokyle0160 11 месяцев назад +4

    man if this video was 10 hours long I would certainly watch it all 😂

  • @fuzzy-02
    @fuzzy-02 11 месяцев назад +5

    This is just amazing.
    I was fascinated most by how the board conveniently fit into an int64 and how from there everything just rolled as mathematics. Matrix multiplication in particular.

    • @Rexvideowow
      @Rexvideowow 10 месяцев назад +1

      Friendly reminder that certain kinds of matrix multiplications have become faster with AI recently finding a new method, a mathematician taking that to the next level, and then AI improving it once more.

  • @dot1298
    @dot1298 5 месяцев назад +1

    Could you do a similar video for Dou Shou Qi (Jungle) ?

  • @Nicolas-sq4fj
    @Nicolas-sq4fj 11 месяцев назад +2

    After watching this video, so many "informative" programming related videos seem so over the top edited or cinematic. I don't want a dramatic intro or unnecessarily upbeat music. I want THIS

  • @presente9501
    @presente9501 11 месяцев назад +4

    Great video! It was in a style somewhat similar to Sebastian but with his personality. It would be interesting to see the game 2048 being dissected by the expectimax algorithm or monte carlo.

    • @BartekSpitza
      @BartekSpitza  11 месяцев назад +1

      Indeed.. 2048 is a fun game!

  • @callofover6595
    @callofover6595 4 месяца назад +1

    can you tell me how do you do your presentation( the video you showed) I need to present my project about the same topic and I don t know how to start?

    • @kech267
      @kech267 4 месяца назад

      Made with motion canvas, check description

  • @Jejkobbb
    @Jejkobbb 11 месяцев назад +1

    Incredible visualizations, love this so much

  • @cydajock
    @cydajock 11 месяцев назад +3

    I think it would be interesting to go over how to make the min max processing multi-threaded and in a compiled language. Fundamentally this was a beautiful video, and python was an excellent choice to show the algorithm at a high level, but a practical engine would need to be scalable and take advantage of as many cpu cores as possible. Keep up the good work!

    • @ME0WMERE
      @ME0WMERE 11 месяцев назад +4

      Functionally, there's no difference to a compiled language - the executable would just be faster.
      Multithreading is, unsurprisngly, hard to implement - the current best chess engine (Stockfish) uses a method called lazy SMP, which starts each thread on the same start position but gives them all access to the same shared transposition table. Very slight deviations in CPU time that each thread will have (due to unpredictable kernel scheduling) will cause some threads to reach positions slightly earlier than others and write the result into the table. This means that the other threads that reach that position microseconds later will just take the value in the table instead of searching it. These slight differences in what positions each thread searches quickly add up, meaning the threads quickly start searching completely different parts of the whole possible minimax tree.

    • @cydajock
      @cydajock 11 месяцев назад +2

      Oh wow that’s actually really cool! Having a shared memory cache is actually quite nifty here. Thanks for sharing 🔥🔥🔥

  • @KakoriGames
    @KakoriGames 11 месяцев назад +1

    I once implemented a minmax algorithm for Tic Tac Toe in Python, its quite simple to implement, the hardest part of a program like this is making it efficient and implementing a good eval function, neither of which my Tic Tac Toe AI needed since it could simply exhaust all possible moves. The thing I've been more curious about is not necessarily the conceptual part of the engine, but rather how you would go about making a engine that could, potentially, work with programs like Chessbase and participate in competitions like TCEC. If you make your own Chess program, doing a working engine is relatively simple, but making a engine that can work with programs and APIs made by other people I don't really know much about.

    • @redbedhed
      @redbedhed 9 месяцев назад

      If interested, I can link you to a couple of Chess programming Discord servers with seasoned authors willing to help.
      Creating a good Chess engine can be hard--- much harder than writing minimax for tic-tac-toe. Even plain Minimax (with no optimization) can solve tic-tac-toe in seconds, building a table that maps positions to best moves. A tic-tac-toe AI doesn't even need to search the game tree more than once.
      However, the game tree complexity of Chess is so high that we will all be dead long before the game is solved. A Chess AI must search the game tree during the midgame, and optimization there is critical.

  • @darnit006
    @darnit006 11 месяцев назад +21

    Wow. Im a software developer and hearing you explain something so complex in such a simple way is a freaking gift. Hats off to you sir.

  • @notinoti2552
    @notinoti2552 11 месяцев назад +1

    The primary issue with the minimax algorithm is its inefficiency in terms of time, especially when applied to a game like chess. Given that even at a depth of 3, chess presents millions of potential move combinations, the algorithm becomes impractically slow. Additionally, it's my belief that pruning does not significantly mitigate this problem.

  • @Pabocheoreom
    @Pabocheoreom 11 месяцев назад +2

    Informative video, really enjoyed it! Keep it up

  • @Nico-qq7xl
    @Nico-qq7xl 11 месяцев назад +1

    Great video. Keep doing java ones too 😂❤

  • @hud6064
    @hud6064 11 месяцев назад +2

    what do you use to create graphics?

    • @BartekSpitza
      @BartekSpitza  11 месяцев назад +4

      I use Motion Canvas and a bit of Davinci Resolve :)

    • @ColinTimmins
      @ColinTimmins 11 месяцев назад

      @@BartekSpitzaVery nice work. Loved the video. =]

  • @bernardoalves3642
    @bernardoalves3642 11 месяцев назад +7

    There are a bunch of small computer science channels out there with really well-made videos that are ready to blow up, and I'm all for it.
    Best of luck, if that's your goal. Lovely video

  • @gandalfjackson1546
    @gandalfjackson1546 11 месяцев назад +9

    As a CS graduate, I love seeing the concepts we learned applied to real world things like chess.
    Fascinating stuff

  • @perfectionbox
    @perfectionbox 4 месяца назад +1

    What a wonderful coincidence that chess has 64 squares and a large integer has 64 bits 🥰

    • @BartekSpitza
      @BartekSpitza  4 месяца назад +1

      It really is 😅

    • @perfectionbox
      @perfectionbox 4 месяца назад

      @@BartekSpitza ruclips.net/video/R-3qm5W__ug/видео.htmlsi=UdCrYFEMNnJ0bAQ6&t=8

  • @TheWanderingNeko
    @TheWanderingNeko 11 месяцев назад +3

    how do you only have 166 subscribers!? you have made the concept easily understandable and presented it better than channels with 100x-1000x your subs. amazing!!!!

  • @dhruvmishra1933
    @dhruvmishra1933 10 месяцев назад +1

    when i saw the length of the video, i thought to myself "alright what can he really teach me about chess programming in 6 mins lol lemme see" and these 6 mins felt like 1 min and 60 mins at the same time. So much info stuffed so precisely and explaining it in such calm and simplistic manner, kuddos man!🙌

  • @el_crego
    @el_crego 10 месяцев назад +1

    Really nicely produced video 👍 recently created chess in c++ and have been interested in engines, I realised how inefficient an array would be and had no idea about this method, I’d been using fen notation. Also, Well deserved channel growth 🎉 👏

  • @XoIoRouge
    @XoIoRouge 11 месяцев назад

    Video was great. Background piano was cringe. Why the fake video essay and fake "dramatic" feel? No need to be "beautiful" with your video. It's annoying.

  • @simplepycodes
    @simplepycodes 4 месяца назад

    Good job. Have you implement perft, transposition table as well?

  • @A71098
    @A71098 11 месяцев назад +3

    underrated channel

  • @computeurhuman6940
    @computeurhuman6940 11 месяцев назад

    Your chess engine have really big chess problem, but, it’s good vidéo, you get subscriber ❤️

  • @raylopez99
    @raylopez99 10 месяцев назад

    Nice video although min/max won't help you if a sacrifice yields material advantage (or checkmate) at a depth greater than the depth you search the chess tree. In other words, a chess tree branch might be pruned as yielding nothing useful when in fact, going a bit deeper, the tree branch pruned might have been a deep sacrifice for material gain or checkmate. But admittedly such "GM Mikhail Tal" moves are rare, so a low-depth alpha-beta min/max algorithm indeed makes for a relatively strong chess engine, all things being equal.

  • @MattMcT
    @MattMcT 3 месяца назад

    Wow! Ok Bartek, just want to say thank you. Not just for the video but for the raw inspiration. I’ve got a learning engine to build, which like your chess engine, needs to be able to strategize on how to best position a learner for further strategic positions. So the challenge is to design the engine to provide the learner with a weighted numerical map of where they might want to head to learn more things. This way a learner can try to grasp the rabbit holes they can possibly traverse, prior to traversing them and strategize as they see fit for themselves. I have to do this in a more 3d type of board, but the principle is the same. So THANK YOU for the nudge I needed to just start building this as an engine. I owe you a beer/coffee/highFive!

  • @jambalaya974
    @jambalaya974 7 месяцев назад

    it feels like a very dry subject.. either you spend years fine tuning a pipeline you've built through experimentation or you implement some known algorithms and/or neural networks and call it a day, all just for watching a computer play chess at slightly more incomprehensible levels than before
    unless you do it competitively/professionally, I don't see the thrill and as for the programming techniques, at least most of what was discussed in the first part should be obvious if you have programmed for some time

  • @noggintube
    @noggintube 10 месяцев назад +1

    I had a ZX81 in the mid-80s and had a chess game on it that was only 1k in memory. It always amazed me how they managed to programme a chess game into such a tiny amount of memory. Modern programmers could probably learn a lot from those tiny memory constraints.

  • @sparshsharma5270
    @sparshsharma5270 10 месяцев назад

    While programming a computer/engine to evaluate chess, some things needs to be taken into consideration. One crucial factor is mobility of pieces. Stronger the piece is placed (depends on how many squares it controls), better is the position for that side. Also, though brute force algorithm would be required for evaluating the position, but to make the engine take lesser time, candidate moves can be programed via recursion. Surely not easy, but as a programmer, that can well be done.

  • @kosterix123
    @kosterix123 10 месяцев назад

    These are very basic techniques known in the eighties. You add no value.

  • @timsagichnicht
    @timsagichnicht 7 месяцев назад +6

    THIS VIDEO WAS LIKE THIS „!!“ BRILLIANT. As a chess lover and young programmer I found it amazing how you explained and visualized everything. Also the sound effects your voice and your explanation itself. I would love to see a continuation or a deeper analysis

  • @JonnyInChina
    @JonnyInChina 9 месяцев назад

    Hey, how did you create the animations for this video? Its so smooth!

  • @blucky_yt
    @blucky_yt 10 месяцев назад

    Since you're already using a float and a win is the best possible position, wouldnt it make much more sense to use Inf as the evaluation for a win position? (And -Inf for loss ofc)

  • @rybiryj
    @rybiryj 10 месяцев назад

    How strong would such a simple engine (that takes into account only the position-adjusted material value of the pieces) be in practice?

  • @nilsfriman1555
    @nilsfriman1555 11 месяцев назад +2

    The video was very nice. Calming, informative, and inspiring. I love Sebastians videos too and i definitiely saw some of what i see in his videos in this one.

  • @applemirer3937
    @applemirer3937 10 месяцев назад

    Wow, I hadn't heard this song before. I love your taste in music.

  • @sushi5796
    @sushi5796 2 месяца назад

    I barely know anything about programming but this is a really cool video!

  • @mk17173n
    @mk17173n 3 месяца назад

    I really love your animation with motion canvas. I am working on learning motion canvas in order to make code challenge tutorials. Do you have a github repo that shows the code you used to create the animation? It would help me learn how you created the animation. Thanks.

  • @martinzokov
    @martinzokov 10 месяцев назад +3

    Dude! Really nice vid. You explain the concept in simple terms without all the unnecessary details. Looking forward to more of that!

  • @NorthCalm
    @NorthCalm 5 месяцев назад

    The fact that this channel has 11.1k subscribera only is indeed surprising.

  • @MrOnosa
    @MrOnosa 10 месяцев назад

    I had a hard time following why that pruning optimization was possible. I rewatched it and got it.

  • @blackty6922
    @blackty6922 10 месяцев назад

    I would love to see some simple game's program inside. this one is to complicated for me right now. after 3min my brain lefts xd

  • @JIMPENREVIEWS
    @JIMPENREVIEWS 8 месяцев назад

    I liked the video, but if each position is a "bit" how do you program how pieces can move?

  • @MetsuryuVids
    @MetsuryuVids 10 месяцев назад

    Isn't it a bad idea to prune immediately, because if you have a position that sacrifices a piece to gain a better piece, or a win, that path would be pruned because of the sacrifice, if you don't search it deep enough?

  • @renzpajarito4655
    @renzpajarito4655 11 месяцев назад +1

    now I understand how chess evaluation works.

  • @nimeshpoudel8277
    @nimeshpoudel8277 11 месяцев назад +1

    2:13 capturing pieces is good but in that specific position it as M2

  • @supertigik
    @supertigik 10 месяцев назад

    The video ended so abruptly 😩 i for some reason expected to hear about more advanced chess algorithms, at least in general terms

  • @ginters5389
    @ginters5389 11 месяцев назад

    Great video, but what you needed is playing against your engine at the end.

  •  11 месяцев назад

    Im early and I know this will get 1 million views one day so I want to claim my spot

  • @JeeliBeeli
    @JeeliBeeli 10 месяцев назад

    I got 3blue1brown vibes from the editing, very nice to look at

  • @ninek8
    @ninek8 10 месяцев назад

    The evaluation is, in my opinion inherently wrong since it only takes into account some very basic tips we teach children that are just starting out but that lose almist all relevence when you become even an intermediate player.

  • @craz2580
    @craz2580 11 месяцев назад

    I know nothing about coding, not much about chess aside from the movement but this video came to my recommendations at random. It was interesting

  • @PrithviBathla-ub8oy
    @PrithviBathla-ub8oy 5 дней назад +1

    make for ludu game

  • @eduardojose-vm9le
    @eduardojose-vm9le 11 месяцев назад

    Like comment subscribe to pump the algorithm you know how it goes 🎉

  • @MOGE_
    @MOGE_ 3 месяца назад

    this gave me some ideas of how to mKe an engine for a local boad game played in my country.

  • @thejfcad9020
    @thejfcad9020 11 месяцев назад

    Are we sure this guy didn't reupload from someone else? This is good for this less subs

  • @iau
    @iau 11 месяцев назад

    Is there any benefit to be gained from representing bitboards in even more compressed ways?
    For example, there is only one king per player, and he can only be in one of 64 squares, so you can represent him in a 6-bit number. Same for the other king, and the queen. And all other pieces. You could use a 6 × 32 pieces = 192-bit number, or just 3 int64s instead of 12 int64s, to represent the entire board.

    • @BartekSpitza
      @BartekSpitza  11 месяцев назад

      Unfortunately that would break the idea of using Bitboards. For example, in move generation, Bitboards can be used to create occupancy masks by ANDing all the bitboards together.

  • @noahcoleman6385
    @noahcoleman6385 10 месяцев назад

    How on earth do you run the code lol. Don't think the average person knows how to do this.

  • @michaelidehen5351
    @michaelidehen5351 6 месяцев назад

    does anyone know how this guy creates his videos the animation style is super cool and id like to know

  • @youcefg9760
    @youcefg9760 4 месяца назад

    Can I get the SVG of video's thumbnail?

  • @assassin_un2890
    @assassin_un2890 3 месяца назад

    Very nice explaaanation video and Also Music Thanks

  • @thornels
    @thornels 8 месяцев назад

    Reminds me of the Sebastian Lague video, great content :D

  • @mylesprospero8105
    @mylesprospero8105 10 месяцев назад

    i swear theres a youtuber with a similar animation as you, I forgot their channel name

  • @davejoseph5615
    @davejoseph5615 10 месяцев назад

    I never thought about the fact that the board could be described as a set of 64 bit words.

  • @saru4L
    @saru4L 10 месяцев назад +1

    Subscribed! This intro to chess engine development was very interesting, and I loved how you implemented the minimax algorithm into it. Maybe next time you could use genetic algorithm for the engine, using optimized material as heuristics?

  • @allinone-cy4cy
    @allinone-cy4cy 10 месяцев назад

    Can you make a video tutorial on coding and how to make a chess engine better

  • @Master_of_Chess_Shorts
    @Master_of_Chess_Shorts 11 месяцев назад

    Very nice project, impressive. I use chess engines to generate chess movies...

  • @richardshwarz2794
    @richardshwarz2794 11 месяцев назад

    Great Video! Can you estimate how strong your AI is?

  • @cj-zl2gu
    @cj-zl2gu 10 месяцев назад

    Great video!! 😲What program did you use to animate this video?

  • @Jordan-hz1wr
    @Jordan-hz1wr 10 месяцев назад

    Bravo. I'm a terrible programmer so I admire this so much!

  • @aljox5566
    @aljox5566 11 месяцев назад

    How do you make such animations . Can someone tell ?

  • @harshnj
    @harshnj 5 месяцев назад

    the fact that this channel has.... huh! wait, it was 17 just 6 months ago, and now, I see 11k subscribers! This fact is bewildering, perplexing, and puzzling and.... don't know what to say. Exponential growth like this 🤯

    • @NorthCalm
      @NorthCalm 5 месяцев назад

      वास्तव में यह हैरान करने वाला, भ्रमित करने वाला और बहुत आश्चर्यजनक है।

  • @andrewdunbar828
    @andrewdunbar828 9 месяцев назад

    I got a lot of satisfactioncy from the word "elegancy".

  • @_soundwave_
    @_soundwave_ 11 месяцев назад

    Wish you a happy day . On my way to make a chess engine.

  • @mogr488
    @mogr488 10 месяцев назад

    Amazing video, How did you make those animations ?

  • @robbasgaming7044
    @robbasgaming7044 11 месяцев назад +1

    Beautiful video

  • @raphaye.l
    @raphaye.l 10 месяцев назад

    How does he make these animations and graphics?

  • @L-Coder
    @L-Coder 11 месяцев назад

    The fact that this channel has 1.62 k subscribers is bewildering, puzzling and perplexing for me😊

  • @Shivam-sl4sp
    @Shivam-sl4sp 2 месяца назад

    Could you let us know what editing software did you used?

  • @SomeSnowman12
    @SomeSnowman12 11 месяцев назад +1

    Wonderful video. I loved how you walked through your processes in making this. Wished it was a bit longer/more in-depth, but that's just a personal preference.

  • @mikebikekite1
    @mikebikekite1 11 месяцев назад

    It's fairly demanding writing a chess engine and certainly isn't for everyone. My own little program (bikesandkites Fun Chess) plays moderately well and looks quite sweet but it took far more time than I anticipated. It doesn't use bit moves so that does impact it's strength but it destroys most people, including me, fairly easily.

  • @HeroSanjA
    @HeroSanjA 10 месяцев назад

    How you create the vizualiizations?

  • @JirkaKlimes_
    @JirkaKlimes_ 11 месяцев назад

    I Wish you happy day too mate 😊 as well as hell of a lot more subscribers, what?? I hate yt algorithm... Btw awesome video, thanks