
Chess AI
by ArnoHu
Description
Most recent game - "Connect 4": https://scratch.mit.edu/projects/1114744709 Plays a lot better on: https://turbowarp.org/148769358 GoK Chess Classic version: https://scratch.mit.edu/projects/828094886/ GoK Online Chess (remote players, public viewing): https://scratch.mit.edu/projects/209130998/ Win over Stockfish 16 level 8: https://scratch.mit.edu/discuss/post/8134928/ How this project was done: (1) https://scratch.mit.edu/discuss/post/2967632/ (2) https://scratch.mit.edu/discuss/post/8014663/ Forum: https://scratch.mit.edu/discuss/topic/248984/ Thanks a lot to the Smallbrain Chess project for NNUE model data. GoK Chess NNUE would not have been possible without their work. Smallbrain can be found at: https://github.com/Disservin/Smallbrain/ Opening Book by @Grijfland (thanks a ton, that was a lot of work!) AI Bot image licensed via shutterstock.com Piece sprite SVGs licensed via shutterstock.com Graphics from external sources all labeled free for non-commercial use. See links below. Board image: https://upload.wikimedia.org/wikipedia/commons/5/5b/Chess-niemann.PNG Intro screen image: https://pixabay.com/p-316657/ Sound Effects: http://www.fromtexttospeech.com/ https://freesound.org/ Original quicksort implementation (had to fix one bug to keep local stack state): https://scratch.mit.edu/projects/41440388/ Piece square table definitions: https://www.chessprogramming.net/using-excel-to-help-create-piece-square-tables/
Instructions
Welcome to "Scratch Chess AI - Game of Kings". FAQs: - "There is a bug!" Unlikely, 820k visitors, no known issues. Consult experienced player, read instructions. - "Why invalid move?" Likely keeps / puts you in check. - "I still found a bug!" Please describe in detail, and click "Export", then copy & paste FEN (board) or PGN (moves) data into a comment. - "How to move?" Click piece, then click target square. - "Too difficult!" Switch to level Easy 1 or 2, at which the engine makes semi-random moves. - "Too easy!" Play level Difficult on TurboWarp (a Scratch runtime 50x faster than Scratch 3): https://turbowarp.org/148769358 or https://turbowarp.org/1033757275 If you win against level Difficult, please copy/paste PGN data for analysis (click "Export"). Scratch is not well suited for CPU-intense calculations (interpreted, missing language features like bitwise operations, slow by design), that is why a Scratch chess engine will always have limited playing strength. TurboWarp is faster, but still has to emulate Scratch, hence has to impose similar restrictions. - "Too slow" On slow systems it is recommended to select a lower playing level. The engine is think time bound, and takes exactly as long as designed (15 sec (Medium) resp. 25 sec midgame / 15 or 10 sec endgame (Difficult), or up to 50% longer, when minimum search depth not finished). On Easy and Blitz levels, response time is 0 to 4 seconds. Scratch is inherently slow due to its design and interpreted nature. On TurboWarp level Blitz 2 plays better than level Difficult on Scratch 3, at 4 seconds think time. - "How to castle?" Move the king two squares towards the rook; king must not be in check, none of the passed squares must be attacked, and neither king nor rook must have moved before. - "Board is set up incorrectly" Maybe you mixed up king and queen. - "King and queen move the wrong way" Maybe you mixed up king and queen? - "King and rook moved at the same time" That's called 'castling', and is a valid move. - "Opponent pawn captured my pawn which had already passed it by moving two squares before!" That's called 'en-passant', and is a valid move. - "Why is it a draw when the engine mainly has its king left and I still have pieces?". Most likely draw by stalemate (no legal move but also not checked) - "How do I copy FEN or PGN data?" Click "Export", triple-click FEN or PGN data, press Ctrl-C (Windows) or right-click / select "Copy". - "How to play en-passant?" Move your pawn diagonally by one square, behind the opponent pawn which just moved two squares. - "What does the black/white bar on the right side of the board indicate?" It shows the current evaluation of the board, so either black's or white's lead in the game. - "Can you increase the engine's playing strength?" It has been tuned a lot already, and we probably reached the end of the rope now. A Scratch chess engine will never play at the level of one implemented in C/C++, Java or JavaScript. Scratch is slow due its interpreted nature, every variable access triggers a table-lookup by name, it doesn't have bitwise operations for bitboards, and uses variants with constant value conversions, etc. Difficulty levels: - Easy 1: searches 1 ply, makes many deliberate mistakes - Easy 2: searches 1 ply, makes some deliberate mistakes - Blitz 1: searches 2 plies (4 on TurboWarp) plus subsequent captures / checks - Blitz 2: searches 3 to 4 plies (8 on TurboWarp) plus subsequent captures / checks - Medium: think time 15 seconds for midgame, 10 seconds for endgame (or ply 3 reached); searches ca. 3 plies plus all subsequent capture (+ check) sequences during midgame, more checks during endgame - Difficult: think time 25 seconds for midgame, 15 seconds for endgame (or ply 4 reached); searches ca. 4 plies plus all subsequent capture (+ check) sequences during midgame, more checks during endgame. FIDE ELO rating ca. 1750 on Scratch 3, ca. 2500 on TurboWarp and a fast system. - Difficult (competition mode, press 'c'): think time 90 seconds; searches ca. 5 plies plus all subsequent capture (some check) sequences during midgame, more checks during endgame The fast TurboWarp runtime will add ca. 4 plies on Medium and Difficult, and doubles the plies on Blitz 1+2. Press 'c' to toggle 60 seconds think time on Difficult Press 'd' for debugging info (evaluation, search depth, NPS, MPS) Press 'p' for profiler mode (Stats, time spent per function and search depth, number of transposition table hits) Press 't' to set transposition table cache size BUG REPORTS: Please describe exactly what happened, and provide exported board data: Click "Export", then look for the FEN data, select the text by triple-clicking it, copy it to the clipboard and paste it to the bug comment. Alternatively you can also export the move list in PGN format. Before you post a bug, go sure it really is a bug and not a misunderstanding, e.g. you may want to consult an experienced chess player beforehand.
Project Details
- Visibility
- Visible
- Comments
- Enabled
More Cool Projects

Nano Ruins the Vacation in Australia
by 610267006

ρʅαƚϝσɾɱҽɾ Lst's go! pooh0105×contrᴏller-55
by pooh0105

Friday Night Funkin' Vs. Whitty | Defenitive Edition
by CharizardAaroshdude

Beat up Tera!
by scratchcatsonic

キャットのバイクレース Cat Bike Racing
by praplane

Sneak Peek Playable - GD2.2 Scratch Editor
by duckyALT

Windows Longhorn Build 4074 Crazy Error Maker remix
by Naka4545

にゃんこ大戦争Vr.8
by nyankodaisensouAHAHA

The escape || 脱出ゲーム
by Echo_magic

Wave Multi-Emulator 8X - V0.8.7
by oxiti8

Rede Globo Yoshi's Island Saindo-do-ar (1979-1985)
by Mariofans1981

i2p - Pen image renderer
by agcoder66

スプラトゥーン サーモンラン splatoon salmon run
by abescreame

おにごっこ~Nightmare 13th~第伍拾弐話「神vs神」
by tyomuko22

Cuphead Scratch Boss (Finished)
by LoganTheCartoonist

タワーディフェンス ver1.27 Tower defense ver1.27
by hayate_1121

クレーンゲーム (100%Pen)
by Keiji710

JDScratchified Beta: D.A.N.C.E. (Justice)
by everone123

Beat up handy manny (But Super Why Replaces You)
by LiamPenPal026

日本語版Among Us Scratch remake harumakinngu (リミックス)
by harumakinngu

Flappy Helicopter V3
by getnatpavee2

FNF - (VsSketchy) (Remastered)
by Bradk2005

FNF vs Kapi | Arcade Showdown (OLD)
by chucky_lee

Just Shapes And Beats : Barracuda BETA
by TheConstructer