
Sunfish: A simple but strong chess engine written in Python - tosh
https://github.com/thomasahle/sunfish
======
nabla9
It would be fun to have 'demoscene' for chess engines and AI in general where
computers to play chess with very restricted resources.

What is the smallest computer with superhuman cababilities?

~~~
crawftv
With advancements in saved/pretrained models I think answer is or will be a
raspberry pi. I think a more interesting question is “what is the smallest
computer that can learn chess”

~~~
stackola
I'm sure there's a smaller computer than a raspberry pi that can beat any
human in chess.

~~~
tim333
The one that beat Kasparov in 1997 could evaluate 200 million positions per
second which is quite a lot. On the other hand beating me could probably be
done with a modified pocket calculator.

~~~
Recursing
There has been _a lot_ of progress in computer chess software since 1997, the
current version of Stockfish is very probably superhuman on a low-end
smartphone

I can't find any recent experiment, but here
[https://en.chessbase.com/post/komodo-8-the-smartphone-vs-
des...](https://en.chessbase.com/post/komodo-8-the-smartphone-vs-desktop-
challenge) is a test done in 2014 that shows that smartphones were already
clearly superhuman then

In 2019 I estimate we would need less than half of the computing power of that
2014 smartphone to achieve the same playing strength

------
Recursing
I just made a Rust port of it
[https://github.com/Recursing/sunfish_rs](https://github.com/Recursing/sunfish_rs)
if anybody's interested (would love some feedback)

You can play against it at
[https://lichess.org/@/sunfish_rs](https://lichess.org/@/sunfish_rs) and see
its strengths and weaknesses

------
darkpuma
What's the deal with naming chess engines after fish? I tried to look up
someplace to buy stockfish the other day and instead finding information about
dried fish I found a bunch of information about the chess engine.

~~~
nisuni
Stockfish was named that way because the two main authors are from Norway and
north-eastern Italy. Oddly enough, in both places stockfish is a typical dish.

------
abbadadda
The screen shot could use a little work. Looks like the dots and letters don't
line up with the pieces. Very cool though.

~~~
fred256
It's not an image. Just Unicode characters for the various pieces.

------
thom
This engine appears to have neither an interesting evaluation of positions,
nor any of the performance tweaks that make traditional engines powerful.
You're likely to learn more in an afternoon on
[https://www.chessprogramming.org](https://www.chessprogramming.org), but all
chess engines are beautiful in their own way, and I have certainly created
nothing better.

~~~
Recursing
It's not meant to be a competitive engine, after all, it's written in 111
lines of python.

I think it could be very useful for didactic purposes, or for getting started.
Not having all the extra complexities needed for efficient board
representation, position evaluation, move generation etc... makes the big
picture much clearer imvho

~~~
thom
Yeah, I totally agree that eval + search is the first step to learn, in terms
of overall structure. And this includes lots of important concepts like
quiescence search etc. I just think it's worth being honest: you either need
really good eval or really fast search just to give _yourself_ a good game.

~~~
Recursing
You are welcome to try to play my rust rewrite of this exact engine on lichess
[https://lichess.org/@/sunfish_rs](https://lichess.org/@/sunfish_rs)

If you're not a top 5% player, it can absolutely give you a good game
(especially on fast time controls)

~~~
thomasahle
That is cool! I've thought about making a rust version of Sunfish, and I
didn't even know this existed!

------
bradknowles
I’m curious how the code is sped up with pypy and why that helps?

What does pypy bring to this situation?

~~~
detaro
PyPy is a JIT-based interpreter for Python - code that loops a lot over
similar data structures is a natural candidate for being faster if jit-ed.

------
hestefisk
This is very cool. How does the chess engine work without some sort of AI?

~~~
tim333
It's debatable if this is AI but basically it looks at all the moves you can
make then all the responses an opponent can make and then what you can do back
etc. and attaches scores based on pieces taken and the positions. And then
goes with the best score.

Conventional chess programs use a similar algorithm and ones like AlphaZero
are similar except they use machine learning and neural nets to judge how good
positions are rather than a simple point score system.

I remember trying to write a similar one after seeing the algorithm explained
on the TV show Tomorrow's World, around 1980. (Here they are explaining the
cutting edge of mobile phones in the day
[https://www.youtube.com/watch?v=vix6TMnj9vY&feature=youtu.be...](https://www.youtube.com/watch?v=vix6TMnj9vY&feature=youtu.be&t=79))

~~~
jeanlucas
Just to add to your reply, alpha0 and Leela actually learn to play by playing
with itself, which is much more than just having a score for a given position.
Also, in the chess community, Stockfish is not seen as AI, but Leela and A0
are.

~~~
Scarblac
> Also, in the chess community, Stockfish is not seen as AI, but Leela and A0
> are.

That's a strange statement. For one, because chess players are hardly judges
of what is and what isn't AI.

Among chess programmers there may be such an opinion here and there, but
originally chess was a classical AI topic and alpha/beta search a classical AI
algorithm. As are neural networks and Monte Carlo tree search. So it's quite a
strange opinion, IMO.

~~~
dkarl
The classic definition of AI is a machine doing something that seems like it
should require human intelligence. Of course once it becomes commonplace for a
computer to do something, it no longer seems like it should require human
intelligence, so an equivalent definition is that what works consistently is
just programming and what seems like it should work but doesn't yet is AI.
Successful AI exists in the lag between getting something to work for the
first time and it being accepted as something that computers routinely do.

~~~
ska
roughly - "AI is what we call it when we don't really understand how it works,
yet."

~~~
chongli
I think we need to be ready to accept that some things we may never completely
understand because they're too complex. The human brain may be one of those
things, and AI may be another.

