logoalt Hacker News

Show HN: Sameshi – a ~1200 Elo chess engine that fits within 2KB

80 pointsby datavorous_today at 1:47 PM33 commentsview on HN

I made a chess engine today, and made it fit within 2KB. I used a variant of MinMax called Negamax, with alpha beta pruning. For the board representation I have used a 120-cell "mailbox". I managed to squeeze in checkmate/stalemate in there, after trimming out some edge cases.

I am a great fan of demoscene (computer art subculture) since middle school, and hence it was a ritual i had to perform.

For estimating the Elo, I measured 240 automated games against Stockfish Elo levels (1320 to 1600) under fixed depth-5 and some constrained rules, using equal color distribution.

Then converted pooled win/draw/loss scores to Elo through some standard logistic formula with binomial 95% confidence interval.


Comments

sireattoday at 4:31 PM

This is very cool and having stalemate is nice, however how much space would it take to implement the full ruleset?

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.

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.

https://en.wikipedia.org/wiki/Video_Chess fit in 4k and supported fuller ruleset in 1980 did it not?

So I would ask what is the smallest fully UCI (https://www.chessprogramming.org/UCI) compliant engine available currently?

This would be a fun goal to beat - make something tiny that supports full ruleset.

PS my first chess computer in early 1980s was this: https://www.ismenio.com/chess_fidelity_cc3.html - it also supported castling, en pessant, not sure about 50 move rule.

l674today at 4:36 PM

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

[1] https://cutechess.com/

[2] https://www.chessprogramming.org/Sequential_Probability_Rati...

[3] https://github.com/michiguel/Ordo

dfctoday at 4:21 PM

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.

jll29today at 4:14 PM

Cool project. You could also use the front-end of GNU chess to save some lines, and implement only a back-end.

Bug report:

    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
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. (First moving two fields, and then one would have been okay, in contrast.)
show 1 reply
tromptoday at 4:00 PM

https://www.chessprogramming.org/Toledo is a family a moderately strong tiny chess programs.

lekeviciustoday at 2:39 PM

Do you think it would be possible to achieve 1:1 ELO:bytes? Even smaller, but can be less smart.

show 2 replies
oh_my_goodnesstoday at 4:24 PM

If you ever spent much time at a chess club, you've seen why 2kB is a really disturbing number.

chvidtoday at 2:12 PM

Cool that you could keep it under 2k but it would nice to have a readable version of the source code.

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?

show 2 replies
GeertBtoday at 2:35 PM

How did you handle games where Stockfish would castle or promote?

show 1 reply
haute_cuisinetoday at 3:08 PM

This is amazing! Thanks for sharing. What would be the elo gain for 4KB engine?

P.S. I assume 1200 elo in chess com scale (not lichess / fide elo) and bullet chess variant?

show 1 reply
falsaberN1today at 3:24 PM

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.

burstw0wtoday at 3:30 PM

Good job! I love how you obfuscated your code, really in a spirit of FOSS!

show 2 replies
TZubiritoday at 2:53 PM

Codex or Claude Code?

show 1 reply
newzinotoday at 3:48 PM

[dead]

genie3iotoday at 3:00 PM

[dead]