Chess AI
A downloadable game for Windows, macOS, and Linux
Download NowName your own price
My attempt at creating a chess program. It's not terribly good at the moment, but it will happily gobble up your pieces if you're not vigilant! I hope to improve it in the future.
The source code can be found here.
Video about the development here.
Download
Download NowName your own price
Click download now to get access to the following files:
Chess 20 MB
Chess 20 MB
Chess 23 MB
Comments
Log in with itch.io to leave a comment.
Reaaaaallly Cool! Can you teach me, sebastian?
Here's another game: I played the sharp 'B90 Sicilian Defense: Najdorf Variation, English Attack' and sacrificed my bishop to gain a strong attack. Notice that black(AI) isn't moving any pawn to attack my King. And when I was about to deliver checkmate, Its eval showed 00.25!
Additionally, I think your Chess AI cannot play openings that require sacrifices or strong pawn attacks, such as the Sicilian Defence, or the English opening I showed I my previous comment.
https://lichess.org/DjkVv9j6#59
In this game, the AI just allows me to checkmate instead of taking the Knight with its Queen.
pgn:
1. c4 g6 2. Nc3 Nc6 3. e3 Nf6 4. d4 e5 5. Nf3 e4 6. Ng1 Bb4 7. f3 Bxc3+ 8. bxc3 d5 9. cxd5 Nxd5 10. Qc2 Bf5 11. fxe4 Qh4+ 12. Qf2 Qxe4 13. Bd2 Qc2 14. Nf3 Nxc3 15. Bc4 Qb2 16. O-O Nb1 17. Bxf7+ Kxf7 18. Ng5+ Ke7 19. e4 Qxa1 20. exf5 Qxa2 21. Qe3+ Kd6 22. Qf4+ Kd7 23. f6 Nxd2 24. Qg4+ Kd8 25. Ne6+ Kc8 26. Nc5+ Kb8 27. Nd7+ Kc8 28. Nb6+ Kb8 29. Qc8+ Rxc8 30. Nd7#
Your AI had a 77.9 accuracy against Stockfish 15. Not bad
OK it beats me it's either good or I am bad
And I rage quitted
I found a big glitch.. It thinks bxc5 is a move..
This is the game:
https://lichess.org/paste?pgn=1.+e4+c6+2.+d4+d5+3.+Nd2+dxe4+4.+Nxe4+Bf5+5.+Ng3+Bg6+6.+h4+Nf6+7.+h5+Be4+8.+Rh4+Bd5+9.+c4+Be6+10.+Bd3+Qa5%2b+11.+Bd2+Qb6+12.+Kf1+Qxb2+13.+Rb1+Qxa2+14.+Qc1+Qa6+15.+Ra1+g5+16.+hxg6+Qb6+17.+gxf7%2b+Kd7+18.+Ba5+Qa6+19.+Nf3+Kc8+20.+Ng5+Bd7+21.+d5+c5+22.+Qe3+b6+23.+Bc3+Qb7+24.+Bxf6+exf6+25.+Rxh7+Rxh7+26.+Qe8%2b+Kc7+27.+Qxf8+Rh4+28.+Be4+Rxe4+29.+N3xe4+Qc8+30.+Qxc8%2b+Bxc8+31.+f8%3dQ+fxg5+32.+Qd6%2b+Kb7+33.+Nxc5%2b+bxc5+34.+Rb1%23+
Stockfish had just sacked its knight for the b6 pawn but the ai thought it was still there!?
Was it a transposition error?
maybe one of the duplicates of zobrist hashing (see video
Likely
I don't know if I'm just blind, but I don't see a problem
I dont see the error, it doesnt think bxc5 is a move, he show what it moved before..
Started getting interested in chess after watching your vid, gonna get this to practice :)
Sebastian,
Great chess program! Would you mind doing two things for it? A windowed mode, and board inversion so you can play white bottom or top? Alpha-numeric on the side and bottom would be a nice touch also (well, three things).
Shawn
Great engine! I played it a few times, and I lost more games than I care to admit. My ego was a little hurt :p . At least when playing, so to speak typical openings. It feels like it has an opening book. If I didn't know better, (I assume it doesn't).
However, if I play anti-engine chess. Like the Hippo ( absolute garbage opening btw ) I literally feel like I could do anything and win. For example in one of the games. I blundered a rook and its eval was +4. I Still manage to win. It just pushes all its king side pawns and gets mated.
Another weird thing happen (its hard to explain), His queen was on h5 and then he would play Qf5, then I would play Nh4 attacking the queen. He would then move it to g5. I would move my knight back to f3 attacking the queen. Then it would just play Qh5 again. giving me a tempi. It did this until I "allowed" it to smother mate me in 1 hehe.
I only played 20 games or so, but in some aspects it feels like a GM and in others like a 1200. Oh one more thing, it evaluated a drawn rook endgame as +1 up until it was a draw. Even the turn before the 50-move rule kicked in. I assume its not aware of the rule ( the algorithm playing).
There is a file called opening book in the source code.
Hi thank you and beautifully work how much will you charge me to the same in javawfor checkers game?
The AI seems to be able to play well in some positions, but doesn't fair well against gambits and sacrifices due to overvaluing material.
Stafford Gambit (Computer is White): 1. e4 e5 2. Nf3 Nf6 3. Nxe5 Nc6 4. Nxc6 dxc6 5. Nc3 Bc5 6. h3 h5 7. d3 Qd6 8. Be2 Kf8 9. O-O Ng4 10. hxg4 hxg4 11. e5 Qxe5 12. Bh6 Rxh6 13. Re1 Qh2+ 14. Kf1 Qh1#
Fried Liver Attack (Computer is Black): 1. e4 e5 2. Nf3 Nc6 3. Bc4 Nf6 4. Ng5 d5 5. exd5 Nxd5 6. Nxf7 Kxf7 7. Qf3+ Ke6 8. Nc3 Nb4 9. d4 Nxc2+ 10. Kf1 Nxa1 11. Bxd5+ Kd7 12. Qf5+ Kd6 13. Qxe5+ Kd7 14. Qe6#
AI time limit problem could be solved by making it increment as the game goes. It could take longer in worse positions.
searchTimeMillis = min(1 + (turns_in_game * position_favorable% * some _C), time_left / 2)
Fried liver as Macarc mentioned
1. e4 e5 2. Nf3 Nc6 3. Bc4 Nf6 4. Ng5 d5 5. exd5 Nxd5 6. Nxf7 Kxf7 7. Qf3+ Ke6 8. Nc3 Nb4 9. a3 Nxc2+ 10. Kd1 Nxa1 11. Nxd5 Kd6 12. d4 c6 13. Bf4 exf4 14. Qxf4+ Kd7 15. Re1 Qa5 16. Qf5+ Kd8 17. Qg5+ Kd7 18. Re7+ Kd8 19. Rf7+ Ke8 20. Rxf8+ Kxf8 21. Qe7+ Kg8 22. Qe8#
It's quite challenging! I managed to get it eventually using the fried liver attack (transposed from Petroff):
1. e4 e5 2. Nf3 Nf6 3. Ng5 Nc6 4. Bc4 d5
5. exd5 Nxd5 6. Nxf7 Kxf7 7. Qf3+ Ke6 8. Nc3 Nb4
9. d4 Nxc2+ 10. Kd2 Nxa1 11. Bxd5+ Kd6 12. Nb5+ Kd7
13. Qf5+ Ke7 14. Qf7#
Fell for the Blackburne Shilling gambit:
1. e4 e5 2. Nf3 Nc6 3. Bc4 d5 4. exd5 Nd4 5. Nxe5 Qg5 6. Nxf7 Qxg2 7. Nxh8 Qxh1+ 8. Bf1 Qe4+ 9. Qe2 Nxe2 10. d3 Qxd5 11. Bxe2 Qh1+ 12. Bf1 Bh3 13. Nd2 O-O-O 14. d4 Re8+ 15. Kd1 Bxf1 16. Nxf1 Qxf1+ 17. Kd2 Bb4+ 18. c3 Qe2#
Fun game!
It took me an hour to beat the AI. The AI is difficult imo.
10/10, would play again.
1. e4 d6 2. d4 Nf6 3. Nc3 g6 4. Be3 Nbd7 5. Qd2 e5 6. f3 exd4 7. Bxd4 Be7 8. Qh6 c5 9. Bf2 Qb6 10. Rb1 Bf8 11. Qd2 Bg7 12. Nb5 Bf8 13. Rd1 a6 14. Nxd6+ Bxd6 15. Qxd6 Qxb2 16. Bh4 Qc3+ 17. Rd2 Ng8 18. Ne2 Qa1+ 19. Rd1 Qb2 20. c3 g5 21. Bxg5 f6 22. Qe6+ Kf8 23. Bf4 Qb5 24. Bd6+ Kg7 25. Nf4 Qc6 26. Nh5+ Kg6 27. Qe8+ Kg5 28. Bf4+ Kh4 29. g3#
I lost every game lol. Pretty strong AI for beginners.
very nice
Very impressive, cool to see someone use Unity to make the classic chess AI problem!
I am the first one here?
no