I created an AI to Play Chess

Share
Embed
  • Published on Jul 24, 2018
  • Using minimax i created an Ai to play chess.
    Huge thanks to brilliant.org for supporting this channel, check them out at www.brilliant.org/CodeBullet
    I'll upload the program soon
    Twitter: code_bullet
    Patreon: www.patreon.com/CodeBullet
    Discord: discord.gg/UZDMYx5

Comments • 4 784

  • Colorswift
    Colorswift Year ago +1718

    even this AI could have lastest longer than xqc.

    • Lost Opportunity
      Lost Opportunity 9 days ago

      He didn't figure out random hope... Thank God.

    • jan Nowa
      jan Nowa 13 days ago +2

      @7OWN "the chess community is just consisting out of chess nerds" wow so true man your powers of observation skills are truly fantastic and unrivaled. Next you'll be telling me that the gaming community consists of gamers and the Lego community consists of Lego nerds. Maybe you'll even throw on some more sexism and say that there are no women in either of those communities either!

    • Tacizci¿
      Tacizci¿ 14 days ago

      Godzilla had a stroke while reading that.

    • Anastasia O
      Anastasia O 9 months ago +3

      @7OWN That assumes that woman do not program or play chess, which is very inaccurate. Society just pushes the guys who do it more than the women and, from people like you, subconsciously discourage other women from doing it by trying to say it's only a male thing and act like woman are so rare in it.

    • Joe Christo
      Joe Christo 9 months ago

      what’s that

  • Ethan Of All Trades
    Ethan Of All Trades Year ago +207

    As someone who likes chess and AI, I of course had to analyze every move between the two AIs. This chess game was more interesting than the grandmaster games I've studied... I learned a lot.

    • Ethan Of All Trades
      Ethan Of All Trades 3 months ago +5

      Now we need someone to make a video testing two AIs from Chess 100 where one is set to level 1 and one at level 50, but every time level 1 makes a mistake, we go back a move and force it to recalculate. If it is one single algorithm with added mistakes, then we should see level 1 with "takesies-backsies" dominate a standard level 50.

    • Ethan Of All Trades
      Ethan Of All Trades 3 months ago +7

      @R - G - C When the internet asks nicely, I deliver. :)

    • R - G - C
      R - G - C 3 months ago +1

      @bommer yeet He replied

    • R - G - C
      R - G - C 3 months ago +1

      @Ethan Of All Trades Wow man thanks for that!

    • Ethan Of All Trades
      Ethan Of All Trades 3 months ago +33

      @R - G - C The most interesting thing I think is how the Chess 100 AI seems to have a lot more awareness, but it chooses to make bad moves on purpose. It's most clear in the opening that black knows how to put it's pieces in good places. But on move 6 (pawn to d5), it suddenly makes a terrible move for no benefit and leaves a center square pawn unprotected and under attack. I think the chess 100 AI is a single algorithm for all levels, and they added a lot of mistakes to bring it down to level 1. This makes sense for a master chess program because you want the AI, even on level 1, to play like a human and use positional strategy and common openings, but it also needs to make enough mistakes that the human player has a chance.
      Another interesting thing is how CB is looking 4 moves ahead, but only for the best piece count. It doesn't have awareness of winning the game, so it just continues to take pieces until it can't anymore. It also doesn't have awareness of situations it must avoid, such as stalemate (but only if they are winning). I suspect that almost all games will end in stalemate.
      My biggest takeaway here was honestly how much is missing from a chess AI that can see 4 moves ahead, but nothing else.
      For anyone who's interested, here's the whole game in pgn:
      1. h4 d6 2. b4 h6 3. Bb2 Qd7 4. h5 e5 5. e3 b5 6. a3 d5 7. Bxe5 Kd8 8. f4 Ke7 9. g4 Rh7 10. f5 c6 11. f6+ Nxf6 12. Bd3 Qb7 13. Bxh7 Na6 14. Bd3 Qc7 15. Bxc7 Nxg4 16. Ba5 Be6 17. c4 Kd7 18. cxb5 Ke8 19. bxc6 Nxe3 20. dxe3 Bf5 21. Bxf5 f6 22. a4 Nxb4 23. Bd7+ Kf7 24. Qe2 Be7 25. c7 Rc8 26. Bxc8 Ke8 27. Qb5+ Kf7 28. Rh2 Na2 29. Qxd5+ Kf8 30. Rhxa2 g6 31. Qd7 Kg8 32. Qe6+ Kh8 33. Qxe7 g5 34. Qxf6+ Kg8 35. Qxh6 Kf7 36. e4 a6 37. Qxg5 Ke8 38. Qg7 1/2-1/2
      And here's a link to chesscompass where you can analyse the whole game. (No affiliation) www.chesscompass.com/analyze/b9cb802802d72d73e61e28102e9f9698

  • Diamond Dog
    Diamond Dog 2 years ago +2518

    6:23 Seeing the King and Pawn like that physically hurt me.

    • Omar Qasem
      Omar Qasem 5 months ago

      He fixed it without talking about it because it was stupid

    • bEansGuy
      bEansGuy 11 months ago

      Love how the queen took his king

    • Luka Plavevski
      Luka Plavevski Year ago

      me too

    • Dark Voice
      Dark Voice Year ago

      @Tester Wulf :3 Queen of England is a terrible example because there is no King of England. If there was, he would rule without her.

    • Tester Wulf :3
      Tester Wulf :3 Year ago

      @Dark Voice Except in kingdoms the spouse never takes rule after their leader and mate dies..like for example if the queen of England dies her husband wouldn’t take rule but one of her sons would.
      The point of chess is that once you kill the leader the kingdom falls apart as it’s a bit of a process to transfer rulership and without a ruler in the middle of war they’re kinda helpless and will lose.
      Whether the queen takes over or not they still lose as they’re torn apart from the inside and have too little time to recover in war.

  • Ridley Hult
    Ridley Hult 2 years ago +555

    Legend says he's still getting ready to release it

  • Superairdog
    Superairdog 3 years ago +8680

    You didn’t implement check and check mate. If someone is in check, they MUST make a move to save the king, or else they will lose.
    Edit: I made additional comments in the replies, please read them.

    • XenoPlayz
      XenoPlayz 13 days ago

      @BobV3 because making ai play chess is so easy

    • Seventythirst
      Seventythirst 13 days ago

      @OnlyRealmatze and queen side castling

    • Thom
      Thom 3 months ago

      @Rosto xBoomerang It doesn't work since you could capture the other player's king with a piece while leaving your king in check which is illegal.

    • Ryan Garvey
      Ryan Garvey Year ago

      @OnlyRealmatze and promoting and en passant

    • Voidling
      Voidling Year ago

      @Amaras A i hate this move that is why it was the first hing i thought

  • Erik Merrill
    Erik Merrill 2 years ago +581

    “We’re going to assign pieces values and from whites perspective we are trying to reach a high score.”
    That’s not how this works. That’s not how any of this works.

    • Henning Breede
      Henning Breede 19 days ago

      That's pretty much exactly how it works, just that the evaluation functions in engines such as stockfish are more complex. But this is exactly what they are doing.

    • ItsJustEthan
      ItsJustEthan 4 months ago

      @Aditya Mehta I didn't know that. That's actually really interesting. Thanks!

    • Aditya Mehta
      Aditya Mehta 4 months ago +1

      @ItsJustEthan Actually, it is quite easy. In chess programming they have things called piece square tables which is basically a 64 element array which says where each piece is best (there is of course not 1 perfect table but many different tables used by many different engines). For example, knights are best in the center of the board so the AI will simply check which square the Knight is on and then check the Knight piece square table and then use the value in the table. This is the bare minimum for any chess engine because otherwise it plays random moves until it sees a capture or checkmate.
      In actual chess engines, though instead of just using alpha-beta pruning other techniques would be used to prune and the move generation would be faster, but of course he is not trying to make a high level AI because that would take months. It is possible for one person to do this by themself, but as you said it is too much for just one TheXvid video.

    • Anunoriginaljoke
      Anunoriginaljoke 4 months ago

      Have you tried watching till the end of the video?

    • Donovan
      Donovan Year ago

      @JesusInStripeZ Except for the AI it's better for him not to get into a position to sacrifice for a positional advantage in the first place. When you consider just about every move that the other team can make for 15-20 moves and deal with the quintilions especially at the start that can bring, you dont need to sacrifice for positional advantage. Also its pretty bare bones to begin with. The AI pretty much does fight with minimax by that point. Minimax becomes the better strategy.

  • Adam Coburn
    Adam Coburn 2 years ago +787

    The queen just ate his king lmao

    • :D
      :D 16 days ago

      @ObnoxiouslyTrans thank you for saying captures and not eating.

    • R_G
      R_G 3 months ago

      his pawn is littearly putting the ai’s king on check

    • Master_ YT
      Master_ YT 3 months ago

      That's what she said

    • Dr. Cuckoo
      Dr. Cuckoo 3 months ago

      Pause
      ಠ_ಠ

  • DominikHatHunger
    DominikHatHunger Year ago +366

    "I'll upload the program soon"
    so that was a fucking lie

    • Will English
      Will English 11 months ago +2

      It's on the website, and the website is on his github so navigate to the project files and the folder is called Chess.

    • AllThingsIan
      AllThingsIan 11 months ago

      @Bartosz Konieczny he has a website?

    • Bartosz Konieczny
      Bartosz Konieczny 11 months ago +1

      Pretty sure it's on his website.

    • Meyer Reynaldo
      Meyer Reynaldo Year ago +4

      Yep it was

  • Daniel Abeleira
    Daniel Abeleira Year ago +7

    I love how he made a 3 minute tutorial on how to make chess before he started with the actual subject of the video

    • Shay Boual
      Shay Boual Year ago +2

      He can't even play chess aswell, he forgot about the concept of checkmate

  • Kapotos Fotis
    Kapotos Fotis 3 years ago +1180

    Dude your algorithm could have beaten Level 1 IF you had implemented check and checkmate. Your algorithm is clearly able to take all the opponents pieces but your heuristic for your minimax is wrong because the purpose of the game is not to take the most pieces, it is to checkmate. If you were to add that checkmate equals like 10000 points then your algorithm could easily beat level 1 even more if you increase the depth

    • Arthur, the Kyogre
      Arthur, the Kyogre Year ago

      THAT'S WHY I WANT PART 2

    • Davis Law
      Davis Law Year ago

      Something like checkmate=10000, being checkmated=-10000, stalemate=0

    • Iuri Grangeiro
      Iuri Grangeiro Year ago +1

      @Jdj Dfg worse than even that, there are multiple engines for MOBILE that can consistently beat the world's best.

    • Killertiger Gaming
      Killertiger Gaming Year ago

      He also missed stalemate pawn promotion and en passeant

    • GRBTutorials
      GRBTutorials Year ago +4

      JediNxf7 Chess engines are AIs. AI is a broad term that describes any kind of program that’s able to make decisions that look “intelligent”. In fact, this video shows an AI that’s similar to a chess engine, but simpler. What’s special with those two is that they use neural networks to read the board more efficiently. All (artificial) neural networks are AIs, but not all AIs are neural networks

  • Joel Oliver
    Joel Oliver Year ago +97

    I was in a chess club for 2 years and this physically hurt me

  • BenBen
    BenBen Year ago +37

    6:24 king subtly sits in check for the next 4 moves...

    • Yeetionary
      Yeetionary 6 months ago

      @BEN in chess,putting the king into check is an illegal* move (*illegal meaning you shouldn't do it)

    • BEN
      BEN 6 months ago

      The point of the game is to capture the other player's king first as I see it, but if the player is so bad that he doesn't know he can do that yet the game should probably let you stay in check how long you want

  • Iee Gordon
    Iee Gordon 2 years ago +356

    Microsoft: *castling*
    Codebullet: wait, that's illegal.

    • Patrick Tho
      Patrick Tho Year ago

      @weckar depends on the konvention/definition.
      If any object, that is on a chess board and takes part in the game (moving on the chessboard is a mechanic of this object, so the clock is ruled out) is defined as beeing a piece, then it is a piece.

    • weckar
      weckar Year ago

      @Patrick Tho Pawn also not technically a piece

    • Patrick Tho
      Patrick Tho Year ago

      @Panda Tobi yes, I said only one direction of the eqivalence not both, as it should be in a definition :)

    • Panda Tobi
      Panda Tobi Year ago

      @Patrick Tho you said 'can', not 'must'. regardless, i was joking, in that i was being needlessly pedantic over such a stupid correction.

    • Patrick Tho
      Patrick Tho Year ago

      @Panda Tobi I said "any other piece ..."
      The "other" means, that it isn't allpwed to promote to itself

  • Nolan Batur
    Nolan Batur Year ago +8

    Any possibilities of calculating the win percentage of the wooden shield strategy?

  • Albert Batfinder
    Albert Batfinder 2 years ago +2

    Apart from implementing ALL the rules of the game, you could do some simple work on the evaluation function. Adding up the value of the pieces is one thing. You can then then add increments to each piece for every square it can get to. A knight on the edge and a knight in the middle are not equal in value. A trapped rook is worth less than one on an open file.

  • Logan Cary
    Logan Cary 2 years ago +2

    This would work really well for my checkers AI! Checkers is much simpler than chess but still too complex for machine learning (in under a decade of training) so thanks for the algorithm explanation ;-)

  • Jon Arnzen
    Jon Arnzen Year ago +2

    From what I understand this is actually essentially how deep blue kind of works by trying to get a high value to win. Where now most chess engines are fed data along with brute forcing options and then determines the path that will most likely lead then to a checkmate.

  • Oppai Visuals
    Oppai Visuals 2 years ago +2

    its practically impossible to apply the mini max algorithm to the whole chess board since there are more iterations in chess then the atoms in the Observable Universe.
    That's why neural network is always preferred while making Chess AI

  • Bao Cypher
    Bao Cypher 3 years ago +1026

    Please make an AI that play Tetris at max speed and is able to do difficult spins, tetris, Tspin single/double/triple and combo

    • Zack Stump
      Zack Stump 24 days ago

      Don’t forget cascades

    • Brian Hope
      Brian Hope 3 years ago +1

      We got Tetris 99, now. We need this more than ever!

    • Dreckbob Bratpfanne
      Dreckbob Bratpfanne 3 years ago

      Modern or Classic NES/GameBoy Tetris?

    • Ahmet Gırcın
      Ahmet Gırcın 3 years ago

      It will set the best thing to the position of the game and next piece. If it's better to set a Tspin then it will. If it's better to set a tetris then it will.
      edit: boom,tetris for jeff

    • Jay Eisenhardt
      Jay Eisenhardt 3 years ago

      I don't see why you would need a T-Spin if you are playing Tetris right. Using that move means you already lost too many points. I guess it would be useful for making mistakes. Why would you want your A.I. to do that though?

  • Micael Pedrosa
    Micael Pedrosa 2 years ago +1

    Try to add points for each free move a piece have. Optimizing piece movement. You will be amazed how good the results will be. Rooks go to open lines, knights go to the middle, etc.

  • OXMOND Tutorials
    OXMOND Tutorials 2 years ago +4

    Me: “Wow! I've made an AI that actually can play chess!”
    Code Bullet: “How strong? What’s his rating?”

  • A Classy Phoenix
    A Classy Phoenix 2 years ago +1

    Did you know that in a single game of chess there are more possible moves than the number of atoms in the universe?

  • Calidad Furiousdestroyer

    I saw the game then remembered this guys work ethic and I knew. I knew this would be a piece of work

  • Nerika Cutie 2
    Nerika Cutie 2 2 years ago +32

    6:27 no check. Having check and checkmate is crucial for an AI since the game and your moves rely on them.

    • Samuel
      Samuel 15 days ago +1

      Looks to me like he didn't only not account for illegal moves (you're not even allowed to sacrifice the king). The AI also didn't seem to get any penalty for sacrificing the king nor reward for a checkmate. For example: around 9:25 it misses an easy mate in two, despite supposedly looking four moves ahead, meaning it must have prioritized capturing pawns over the checkmate, in turn letting the opposing AI play into a stalemate.

  • Karasight
    Karasight Year ago

    That moment when you’ve ACTUALLY CODED MINIMAX and for once you actually know what the hell he’s talking about

  • Luredreier
    Luredreier Year ago

    I'd love to see you do a really good chess ai.
    Or even multiple different ones?

  • u8f7
    u8f7 3 months ago

    That was really interesting! I had a gander at the description and it says "program will be uploaded soon" even though it's been 3+ years, I'd be really interested to check it out! Def agree that you should revisit this with more implementations, adding rules like you have to move out of check, etc.

  • ian oñate
    ian oñate Year ago

    Ah yes. The good old times. When code bullet explanations were actually true

  • AbsurdismBeLikeThat
    AbsurdismBeLikeThat 3 years ago +147

    If you plan on improving the AI you should make the King have infinite value(or enough that it would be more than the sum of all enemy pieces) because if you lose it you lose the game. The concept of checks and castles seemed missing but it is a pretty good start.

    • Rumford Chimpenstein
      Rumford Chimpenstein 3 years ago +1

      +Flerikko I don't know if you missed it but at 5:03 he is literally showing the 'value' he's assigned to each piece.

    • OKay5067
      OKay5067 3 years ago

      Dante according to stockfish... Well and alpha zero won. Seems pretty obvious to me

    • Ethorbit
      Ethorbit 3 years ago

      Flerikko when someone thinks they know what they're talking about

    • Daniel _
      Daniel _ 3 years ago

      But a value of a piece is highly subject to its position on the board, which is extremely hard to pinpoint.

    • Zychuu
      Zychuu 3 years ago +1

      En passant is missing too.

  • Reece Norwood
    Reece Norwood 3 months ago

    Never thought I would get a quick lesson in game theory by watching an A.I play chess

  • The Tony Express
    The Tony Express Year ago +1

    I'd love to see a vid of this one being further improved

  • Nick Alemany
    Nick Alemany 2 years ago +3

    I remember reading this thing and it was saying something like, “there are more possible ways for a chess match to end then there are atoms in the observable universe.”

    • Eric B
      Eric B 2 years ago

      not more ways to end, there are 3 of those, but many many more possible chess games that can be played. probably more than the number of atoms in the universe, multiplied by that same number.

  • Yahia
    Yahia 10 months ago +1

    10:24 that was a pretty good tactic , considering the level of the AI !

    • Psycho SledgeHammer1237
      Psycho SledgeHammer1237 4 months ago

      Well it isn’t because Rxh8 is better because if Nxe2 then Rxg8#, Bf7 dosent work because you just lose ur rook and black doesn’t even need to take the bishop because the queen and rook is hit

  • Will Jerden
    Will Jerden Year ago

    As a casual chess player: This AI hurt my brain.

  • Willie Pierce
    Willie Pierce 2 years ago

    Hey I wouldn't mind seeing you do something like this with neural networks. Maybe train it by having it play the Microsoft game. Having the computer move the pieces and what knot... or just have it play itself. Over and over.

  • Ok
    Ok 2 years ago

    you could also make the AI protect its pieces so when a piece it taken it can take one as well

  • Jesse Kinghill
    Jesse Kinghill 2 years ago

    Love chess, would love to see a rework of this

  • Orion Nash
    Orion Nash 10 months ago

    This brings me back to when I set up a Crafty AI on my computer and uploaded tons of tablebases to it so it could wreck nerds on chess.net. It only got rated about 2300 in blitz. I'm curious what the rating of your AI would be. Also, did you program in "En Passant" where pawns could deny other pawns privilege to move two spaces on their first move?

  • Some One
    Some One 2 years ago

    I once attempted to create an Excel Chess Engine, by having the up down direction represent time, and for each piece having one column representing the x position of the piece, and one the y position of the piece, and using the numbers in the cells to represent the locations of the pieces on the board. I tried using conditional formulas, to control how the pieces move, but could not fit enough information into my formulas to get it to work, and so gave up on trying to create an Excel Chess Engine.

  • broccolidood
    broccolidood 2 years ago

    I'm thinking, how much computer power would you need to actually minimax chess? Is it feasible, or would you need to turn the entire universe into a computer? Also, I wonder how that'd work because two players can walk around the board infinitely, so it'd need some sort of way to exclude possibillites of both players doing nothing

  • charmeleon evolves
    charmeleon evolves Year ago +1

    Cb: I'm 90% sure you guys know how to play chess
    Me: 👁️👄👁️

  • Christopher Ko
    Christopher Ko Year ago

    The hardest chess AI i have ever gone against crashed the game whenever i was winning.

  • it's just me
    it's just me 3 months ago

    We need a chess master to try and beat this AI

  • David Perry
    David Perry 2 years ago

    Definitely sounds interesting. You should totally add the other rules and make it better!

  • Deleted Channel
    Deleted Channel Year ago +6

    3: years later... Still haven't uploaded the program to play the chess bot

    • raydarable
      raydarable 6 months ago

      Five months later... Still nothing.

  • Soup-Flavored-Soup

    This just sounds like playing against an ai with extra steps

  • Jackson Jackwagon
    Jackson Jackwagon 9 months ago

    CB: “dont know why im telling you this, 90% of yall know how to play chess”
    Me: the 10% that doesn’t know

  • Frax
    Frax 16 days ago

    as someone who've played chess for 6 years...
    my disappointment is immeasurable and my day is ruined

  • Captain Awesome27
    Captain Awesome27 2 years ago +3

    Code bullet: "Any time the AI looks ahead-"
    Me: CHESS AI! EPITAPH!

  • XxConsole PlayerXx
    XxConsole PlayerXx 3 years ago +93

    I hope that this comment can help you building the AI: in the scripting part you forgot some rules:
    the rule of castling, which "consists of moving the king two squares towards a rook on the player's first rank, then moving the rook to the square over which the king crossed. Castling may only be done if the king has never moved, the rook involved has never moved, the squares between the king and the rook involved are unoccupied, the king is not in check, and the king does not cross over or end on a square in which it would be in check." (quote from Wikipedia).
    Other rules are: when the king is in check, he has to move or a piece must defend him, and this means that king can't be captured, infact he doesn't have any "value"; when a piece is "pinned", "a situation brought on by an attacking piece in which a defending piece cannot move" (quote from Wikipedia) without exposing the king and therefore putting him in check.
    Other two rules are that pawns which reach the last rank can be promoted in any other pieces and the infamous en-passant rule that many chess beginners don't now about (some of them complain that it's a "bug" when they see it the first time ahahahaha). Last but no least, it's missing the rules of checkmate and stalemate (you noticed that when confronting the level 1), that are 2 ways that a game can end. The third way is resigning, which isn't necessary.
    As you stated in the end of the video, the minimax algorithm also takes in consideration many more variables when exstablishing the value of a position: i. e. if a position leads to a checkmate, a win, it has obviously a very high value. An other example - more complex but helps with the understanding - if you are in a very bad, loosing position and you can force or at least try to reach a stalemate, those moves have a higher value.
    You're a very good scripter! Keep up with the videos also, they're very interesting and you put a big effort behind them, explaining with simplicity and in an entertaining way a topic like coding! Greetings
    -An average chess player from Italy

    • Aniruddh Barve
      Aniruddh Barve 3 years ago +1

      XxConsole PlayerXx *pawn which reaches last rank.

    • XxConsole PlayerXx
      XxConsole PlayerXx 3 years ago +3

      Chess is a simple concept but it has a lot of rules and I totally forgot this one... God good ahahaahah

    • Robin Winkels
      Robin Winkels 3 years ago +3

      A minor thing you forgot is the 50 moves rule: After 50 moves without a piece getting captured or a pawn moved both players can claim a draw.

    • XxConsole PlayerXx
      XxConsole PlayerXx 3 years ago

      As I mentioned before, I'm not a coder, the only thing I knew was that chess computer used the minimax algorithm by reading a bunch of pages of internet... You're surely more competent than me and so does CB, I'm pretty sure he'll use your advise and create a good AI.

    • XxConsole PlayerXx
      XxConsole PlayerXx 3 years ago

      I think I forgot only the threefold repetition rule, but it is not so important considering this is a video on YT ahahahah

  • Dan Jeory
    Dan Jeory 2 years ago

    I'll upload it soon..... I guess coding in the full rules of chess takes a bit longer than he realised 🤣

  • Niek
    Niek 2 years ago

    Add the idea of stalemate, check, and checkmate in the ai, add machine learning + add something that lets the computer know, hey they 4 most center squares are the most important squares. And let it train by playing against itself.

  • Tristun Alekzander

    8:50 that's a bug, it should have seen that move led to a lower positional value. That's why it doesn't win, it's because it isn't working right. I had similar bugs in my A.I. and although it wouldn't be great with just the integer position values as you said, it would still be able to beat that first level A.I. You should come back to this one man and make it better. A little tip I can give is it plays a lot better if when you calculate the positions' values, you count how many possible moves each piece has and use that to give them a very, very small bonus to the piece's value. Pawns are different, base their bonus value on whether or not another friendly pawn is diagonally or horizontally adjacent to it. This little trick actually makes it play like a human in the opening, it will usually play e4 to open because it opens up more possible moves for its queen and its bishop, which is the same reason human players like to play e4. It also causes the A.I. to inversely try and limit its opponent's total amount of possible moves and isolate their pawns. Just make sure that the maximum amount of total bonuses a position can grant to the pieces isn't itself worth more than even a single pawn, so it won't sacrifice a piece for a better position, I just divide the bonus by 32 (for the 32 maximum amount of pieces on the board, it doesn't matter how small it is as long as the total bonus amount is never greater than a pawn's value). I've found having a high bonus makes it play extremely aggressively but recklessly.

  • Kami Akainu
    Kami Akainu 2 years ago +2

    Code Bullet: Viewer retention is dropping
    Me: *Gripping the edge of my seat at the sight of such an intense battle of wits*

  • David Phillips
    David Phillips 3 years ago +179

    You should make another basic chess engine where piece values vary by how many squares they control instead of the static 1, 3, 5, and 9. I would be interested to see how an AI that only values material value would stack up against an AI that only values control of squares.

    • Meowmere
      Meowmere 2 months ago

      it's less about how much space each piece has and more about where the pieces are

    • Mirarkkthur
      Mirarkkthur 3 years ago +3

      @Marouane H And the Chessomat is a complete database with millions of movesets that always just spawns the optimal move, which is why no human player ever defeated it but its weak against other AIs. :D

    • Marouane H
      Marouane H 3 years ago +2

      That's what chess AI do, given a position, they look at every piece and give it a score based on a heuristic, and compare the total scores for black and white. Different heuristics give rise to different styles. A checkmate is affected infinity, to make the AI sacrifice pieces to win the game if possible, or to avoid being checkmated.
      Specific score values differ from one AI to another, but they follow the same general ranking of importance more or less. A passed pawn is worth more than a pawn that hasn't moved, a pawn late game is worth more than a pawn in the early game, a double pawn is not worth as much, a knight's worth depends on its position, if there are too many pawns a knight is worth more than bishop, and vice versa, a piece's worth is affected by the number of peaces attacking it or defending it, and on whether it's pinned, etc. In the opening, the AI is usually given bonus score for castling ASAP and for developing pieces, some AI have an opening hand book that they pick the few first moves from, others like Stockfish compute from move 1.

    • ShaBer
      ShaBer 3 years ago +4

      Wow, interesting concept! Since for you to be able to control squares, it would automatically be careful with pieces positioning and also material as well, since it wouldn't be able to control as much if it gives pieces away, however I think it would be possible to "cheat" the crap out of it, if you're careful enough to lock all your pieces and give all the mobility to your opponent, then you could then capture some of the AI pieces in a way that he would think he was still in advantage, but suddenly you would unlock all your pieces and exchange the remaining pieces, simplifying to an easy to win end game, but I really think it worth a try! :d

  • JCDP's gamming zone
    JCDP's gamming zone 2 years ago

    when you realise that he has to remake every game he adds A.I to

  • Paul S
    Paul S Year ago

    arguably, AlphaZero is the strongest AI chess program as well as a few others (like Stockfish for example) that since 2014 eclipsed DeepBlue in playing ability

  • Flik
    Flik 2 years ago

    You always say your videos are getting too long, but I would love watching more!

  • Marcus Bordeaux
    Marcus Bordeaux Year ago

    Code: I sure 98% of you know how to play chess Also Code: Has clearly never played other than an elementary level

  • Deldrel
    Deldrel 3 years ago +379

    AI learn to play Tetris could be really cool (lika all the other ones)

    • Ricci is cool
      Ricci is cool 11 months ago +1

      It came soooo

    • Kaiden
      Kaiden Year ago +1

      it came true, youre a prophet

    • NANCOK
      NANCOK 3 years ago

      The closest to that i've seen is a TAS of tetris, plays even better than a IA could

    • s0mePi
      s0mePi 3 years ago

      Deldrel I second this

  • Trey Best
    Trey Best 2 years ago

    I know a lot people are pointing the whole "check(mate), castling, and en passant" but Knights can also jump players, they're the only ones. Pretty important part of strategy in the game actually. Would love to see you make this one as good as you could get it.

  • Drecon84
    Drecon84 2 years ago

    There are a bunch of rules of chess that are a lot of work to code. When I did my own it took me pretty long to do the rules for castling and such.

  • Simon King
    Simon King 2 years ago

    You should have included an arbitrarily super-high piece value for the King, say 1,000,000, to (begin to) implement checkmate aims in the AI.

  • kevkevplays
    kevkevplays 4 months ago

    When you have only your kings left neither of the opponents will win unless one forfeits, this is called a war of attrition(i think) where neither outcome is favorable and it becomes a waiting game

  • Memento Mori
    Memento Mori 3 years ago +59

    The biggest Problem with the AI is that it has the wrong goal.
    The AI tries to take a many pieces as possible while completely ignoring the not only the positioning, but also the King!
    the actual goal should be to place the enemy King into a checkmate. The other pieces are just a means to the end, but for the final goal they're all irrelevant.
    And quick fix might be to give the King a very high number so that putting the king in a checkmate would be a very valuable move to consider. In your value appointment for the pieces, you completely ignored the King, so I don't know wether or not it has any value and how high this value is.
    Try setting it to something like 40 (sum of value of all other pieces + 1) or so. That should make the AI try to go after the king much more.
    Of course, this could also backfire if it makes bad moves and sacrifices all of its pieces just to try to get to the king which it might never reach...

    • ca-ke
      ca-ke 3 years ago

      I think a good way to implement positioning value is to calculate the value of the squares that the piece can currently see instead of just the value of the piece via standard chess ideas. Anyways the idea of a rook (5pts) being worth more than say a knight (3pts) is due to it having more potential uses and less the state of the board at any given time so the minimax should take care of that (since it looks into future possibilities). To add to that we should have a value for each square on the board in terms of the importance of controlling that area (which is very complicated judgement already, but a simple way would probably to just have a heatmap of squares a certain moves away from opponent pieces, with the king's capture being the most important and capturing a pawn being the least. (So the queen's current square is worth loads, and the squares that the queen can go to are worth some fraction of the queen's value). So checkmate would be being able to control all of the king's moves and the square the king is currently on.

    • Daporan
      Daporan 3 years ago +1

      Great answer Vajom! Thanks for the sub btw.

    • Vajom
      Vajom 3 years ago +1

      if you give the vallue infinite to the king it does just that. How do you input infinity in the computer? you don't have to: any value above the maximum combined vallues of all pices makes the computer value the king as infinite.
      now the positionnig part is a mondial challenge that stockfish and alphazero creator are trying to solve by different approaches:
      first the convenional chess engine are algorythm that uses humain understanding of chess to value a pice within the position. How many squarres can it move to? does it attack enemy king?...
      in the otherside neural network and machine learning is trying to make computer learn bether than what humans understand
      this is not a challenge a man can solve alone in a week just to make a youtube video

    • Daporan
      Daporan 3 years ago +1

      I love to see other people who like AI, I have some AI demo's on my channel, let me know if you'd like to see tutorials.

    • Memento Mori
      Memento Mori 3 years ago +4

      yeah, based on the minimax Algorithm he's using it should basically end up with the exakt same game with the only difference that, at the end, it will go for the king a little more if it has a chance (especially if there is a guaranteed checkmate, which often is the case... so unfortunately, it often takes more than just 4 steps to get to the guaranteed checkmate).

  • Fake Name
    Fake Name 3 months ago

    It seems like adding a few more variables would help a ton. Basic numbers like, # of black pieces in a position to take space X. # of white pieces protecting space X. # of pieces that piece Y is protecting. Give the AI points for defense and you could see much more coherence within the moves. Probably wouldn't add too much to processing time.

  • Asrito Ken
    Asrito Ken Year ago +1

    Code Bullet: Says "You can try to beat his A.I. , because he will put the link in the description."
    Me: *Checks Description*
    Code Bullet in Description: Says "I'll upload the program soon".
    Me: *Watches two years after upload*
    *In complete disbelief that anyone is that lazy*

  • Cossicrots 42
    Cossicrots 42 Year ago +30

    Code Bullet “I’m 98% sure you know how to play this game.”
    The other 2% AKA 20,000 people. “What about us?”

    • Cossicrots 42
      Cossicrots 42 Year ago

      IHateFatFurriesWeebs and theDisabled If no one laughed, then why does the joke have 28 likes? Hmmmm? Exactly. People did laugh.

    • Torbothy
      Torbothy Year ago +1

      @Cossicrots 42 its cringe because no one laughed at that garbage I wouldn't even call a joke

    • Cossicrots 42
      Cossicrots 42 Year ago

      IHateFatFurriesWeebs and theDisabled Cringe? How is it cringey? It’s not cringey at all.

    • Torbothy
      Torbothy Year ago

      @Cossicrots 42 yea the quite innocent joke was super unfunny and cringe kid

    • Cossicrots 42
      Cossicrots 42 Year ago

      IHateFatFurriesWeebs and theDisabled Quite the language for a small innocent joke.

  • Tim Burton
    Tim Burton Year ago

    It amazes me that he did all this in 11:52 well played brother

  • The Random Raccoon Dog
    The Random Raccoon Dog 2 years ago +1

    both times he "tied" the other AI was in checkmate then gave up and told him they "tied" no wonder the other AI is hard ITS UNBEATABLE

    • The Random Raccoon Dog
      The Random Raccoon Dog 2 years ago

      white made a move black had an unmoveable pawn and a king not in check but if moved dies. seems like black lost to me

    • Danijel Naporic
      Danijel Naporic 2 years ago

      They were both playing terribly bad

  • Bryan Jensen
    Bryan Jensen 2 years ago +1

    Start the AI learning from only two kings left, then two kings and a pawn, two kings and two pawns, so on and so forth. Also starting from two kings one queen would be something to run against two kings and a pawn or what ever piece you are looking at. Learn from less moves and grow into using all pieces. Stalemate equals infinity so avoid that.

    • Micah Wright
      Micah Wright Month ago

      Two kings left is automatic stalemate

  • Sean Mitchell
    Sean Mitchell Year ago +1

    Why is there so many negative comments on this like I love chess and I know that he did good to make an Ai even this good like if anyone else wants to try it and do better then go ahead but no one will because it takes a lot of time and patience

  • Nathan Crane
    Nathan Crane 2 years ago

    I did the same program (without AI though so it was way more simple) in computer science and watching the beginning gave me nam flashbacks

  • kevnar
    kevnar 3 years ago +437

    Challenge for you: Can you create an AI that can parse a human question and return an answer from a given piece of text? For example, give it the Wikipedia article on Beethoven, and ask it "What year did Beethoven die?" Or give it the lyrics to the Itsy Bitsy Spider, and ask it "What washed the spider out?" Then if it can return the correct answer from the source text, you win.

    • André Rhine-Davis
      André Rhine-Davis 3 years ago

      Wolfram Alpha can do it to some extent

    • teenspirit1
      teenspirit1 3 years ago

      ​@Kaappo Raivio watson hasn't been around for four years now. It isn't in the API docs anymore. IBM image recognition is about as good as google's and microsoft's. They all train the same resnet 50 these days.

    • That One Guy
      That One Guy 3 years ago

      kevnar
      No

    • Samuel Harverson
      Samuel Harverson 3 years ago

      Phil Rodgers l

    • Dexxus
      Dexxus 3 years ago +2

      I don't think you understand just how ridiculously advanced that request is.
      We've only recently managed to get the absolute best supercomputers to that level in the last few years or so, and there's only a handful of them.
      Language processing is incredibly advanced, and would be outright impossible to impliment for one person with little to no budget that, to be quite frank, is pretty terrible at making AIs to begin with.

  • syroyoga16
    syroyoga16 2 years ago

    Idk how you do all this coding looks super complex af. But you make it look really cool

  • Andrew Rivedal
    Andrew Rivedal 2 years ago +133

    "Grandmasters think like 7 moves ahead"

    • Ricci is cool
      Ricci is cool 11 months ago

      @mo7ammed a7med bruh an IM thinks like 5 moves ahead and a GM is better than a IM by a large gap

    • Sujal S
      Sujal S Year ago

      Grandmasters don't always think X moves ahead. Calculation like that is usually only done in endgames. In the rest of the game they just make moves that help them develop and stuff. Humans don't just look many moves ahead like computers.

    • Darth Vader
      Darth Vader Year ago

      @OriFl Except if you are a GM you are thinking more than 7 moves ahead on a regular basis, play chess a little more before you correct somebody :(

    • OriFl
      OriFl Year ago

      ​@Darth Vader actually it doesnt. "Grandmasters think 7 moves ahead" means that if you are a Grandmaster, then you are thinking 7 moves ahead. However, if you are thinking 7 moves ahead, it doesnt necessarily mean that you are a grandmaster.
      For example, if it rains, it means that there are clouds in the sky. however, it there are clouds in the sky, it doesnt necessarily mean that it rains.

    • Potatoe Dealer
      Potatoe Dealer Year ago

      @Darth Vader I recommend watching Hikaru nakamura premoving 17 or 69 moves

  • Xyloz Quin
    Xyloz Quin Year ago

    When you don't assign a value to the king the AI won't target the King will it.
    Additionally at end game the king / one peice needs to be able to move to avoid stale mate but the king needs to be trapped in order to checkmate. Solve for these and you have a brutal AI.

  • Wiltonlaws
    Wiltonlaws 2 years ago

    Please come back and revisit this idea, that would be cool to see how far it could get

  • A Classy Phoenix
    A Classy Phoenix 2 years ago +4

    Did you know that in a single game of chess there are more possible moves than the number of atoms in the universe?

    • A Classy Phoenix
      A Classy Phoenix 2 years ago +2

      @Seth Carter nope, just a nerd.

    • Seth Carter
      Seth Carter 2 years ago

      Glad to see some one watched no game no life

    • NJS
      NJS 2 years ago

      Cool

  • Adrian J
    Adrian J Year ago +1

    AI thinks 4 moves ahead and decides: "yes, the scandinavian"

  • Ale Kid
    Ale Kid Year ago +1

    I like how chess AI is actually a logically structured conditional algorithm, not just a jumbled neural net

  • 0MindSwept0
    0MindSwept0 2 years ago

    The first turn for each player isn't 20, but 24 since the knights can move over the pawns

  • Joshua Fetter
    Joshua Fetter 3 years ago +70

    You gotta revisit this with all the chess rules implemented.

    • I’ma Faux
      I’ma Faux 7 months ago +1

      Like ya know, checks, and check mates

  • spencer hockensmith

    So, in this version of chess, there is no castling, no en passant, no checks, and you don’t win by checkmate, you win by actually capturing the Opponents king. I believe that most of that was how chess was played a longgggg time ago. Code zero was just trying to bring this game off chess back to its roots

  • comicsansgreenkirby
    comicsansgreenkirby 2 years ago

    Will it beat the ASTRAL Chess Board though? I haven't seen any of the chess AIs to that yet.

  • Joshua Spector
    Joshua Spector Year ago

    I want to see this get good and then play nerds on the internet. 😂 also I was really hoping to see if they knew en passant.

  • Nichtsistkostenlos
    Nichtsistkostenlos 2 years ago

    How the hell do you spend so much time to actually write an entire chess program and an AI to play it without using 15 min of that time to look up the rules of chess?

  • statikreg
    statikreg Year ago

    I wonder what would happen if you added a psuedorandom component so it occasionally veers off the optimal course.

  • MrMonkeyMan
    MrMonkeyMan 11 months ago

    “I used the AI to destroy the AI”
    I WAITED TO SAY A MEME

  • Captain Roach
    Captain Roach 2 years ago +39

    6:23 THE KING IS IN CHECK

    • Alex2005z
      Alex2005z Year ago +1

      Why didnt he make the king worth just 100000. Problem solved

    • Pedro Umbelino
      Pedro Umbelino 2 years ago +1

      I was curious to see what would happen if the pawn took the king 😅

  • Asura
    Asura 2 years ago

    So er...you guys all want him to implement EVERY checks in the game?
    Why not ask him to program a entire proper game of chess at that point?

  • Klandalf The White
    Klandalf The White 3 years ago +17

    Perhaps in future avoid switching, especially rapidly, between majority dark and majority white screens. Just a quality of video suggestion.

  • Taffy_Factions
    Taffy_Factions Year ago +8

    "I'll upload the program soon" (3 Years later) welp fuck

  • Ralf Maapalu
    Ralf Maapalu Year ago

    Code Bullet's computer: I can calculate some moves
    Stockfish (can calculate 99 moves)

  • Fakhri Asyraf
    Fakhri Asyraf 2 years ago

    Did you assign a value for the king? Would giving the king a value of 999 make the AI know how to checkmate?

  • Tieemon :D
    Tieemon :D 2 years ago

    The AI should at first look if it can force a mate. Since this is always the best option.
    You could teach it basic positioning rules like the center should be controlled, cause it's most valuable, development of own pieces and enemy pieces is important.

  • Julian Lazaro
    Julian Lazaro 3 years ago +219

    PLEASE DON'T HATE ME FOR SAYING THIS; I love his videos, but he forgot to add castling to his code.

    • TheMiracleMatter
      TheMiracleMatter 3 years ago +2

      @Not You Someone is having salty flashback ?! xD

    • Hymns For Disco
      Hymns For Disco 3 years ago

      And promotion

    • Caerere
      Caerere 3 years ago +6

      @Not You If he knows the rules better and he wins because of that, that's on you. It makes him the better player.

  • Renier
    Renier 2 years ago

    one thing i see is never implemented is that if you haven't moved your king and right rook you can do a move which places the root 4 left and the king 3 right

  • Star & Ruby
    Star & Ruby 2 years ago

    You should make a sequel where you do it correctly. It’s a great idea, but you missed so many rules(check checkmate stalemate promotion castling)

  • Caden O'Donnell
    Caden O'Donnell Year ago

    Wouldn’t right left right right have been the best path for tour AI tree thing to choose from?