Discuss Scratch
- Discussion Forums
- » Show and Tell
- » Scratch Chess Engine - Game of Kings
- ArnoHu
-
1000+ posts
Scratch Chess Engine - Game of Kings
https://lichess.org/8ZyEIzlx#6599% GoK NNUE (Medium) accuracy game against Element's (6+8) 90%:
Oh wow, White Dove (P3, black), up 7.3 against GoK NNUE (Medium), was still not enough (WD rejected the draw it had at hand, and then…)
https://lichess.org/qBghVWCf#163
I will now test some GoK NNUE (Difficult) games, because I expect a level-up there…
Having gotten a bit suspicious about the premature-draw-eval issue that @birdracerthree brought up, I replayed yesterdays opening against White Dove, this one here that GoK NNUE nearly lost, and boy, and I don't want to scare any one, but did that go differently now:
https://lichess.org/ZE0YGEyo#59
100% accuracy!
GoK NNUE (Medium, black) vs. White Dove (P3), 95% vs. 86% accuracy: https://lichess.org/cUoNMMCw#72
GoK NNUE (Medium, white) vs. Element (6+8), 92% vs. 81%. Element sometimes took more than two minutes https://lichess.org/l5vaV5xD#67
Last edited by ArnoHu (June 11, 2024 16:59:16)
- ArnoHu
-
1000+ posts
Scratch Chess Engine - Game of Kings
Cool, GoK NNUE had 10,000 visits in the last 24 hours. Users even found a timeout bug (on Scratch 3, that is).
- WhiteDoveOfficial
-
31 posts
Scratch Chess Engine - Game of Kings
Cool, GoK NNUE had 10,000 visits in the last 24 hours. Users even found a timeout bug (on Scratch 3, that is).
Cool stuff! Funnily enough, I saw someone in my class playing against GoK NNUE! (They were playing Easy 1 and lost…)
- ArnoHu
-
1000+ posts
Scratch Chess Engine - Game of Kings
Cool, GoK NNUE had 10,000 visits in the last 24 hours. Users even found a timeout bug (on Scratch 3, that is).
Cool stuff! Funnily enough, I saw someone in my class playing against GoK NNUE! (They were playing Easy 1 and lost…)
Nice, and best greetings, but shouldn't they be using White Dove?
Reason for timeout were quiescent check/evasion extensions on Scratch 3, that gets very costly with NNUE.
- ArnoHu
-
1000+ posts
Scratch Chess Engine - Game of Kings
GoK (Scratch 3, Difficult, white) wins against Bonsai Blue in a crazy game: https://lichess.org/nNJACJEr#75
- ababoin07
-
500+ posts
Scratch Chess Engine - Game of Kings
I’m sorry but the AI training has been corrupted, as well as the database I had created, so program change: I will program a minimax with a basic evaluation (as well as AB pruning, delta pruning, transposition tables, as well as quiescence research…), then as soon as I can start training AI again, I will replace the evaluation of my project by this network (I don’t have time to re-train him until Friday because I have the database to redo as well as the training that lasted more or less than 50 hours, and from Saturday I would have a school internship of two weeks and then a scout camp of three weeks, so I wouldn’t have time to do the NN for a month and a half…)
- ArnoHu
-
1000+ posts
Scratch Chess Engine - Game of Kings
Cool, GoK NNUE had 10,000 visits in the last 24 hours. Users even found a timeout bug (on Scratch 3, that is).
OK, now we made it also to the “What the Community is Loving” section.
- AZURUS41
-
100+ posts
Scratch Chess Engine - Game of Kings
Running on a silicon CPU, GoK Chess NNUE also likes the silicon defense!
ArnoHu, 2024.
Apart from this, and excluding the long awaited NNUE program who beat GoK classic ( Einhorn or idk the name I forgot ), which are the best 5 engines at maximum level on scratch 3 ?
ArnoHu, 2024.
Apart from this, and excluding the long awaited NNUE program who beat GoK classic ( Einhorn or idk the name I forgot ), which are the best 5 engines at maximum level on scratch 3 ?
- MoosenMooALot
-
62 posts
Scratch Chess Engine - Game of Kings
Congrats to GoK Classic for this win against Komodo22 (2600)! Last time I matched these two engines, GoK barely won on competition mode (and, granted, that was over a year ago), but this time, GoK, merely on TW Difficult, scored a convincing win despite the slowness of my device:
https://lichess.org/80gGE2YV
https://lichess.org/80gGE2YV
- ababoin07
-
500+ posts
Scratch Chess Engine - Game of Kings
I found the training data!!!! I will make a huge network, and the ia will go to a depth of 3, to see how it deals with other AI (20k nodes per minute on turbowarp…)
- ScratchChessChampion
-
100+ posts
Scratch Chess Engine - Game of Kings
Hello, I recently received a new chess engine project from a Scratch user. Can you all help me review and check if it is genuine and original? Thanks!
Here's the link: https://scratch.mit.edu/users/ExpiredBoy/
Here's the link: https://scratch.mit.edu/users/ExpiredBoy/
- S_P_A_R_T
-
500+ posts
Scratch Chess Engine - Game of Kings
Hello, I recently received a new chess engine project from a Scratch user. Can you all help me review and check if it is genuine and original? Thanks!
Here's the link: https://scratch.mit.edu/users/ExpiredBoy/
It's not a WD or GoK clone, as it's code is way to small

- HasiLover_Test
-
100+ posts
Scratch Chess Engine - Game of Kings
looks legitimate Hello, I recently received a new chess engine project from a Scratch user. Can you all help me review and check if it is genuine and original? Thanks!
Here's the link: https://scratch.mit.edu/users/ExpiredBoy/
- birdracerthree
-
1000+ posts
Scratch Chess Engine - Game of Kings
I agree. The code is less than 3k blocks, very few (if any) engines are that compact. The code appears to original, and there are comments explaining some of the code.looks legitimate Hello, I recently received a new chess engine project from a Scratch user. Can you all help me review and check if it is genuine and original? Thanks!
Here's the link: https://scratch.mit.edu/users/ExpiredBoy/
- ababoin07
-
500+ posts
Scratch Chess Engine - Game of Kings
I also agree, the code is nothing like the other engines I know, however, the fact that the engine contains less than 3k blocks is also quite impressive but as it is in its infancy, it is quite normal.looks legitimate Hello, I recently received a new chess engine project from a Scratch user. Can you all help me review and check if it is genuine and original? Thanks!
Here's the link: https://scratch.mit.edu/users/ExpiredBoy/
- ArnoHu
-
1000+ posts
Scratch Chess Engine - Game of Kings
I also agree, the code is nothing like the other engines I know, however, the fact that the engine contains less than 3k blocks is also quite impressive but as it is in its infancy, it is quite normal.looks legitimate Hello, I recently received a new chess engine project from a Scratch user. Can you all help me review and check if it is genuine and original? Thanks!
Here's the link: https://scratch.mit.edu/users/ExpiredBoy/
Looks genuine in code and behavior.
- birdracerthree
-
1000+ posts
Scratch Chess Engine - Game of Kings
Element v0.3's 9847 blocks : *nervous shaking*I also agree, the code is nothing like the other engines I know, however, the fact that the engine contains less than 3k blocks is also quite impressive but as it is in its infancy, it is quite normal.looks legitimate Hello, I recently received a new chess engine project from a Scratch user. Can you all help me review and check if it is genuine and original? Thanks!
Here's the link: https://scratch.mit.edu/users/ExpiredBoy/
The 1500 block move generation is not helping lol
- WhiteDoveOfficial
-
31 posts
Scratch Chess Engine - Game of Kings
Element v0.3's 9847 blocks : *nervous shaking*I also agree, the code is nothing like the other engines I know, however, the fact that the engine contains less than 3k blocks is also quite impressive but as it is in its infancy, it is quite normal.looks legitimate Hello, I recently received a new chess engine project from a Scratch user. Can you all help me review and check if it is genuine and original? Thanks!
Here's the link: https://scratch.mit.edu/users/ExpiredBoy/
The 1500 block move generation is not helping lol
9.8k blocks for a version that early?
- ArnoHu
-
1000+ posts
Scratch Chess Engine - Game of Kings
The Story of GoK Chess Neural Network
I had not really considered neural networks feasible for Scratch / TurboWarp chess projects until lately, not even when Efficiently Updateable Neural Networks (NNUEs) took over native chess engines by storm in recent years. NNUEs are much faster, better suited for frequent updates, and smaller than early chess NNs, e.g. as in Leela Chess Zero. NNUEs are typically applied for board evaluation, and most engines kept their previous search logic (Negamax, A/B-pruning) in place. But NNUEs were still too big, too slow for Scratch, at least in my opinion back then. When I checked NNUEs the last time, their typical size was in the single- to double-digit MBs.
End of May 2024, FastSkript posted a test game of his yet unpublished Delta chess engine in this forum, which applied a NNUE for the first time. He proved that Chess NNUE was possible on Scratch. So I stopped doubting, and decided to simply try it out.
This time I encountered Smallbrain at https://github.com/Disservin/Smallbrain - a UCI C++chess engine (GPL-license). Its NN data was more than 3MB binary, but only since it had introduced buckets for king areas. Before that it was just at 700k binary. Smallbrain's C++ NNUE code was slick and easily readable / portable. It looked good!
Quick note on Smallbrain's neural network neuron layer design:
768 => 512 => 1
Featuerset (input) size is 768 (for 12 piece types x 64 squares), the hidden layer has 512 neurons. NN has “viewpoints” for black and white. For every single move applied or reverted, 2,048 accumulator items must updated (more on captures, promotions, castling). for evaluation, 1,024 weights and accumulator items are combined. That is still quite workload esp. on the Scratch runtime, which has high overhead for every Scratch block that is being executed. The one output is the evaluation of the board from the viewpoint of one side, namely the one whose turn it is to move.
I was in London at the time, and did some prep work by creating a concept for Scratch implementation and integration, getting acquainted with the Smallbrain codebase and implementing a little NN data migration tool in C++. No Scratch coding, as I only had an old Surface tablet at hand.
Back at home I went to work immediately. I forked GoK Classic and had a running NNUE prototype done later that day. Unfortunately it made several weird moves. I hunted down the underlying bug for some hours the next evening, until I had the C++ and Scratch NN implementation running side-by-side on the same samples, and I could identify the culprit: a off-by-1 bug in adapter code, converting GoK data to Smallbrain NNUE schema.
Then I went to performance tuning. The innermost NNUE code is all about reading, manipulating and writing numeric data stored in an array / Scratch list, so pretty much a standard case for optimization.
Finally I had to compress the 700k binary NN model data into a Scratch project JSON with its 5MB uncompressed JSON limit. The classic GoK version was already reaching that limit, but I could remove all previous evaluation code, and by using fixed-3b-hexadecimal chunks, which are also fast to decode, it was possible to compress everything just within that 5MB limit. That was the last missing building block, which was finished on the third evening.
Gok NNUE played well, esp. on TurboWarp ( https://turbowarp.org/1033379869 ). On the Scratch 3 runtime, it was able to deliver a decent game, which was hard to believe for me, knowing what goes on under the hood on each move applied / reverted, and each evaluation (thousands of list reads and writes). Not surprisingly, GoK Classic still plays better on Scratch 3 than GoK NNUE.
You can inspect GoK NNUE code in text form at:
https://github.com/ArnoHue/scratch/blob/7479f4b56c15d3458ac47b7207c580ee3ec32db7/chess/EngineNNUE.scratch#L6937 (lines 6937 to 7337)
The NNUE model data looks like this:
https://github.com/ArnoHue/scratch/blob/7479f4b56c15d3458ac47b7207c580ee3ec32db7/chess/NNUE.scratch
GoK NNUE then won its first games against GoK classic, its main competitors and against Stockfish 16 level 7 (vs. Stockfish: https://lichess.org/ntM1vGZE#209 ). It attracted 70,000 visitors during its first 2 weeks on Scratch.
It also has weaknesses for sure, esp. when it does not reach sufficient search depth (TurboWarp and a fast system are highly recommended), and sometimes loses due to that. Search depth is 3.5 plies less compared to GoK Classic. Still, the newly gained creativity and strategic thinking alone is a joy to watch IMHO.
I hope you enjoy playing against GoK NNUE just as much!
A big thank you goes to the Smallbrain project creators and contributors - without their great work in designing and training the network, GoK NNUE would not have been possible!
Update 18/06/2024:
I spent the last week performance-tuning NNUE logic and GoK/NNUE adapter code (lazy and optimized NNUE updates), and achieved a 300% speedup. With sufficient search depth on Difficult and a fast system, GoK NNUE now typically wins against GoK Classic on the Scratch runtime, as well as on TurboWarp against the strongest TurboWarp-optimized engines. GoK NNUE's average search depth distance to GoK Classic was reduced from 3.5 plies to 1.5 plies.
Addendum:
The Story of GoK Classic can be found here: https://scratch.mit.edu/discuss/post/2967632/
Update 06/07/2024:
Further optimizations and other improvements,. lichess.org study with games against strong Scratch chess engines:
https://lichess.org/study/Z5N8Io1T/
I had not really considered neural networks feasible for Scratch / TurboWarp chess projects until lately, not even when Efficiently Updateable Neural Networks (NNUEs) took over native chess engines by storm in recent years. NNUEs are much faster, better suited for frequent updates, and smaller than early chess NNs, e.g. as in Leela Chess Zero. NNUEs are typically applied for board evaluation, and most engines kept their previous search logic (Negamax, A/B-pruning) in place. But NNUEs were still too big, too slow for Scratch, at least in my opinion back then. When I checked NNUEs the last time, their typical size was in the single- to double-digit MBs.
End of May 2024, FastSkript posted a test game of his yet unpublished Delta chess engine in this forum, which applied a NNUE for the first time. He proved that Chess NNUE was possible on Scratch. So I stopped doubting, and decided to simply try it out.
This time I encountered Smallbrain at https://github.com/Disservin/Smallbrain - a UCI C++chess engine (GPL-license). Its NN data was more than 3MB binary, but only since it had introduced buckets for king areas. Before that it was just at 700k binary. Smallbrain's C++ NNUE code was slick and easily readable / portable. It looked good!
Quick note on Smallbrain's neural network neuron layer design:
768 => 512 => 1
Featuerset (input) size is 768 (for 12 piece types x 64 squares), the hidden layer has 512 neurons. NN has “viewpoints” for black and white. For every single move applied or reverted, 2,048 accumulator items must updated (more on captures, promotions, castling). for evaluation, 1,024 weights and accumulator items are combined. That is still quite workload esp. on the Scratch runtime, which has high overhead for every Scratch block that is being executed. The one output is the evaluation of the board from the viewpoint of one side, namely the one whose turn it is to move.
I was in London at the time, and did some prep work by creating a concept for Scratch implementation and integration, getting acquainted with the Smallbrain codebase and implementing a little NN data migration tool in C++. No Scratch coding, as I only had an old Surface tablet at hand.
Back at home I went to work immediately. I forked GoK Classic and had a running NNUE prototype done later that day. Unfortunately it made several weird moves. I hunted down the underlying bug for some hours the next evening, until I had the C++ and Scratch NN implementation running side-by-side on the same samples, and I could identify the culprit: a off-by-1 bug in adapter code, converting GoK data to Smallbrain NNUE schema.
Then I went to performance tuning. The innermost NNUE code is all about reading, manipulating and writing numeric data stored in an array / Scratch list, so pretty much a standard case for optimization.
Finally I had to compress the 700k binary NN model data into a Scratch project JSON with its 5MB uncompressed JSON limit. The classic GoK version was already reaching that limit, but I could remove all previous evaluation code, and by using fixed-3b-hexadecimal chunks, which are also fast to decode, it was possible to compress everything just within that 5MB limit. That was the last missing building block, which was finished on the third evening.
Gok NNUE played well, esp. on TurboWarp ( https://turbowarp.org/1033379869 ). On the Scratch 3 runtime, it was able to deliver a decent game, which was hard to believe for me, knowing what goes on under the hood on each move applied / reverted, and each evaluation (thousands of list reads and writes). Not surprisingly, GoK Classic still plays better on Scratch 3 than GoK NNUE.
You can inspect GoK NNUE code in text form at:
https://github.com/ArnoHue/scratch/blob/7479f4b56c15d3458ac47b7207c580ee3ec32db7/chess/EngineNNUE.scratch#L6937 (lines 6937 to 7337)
The NNUE model data looks like this:
https://github.com/ArnoHue/scratch/blob/7479f4b56c15d3458ac47b7207c580ee3ec32db7/chess/NNUE.scratch
GoK NNUE then won its first games against GoK classic, its main competitors and against Stockfish 16 level 7 (vs. Stockfish: https://lichess.org/ntM1vGZE#209 ). It attracted 70,000 visitors during its first 2 weeks on Scratch.
It also has weaknesses for sure, esp. when it does not reach sufficient search depth (TurboWarp and a fast system are highly recommended), and sometimes loses due to that. Search depth is 3.5 plies less compared to GoK Classic. Still, the newly gained creativity and strategic thinking alone is a joy to watch IMHO.
I hope you enjoy playing against GoK NNUE just as much!
A big thank you goes to the Smallbrain project creators and contributors - without their great work in designing and training the network, GoK NNUE would not have been possible!
Update 18/06/2024:
I spent the last week performance-tuning NNUE logic and GoK/NNUE adapter code (lazy and optimized NNUE updates), and achieved a 300% speedup. With sufficient search depth on Difficult and a fast system, GoK NNUE now typically wins against GoK Classic on the Scratch runtime, as well as on TurboWarp against the strongest TurboWarp-optimized engines. GoK NNUE's average search depth distance to GoK Classic was reduced from 3.5 plies to 1.5 plies.
Addendum:
The Story of GoK Classic can be found here: https://scratch.mit.edu/discuss/post/2967632/
Update 06/07/2024:
Further optimizations and other improvements,. lichess.org study with games against strong Scratch chess engines:
https://lichess.org/study/Z5N8Io1T/
Last edited by ArnoHu (April 19, 2025 05:39:09)
- ArnoHu
-
1000+ posts
Scratch Chess Engine - Game of Kings
I wrote “The Story of GoK NNUE” for future reference, because I have received a lot of questions already.
Last edited by ArnoHu (July 18, 2024 15:47:15)