Coding Adventure: Chess AI

My attempt at creating a little chess playing program!
Think you can beat it? Give it a go over here: sebastian.itch.io/chess-ai

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: www.patreon.com/SebastianLague

Project Source:
github.com/SebLague/Chess-AI

Learning Resources:
www.chessprogramming.org/Main...
web.archive.org/web/200710260...
github.com/MartinMSPedersen/C...

If you're interested in a video about some weird and interesting chess strategies, I highly recommend taking a look at this video by suckerpinch (and all other videos on that channel too!)
althe.info/number/qqO5qWRtZHN-n6Y/video


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

Komente

  • Sebastian Lague
    Sebastian Lague5 muaj më parë

    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

  • Neves

    Neves

    11 ditë më parë

    Generating moves = cat gameplay

  • Savage van wizardwitch

    Savage van wizardwitch

    18 ditë më parë

  • Savage van wizardwitch

    Savage van wizardwitch

    22 ditë më parë

  • Pranav Oak '-'

    Pranav Oak '-'

    Muaj më parë

    stalemate 50 moves draw etc illegal moves ?

  • Henry Feng

    Henry Feng

    2 muaj më parë

    interested: did you serialize depth and set the initial depth as a field for easier testing so that you don't need to fiddle around with the code and just change it in unity windows corresponding to the field?

  • Kid Chester Asuncion
    Kid Chester Asuncion3 orë më parë

    What is its elo rating?

  • Kid Chester Asuncion
    Kid Chester Asuncion3 orë më parë

    Hey Sebastian. This engine is very cool. Would you mind improving it for human-like play? I mean, it seems that you are a good programmer. Why not to develop a chess engine with a unique feature, be able to play chess like HUMANS or be able to mimic the play of humans. That would be interesting.

  • Pranav Belgaonkar
    Pranav Belgaonkar19 orë më parë

    @52:0 is that a one punch man reference ?!

  • Tiny Desk Engineer
    Tiny Desk Engineer22 orë më parë

    2:45 Chess 2: Now with Solitaire Mode

  • Tiny Desk Engineer
    Tiny Desk Engineer22 orë më parë

    1:13 couldn't it just be 4 bits with the color being just one bit instead of two?

  • saurabh kondkar
    saurabh kondkarDitë më parë

    0:52 this is a tower

  • SpiralDJ
    SpiralDJDitë më parë

    So I played a game and won with a Stafford gambit opening trap. 1. e4 e5 2. Nf3 Nf6 3. Nxe5 Nc6 4. Nxc6 dxc6 5. Nc3 Bc5 6. h3 h5 7. d3 Qd6 8. Be2 Bd7 9. O-O Ng4 10. hxg4 hxg4 11. e5 Qxe5 12. Bh6 Rxh6 13. Re1 Qh2+ 14. Kf1 Qh1#. I think the bot gets a bit confused by sacs but overall it understands certain concepts very well that other youtuber created bots don't. Great job!

  • Senpai JayJay
    Senpai JayJayDitë më parë

    me literally screaming at my screen to take the blundered queen 7:27

  • Paul Zupan
    Paul ZupanDitë më parë

    Out of curiosity, what are you using to render the chess board and pieces?

  • Michael K
    Michael KDitë më parë

    Chess is my least favorite game , and I still watched the whole video! :D good job

  • Tekkerue
    TekkerueDitë më parë

    "Because what could be worse than losing a game of chess?" 😂

  • Ferociousfeind
    Ferociousfeind2 ditë më parë

    Perhaps you could include a table of approximate times a search of some depth will take, and continue the search until the computer is about on-par with the human in terms of time remaining? That last game the computer won by time-out with two and a half minutes left in its favor.

  • Hanya manusia biasa.
    Hanya manusia biasa.4 ditë më parë

    3:01 Cursed chess match.

  • Epic Dubber
    Epic Dubber4 ditë më parë

    What ide is that

  • Roiskam
    Roiskam4 ditë më parë

    Wbrew are you programming it in?

  • i'm hungry
    i'm hungry6 ditë më parë

    epic video , btw what programming language was this ?

  • Arran Breckenridge
    Arran Breckenridge6 ditë më parë

    Apologies if this has been discussed already, but does anybody know which API/text editor Sebastian uses?

  • Toby, preferred pronouns he, him Shew
    Toby, preferred pronouns he, him Shew6 ditë më parë

    19:36 WP takes BQ

  • Bhavik Thakore
    Bhavik Thakore7 ditë më parë

    I just finished my first program in Python, yes you all guessed it right, and straight away jumped to see this, hoping to cover all in between, and, NOW, after watching this alien level programming I am like, " I Am So Stupid, I Love Goats".

  • Shisir Baral
    Shisir Baral8 ditë më parë

    I was actually surprised to see how it negotiated the queen vs pawn endgame.

  • Scott O'Nanski
    Scott O'Nanski8 ditë më parë

    I just got smoked by your AI. The upside, I now own a solid chess game.

  • Chess Goat
    Chess Goat9 ditë më parë

    Is this written in C#, C or C++?

  • Anthony B
    Anthony B10 ditë më parë

    Please could someone tell me which is the font as well as the theme he's using?

  • Klevi Alushi
    Klevi Alushi10 ditë më parë

    I struggled a little but I did beat it the other day, the strength of the program is almost equal to the Stockfish's level 6.

  • Cewla
    Cewla11 ditë më parë

    now give it to chess.com 's moderating team

  • Cai Jun wei

    Cai Jun wei

    6 ditë më parë

    moderating?

  • Pollution
    Pollution12 ditë më parë

    Yep! Very interesting.

  • davidBi94
    davidBi9412 ditë më parë

    Use enum for chess pieces. It is a cleqn way to deal with it without defining the int manually

  • Johnstable12
    Johnstable1213 ditë më parë

    There's like a bunch of things you can do to add like 1000 elo easily. First; evaluation function. Tune it using bullet games and Stochastic optimization. Two; futility pruning. Three: Late move reductions. Look at stockfish's search for more issue. Easiest thing to start with would be adding futility pruning/late move reductions. Then tune the evaluation function using PSQT tables and SPSA.

  • Oo F
    Oo F14 ditë më parë

    2:28 - f7, e8, Qf8

  • Lil Logic
    Lil Logic14 ditë më parë

    I am actually learning a programming language at the moment, and seeing what you can do with programming gives me so much motivation.

  • RR The wonder kids
    RR The wonder kids15 ditë më parë

    Could you please tell me which is this language??

  • Aurich

    Aurich

    13 ditë më parë

    English C#

  • Abhijit Majee
    Abhijit Majee15 ditë më parë

    Which software is used to create the graphics? Code seems to be written in JAVA, right?

  • Mr5nan
    Mr5nan15 ditë më parë

    can you make another video implementing AlphaZero?

  • Science Environment
    Science Environment15 ditë më parë

    From Where you render the code ?

  • Science Environment
    Science Environment15 ditë më parë

    Are you use python?

  • Lee Marshal
    Lee Marshal16 ditë më parë

    Hey Sebastian, can I ask what ELO you are at chess? You look good

  • Jozef Matus
    Jozef Matus17 ditë më parë

    This video is incredible! Thank you

  • Manikam Jajak
    Manikam Jajak17 ditë më parë

    mantap!!!

  • ASMR Gaming
    ASMR Gaming18 ditë më parë

    try your hand at upgrading pioneer space sim

  • Moha Bedr
    Moha Bedr18 ditë më parë

    What is this language

  • HydroPage
    HydroPage18 ditë më parë

    Hey, Seb, what editor font do you use? I like it

  • Ali H
    Ali H18 ditë më parë

    Gman's voice

  • pszemyslavv_
    pszemyslavv_18 ditë më parë

    5:41 Cat gives mat in 3 moves

  • Bhanu Prakash Raju
    Bhanu Prakash Raju19 ditë më parë

    How do you do all this with c like how do you make it visual?

  • well, shit
    well, shit19 ditë më parë

    23:15 na it's just been watching Magnus Carlsen play

  • Т1000 Youtube
    Т1000 Youtube20 ditë më parë

    Fun fact: this videos is 4 seconds shorter then code bullet vid. Yes.

  • Avighna
    Avighna20 ditë më parë

    2:28 1. Nf7+ Kh6 2. Qe8+ Q37 3. Qxe8# (yes all of the moves are forced for the longest hold for black

  • Jonas Strabel
    Jonas Strabel22 ditë më parë

    Wow, great video! I didnt know how much there was to implement something like this.

  • Ivan Chesnokov
    Ivan Chesnokov22 ditë më parë

    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.

  • niss cok brow
    niss cok brow22 ditë më parë

    Hi, I'm just here to say that if u made bishop=3,25 instead of 3 it would be more accurate😉

  • Time Rift
    Time Rift23 ditë më parë

    This makes my own coding skills feel severely inadequate.

  • DaDolphinPlayz
    DaDolphinPlayz23 ditë më parë

    i love the way the things appear on the screen on your videos they look so nice to look at

  • Nguyen Tuan
    Nguyen Tuan25 ditë më parë

    2:28 1. Nf7+ Kg8 2. Qe8+ Qf8 3. Qxf8#

  • I Zephyr I
    I Zephyr I26 ditë më parë

    Hey, so, im trying to program a chess bot too, but im wondering what engine are you using? im relatively new to programming, so i dont know a lot of stuff.

  • Addylen West
    Addylen West27 ditë më parë

    is this java?

  • Aurich

    Aurich

    13 ditë më parë

    It's C# under Unity (I guess)

  • Jackson M.
    Jackson M.27 ditë më parë

    As a chess player who studied computer science at university, I thank you for this video. While doing 3rd year courses, we did AI and the concepts you mentioned were really challenging yet enjoyable to me. I had a personal project back then, trying to code a chess playing program. I remember having to deal with legal moves, a chessboard world, etc. My program never got as far as yours. I created a number of search and path-finding applications just to better understand the concept, but I decided it would take too long to teach my AI about good moves vs bad. I thought I needed to be a GM myself in order to get it that far. I was not advanced enough to allow one AI to play against another, and the winner remembers what it learned. My knowledge of pruning, algorithms, searching and path finding was not enough to go further and so I abandoned the project.

  • melody
    melody29 ditë më parë

    5:56 holy hell!

  • Traywor
    Traywor29 ditë më parë

    Thank you for this concise but deep introduction to creating a chess AI. I myself coded a chess engine for once and now you made me eager to go back and improve things :D

  • Menarian
    MenarianMuaj më parë

    I have no idea what all that code says and how it functions, but it is somehow really entertaining to listen and also very interesting. Maybe one day I'll be able to understand what you are doing.

  • Aku Saikkonen
    Aku SaikkonenMuaj më parë

    7:32 Black just hangged it's queen for like 15 moves and white didn't even take it.

  • kevnar
    kevnarMuaj më parë

    With alpha-beta pruning, wouldn't that stop the AI from doing useful sacrifices of valuable pieces that might later win them the game?

  • Carter Yott
    Carter YottMuaj më parë

    3:10 got to watch out for king takes king

  • Srikara Narasimha
    Srikara NarasimhaMuaj më parë

    hi ,which language is it in and which compiler or ide are you using ?

  • William Golove
    William GoloveMuaj më parë

    The answer to the chess puzzle at 2:30 is 1. Nf7 Kg8 2. Qe8 Qf8 3. Qxf8

  • Caden Bolt
    Caden BoltMuaj më parë

    That bot's elo is roughly 1600 - not bad for something you created Good enough to beat me at least

  • Oren A
    Oren AMuaj më parë

    In the position at 19:57, please teach the computer to play Qb8# instead of Qd7#. If Eric Rosen and Ben Finegold have taught me anything it's that the queen is lazy and would like to travel as little as possible to deliver mate.

  • Dennis Spencer
    Dennis SpencerMuaj më parë

    Cat 🐱🐱🐱

  • Eren Jaeger
    Eren JaegerMuaj më parë

    I see you really changed the video and optimized the code, not?

  • Filip Šťastný
    Filip ŠťastnýMuaj më parë

    Very nice video. The funny bugs and edits (like brokend screen) are awesome :D Good job

  • Daniel W
    Daniel WMuaj më parë

    which Engine or tool do you using there?

  • Gabriele Puntin
    Gabriele PuntinMuaj më parë

    Hi, great video and very informative. I have a question, what program did you use? Thank you very much!

  • Judge
    JudgeMuaj më parë

    how can someone think of all this code and write it? I am so intimidated by that

  • Luke Hauser
    Luke HauserMuaj më parë

    Bring back the giraffe king! 0:50

  • Sinem Dilaver
    Sinem DilaverMuaj më parë

    i just started the machine-learning courses on youtube and ,I don't want to be racist but, Indian guys are EVERYWHERE!!!! so yeah my accent is slowely turning to Indian..

  • -EmeraldThunder-
    -EmeraldThunder-Muaj më parë

    What code editor do you use?

  • Bacon Hair
    Bacon HairMuaj më parë

    let me try using stockfish against it

  • Bacon Hair

    Bacon Hair

    Muaj më parë

    STOCKFISH LOST

  • Abhimanyu Vineesh 7B
    Abhimanyu Vineesh 7BMuaj më parë

    what code editor do you use?

  • Blue_367
    Blue_367Muaj më parë

    And that's how stockfish for alone people who don't wanna get beaten up by a bot was creayed

  • jueps1
    jueps1Muaj më parë

    at 0:50 there are pieces of old chess and chess variant

  • Peter Pathos
    Peter PathosMuaj më parë

    Artificial Intelligence WILL be humanity's downfall. Thank you for contributing to the most dangerous invention in history!

  • AdmHipper
    AdmHipperMuaj më parë

    *beating the computer using london, the computer got checkmated* me: damn, I can't believe I beated it

  • maximix
    maximixMuaj më parë

    The solution to the puzzle at 2:27 is Nf7+ Kg8 Qe8+ Qf8 Qxf8#

  • SgtRegg
    SgtReggMuaj më parë

    i was hoping you finish the video with "how does this AI compete against existing AI f.e. the MS Chess-AI

  • Abhishek Saraf
    Abhishek SarafMuaj më parë

    ENjoyed the content.... Hope to see you fixed the last two issues you talked about soon. I agree, following the timeline is most important thing; still, I feel we can always find some room for it. Thanks for the stuff! Keep going :)

  • Kiki Raindeer
    Kiki RaindeerMuaj më parë

    how many elo

  • Adam Ashraf
    Adam AshrafMuaj më parë

    5:55 Holy hell

  • Jake Downs
    Jake DownsMuaj më parë

    this is awesome. i was half-expecting you to write the evaluation code in a compute shader complete with visualizations of the millions of moves it was simulating :P

  • Space Viking
    Space VikingMuaj më parë

    That was absolutely fascinating.

  • Indy Lockheart
    Indy LockheartMuaj më parë

    This was recommended to me bc of the chess. I have absolutely no idea what just happened but I watched the whole 29 mins and I have to say I liked it. Idk what it was but it was cool

  • MongMong
    MongMongMuaj më parë

    Next step: AlphaZero

  • Dakor jparie
    Dakor jparieMuaj më parë

    hummm the xboard icons :) en.wikipedia.org/wiki/XBoard

  • Attila Gábor Kökényesi
    Attila Gábor KökényesiMuaj më parë

    Sooo you spent a lot of time just to lose a match... right?

  • Vadim Kozub
    Vadim KozubMuaj më parë

    like

  • Stewy329
    Stewy329Muaj më parë

    This is programming porn

  • Johnny Doe
    Johnny DoeMuaj më parë

    unfortunately, only a small selection of nerds will get to appreciate how funny you are :D

  • G Shoemake
    G ShoemakeMuaj më parë

    What program did you use to render the board?

  • oocanto
    oocantoMuaj më parë

    Congratulations. Great work.

  • Deepak Ramalingam
    Deepak RamalingamMuaj më parë

    So you made Lichess?

  • H1387
    H1387Muaj më parë

    1. e4 e5 2. Nf3 Nc6 3. Bc4 d6 4. Nc3 Bg4 5. h3 Bh5 6. Nxe5 Nh6 7. Qxh5 Qd7 8. Nxd7 O-O-O 9. Qxf7 Nxf7 10. Bxf7 Kxd7 11. O-O g6 12. Bxg6 hxg6 13. d3 Re8 14. Bg5 Rh6 15. Bxh6 Bxh6 16. g4 Be3 17. fxe3 Rf8 18. Rxf8 Nd8 19. Rxd8+ Kxd8 20. Nd5 c6 21. Nc7 Kxc7 22. Rf1 d5 23. Rf7+ Kd6 24. Rd7+ Kxd7 25. exd5 cxd5 26. d4 b5 27. c4 dxc4 28. b3 cxb3 29. axb3 b4 30. g5 a5 31. d5 a4 32. e4 a3 33. Kg2 a2 34. e5 a1=Q 35. e6+ Ke8 36. d6 Qb2+ 37. Kg3 Qxb3+ 38. Kh4 Qxh3+ 39. Kxh3 b3 40. d7+ Kd8 41. e7+ Kxd7 42. e8=Q+ Kxe8 43. Kh4 b2 44. Kg4 b1=Q 45. Kf4 Qb4+ 46. Ke5 Qb5+ 47. Kf6 Qb6+ 48. Kg7 Qd4+ 49. Kxg6 Qd6+ 50. Kh5 Qd1+ 51. Kh6 Qh1+ 52. Kg6 Qg1 53. Kh5 Qh1+ 54. Kg4 Qg1+ 55. Kh5 Qd1+ 56. Kh6 Qd6+ 57. g6 Qd2+ 58. Kg7 Qd7+ 59. Kh6 Qd2+ 60. Kh7 Qd7+ 61. g7 Qf7 62. Kh8 Qe7 63. g8=Q+ Kd7 64. Qg4+ Kd8 65. Qd4+ Ke8 66. Qa4+ Qd7 67. Qd1 Qxd1 68. Kh7 Qh5+ 69. Kg7 Qf5 70. Kh8 Qg6

Faqja Tjeter