This is very cool and having stalemate is nice, however how much space would it take to implement the full ruleset?<p>As you write: not implemented: castling, en passant, promotion, repetition, 50-move rule - those are all required to call the game being played modern chess.<p>I could see an argument for skipping repetition and 50-move rule for tiny engines, but you do need castling, en pessant and promotion for pretty much any serious play.<p><a href="https://en.wikipedia.org/wiki/Video_Chess" rel="nofollow">https://en.wikipedia.org/wiki/Video_Chess</a> fit in 4k and supported fuller ruleset in 1980 did it not?<p>So I would ask what is the smallest fully UCI (<a href="https://www.chessprogramming.org/UCI" rel="nofollow">https://www.chessprogramming.org/UCI</a>) compliant engine available currently?<p>This would be a fun goal to beat - make something tiny that supports full ruleset.<p>PS my first chess computer in early 1980s was this: <a href="https://www.ismenio.com/chess_fidelity_cc3.html" rel="nofollow">https://www.ismenio.com/chess_fidelity_cc3.html</a> - it also supported castling, en pessant, not sure about 50 move rule.
ToledoChess [0] has a few implementations of this in different languages. Some highlights:<p>2KB of JavaScript with castling, en passant, promotion, search and even a GUI<p>326 bytes of assembly, without the special rules<p>I don't think the author has a UCI-compliant one, but it should be easier than the GUI. There are forks of the JS one that might do it.<p>[0] <a href="https://nanochess.org/chess6.html" rel="nofollow">https://nanochess.org/chess6.html</a>
Cool project. You could also use the front-end of GNU chess to save some lines, and implement only a back-end.<p>Bug report:<p><pre><code> a b c d e f g h
8 r n b q k b n r 8
7 . . p p p p p p 7
6 . p . . . . . . 6
5 p . . . . . . . 5
4 P . . P P . . . 4
3 . . . . . . . . 3
2 . P P . . P P P 2
1 R N B Q K B N R 1
a b c d e f g h
move: b2b3
ai: b6b4
</code></pre>
The pawn is not permitted to move two fields after it has already beeen moved once before: b6b4 isn't a valid move after b7b6. (<i>First</i> moving two fields, and then one would have been okay, in contrast.)
Cool! I just recently implemented a chess engine in ~400 (readable) lines, with all rules, first in Java and then ported to my own programming language "Bau" [1]. This is including a terminal UI. I'll measure the ELO, but I was never able to beat it :-) The castling moves are specially tricky to implement I think. I enjoyed the challenge as well.<p>[1] <a href="https://github.com/thomasmueller/bau-lang/blob/main/src/test/resources/org/bau/converter/chess.bau" rel="nofollow">https://github.com/thomasmueller/bau-lang/blob/main/src/test...</a>
Do you think it would be possible to achieve 1:1 ELO:bytes? Even smaller, but can be less smart.
That's an awesome code golf challenge
maybe for very low ratings it's plausible?
1 elo per byte might happen in a tiny range
but at a useful strength it would break fast, that's what i think
What's the snallest possible program that accepts a chess board state and prints <i>any</i> legal move? True randomness may only have a couple hundred ELO, but then, that's pretty big for golf
If anyone is curious, the most common tool I've seen for ELO estimation among engine developers is cutechess [1], which uses SPRT [2]. Or ordo [3], haven't used this myself though<p>[1] <a href="https://cutechess.com/" rel="nofollow">https://cutechess.com/</a><p>[2] <a href="https://www.chessprogramming.org/Sequential_Probability_Ratio_Test" rel="nofollow">https://www.chessprogramming.org/Sequential_Probability_Rati...</a><p>[3] <a href="https://github.com/michiguel/Ordo" rel="nofollow">https://github.com/michiguel/Ordo</a>
<a href="https://www.chessprogramming.org/Toledo" rel="nofollow">https://www.chessprogramming.org/Toledo</a> is a family a moderately strong tiny chess programs.
How many games did you have to throw away because stockfish wanted to castle? Or did you force stockfish to not castle? Castling seems like such a frequent move it is hard to draw any conclusions about the strength of an engine that does not support it.
zero games were thrown away for castling, because i forced stockfish not to castle (and not to play en passant/promotion) by filtering legal moves and only giving those filtered moves via root_moves<p>so every game stayed in the same no castling variant<p>and you're right, this rating is for that constrained variant, not full chess.
Cool that you could keep it under 2k but it would nice to have a readable version of the source code.<p>Do you work with it like this or do you have some sort of script you apply to get it down to a single line, single letter variable names?
How did you handle games where Stockfish would castle or promote?
need to start measuring these things in the size of compiled functions so we can stop looking at oneliners (maybe wasm since it has an easy to read text representation)
If you ever spent much time at a chess club, you've seen why 2kB is a really disturbing number.
I wonder how big 1300, 1400, ..., 2200 Elo chess engines are.
This is amazing! Thanks for sharing. What would be the elo gain for 4KB engine?<p>P.S. I assume 1200 elo in chess com scale (not lichess / fide elo) and bullet chess variant?
Oh my god the source is so tiny! It's really hard to parse because of it being minified but I love it to bits.
Good job! I love how you obfuscated your code, really in a spirit of FOSS!
Oh well, the file initially looked like <a href="https://github.com/datavorous/sameshi/blob/7ab4e47144f96becdb5ad62c3f15e43f230ba381/tinychess.c" rel="nofollow">https://github.com/datavorous/sameshi/blob/7ab4e47144f96becd...</a><p>It is hideous now!
Coworker: “hey if you have a second, I have a one-liner PR open”<p>The PR:
The mailbox board representation is a good call for size-constrained engines. Bitboards give faster move generation but the manipulation code (shifts, masks, magic numbers for sliding pieces) eats a lot of bytes. With mailbox you just need offset tables and a sentinel check for board edges. Curious what your evaluation function looks like though. At 2KB you can't fit piece-square tables (that's 384 values minimum for both colors), so are you doing material-only eval or did you squeeze in some positional heuristics?<p>The gap between your 1200 Elo in 2KB and the TCEC 4K engines at ~3000 Elo is interesting. That extra 2KB buys a lot when it goes to better evaluation and move ordering. Even a simple captures-first sort in alpha-beta pruning costs only a few bytes of code but can roughly double your effective search depth.
[dead]
[dead]
Codex or Claude Code?
none.<p>scribbling long enough on a piece of paper is more enjoyable than prompting.
Isn't it bad enough they beat us at chess, do you have to make it even worse? ;p