
Stockfish – Strong Open-Source Chess Engine - mabynogy
https://stockfishchess.org/
======
xal
One aspect of chess that's really interesting is UCI which stands for univeral
chess interface. It's a simple protocol that all engines "speak" and almost
all pieces of chess software support. Chess players tend to collect engines
that are good at certain things and then use whatever UX they are most
comfortable with. At least in the past before Stockfish became so dominant.

The chess community in general is pretty technical. lichess.org is an absolute
marvel of a website. It's full of brilliance and it's all open source.
Interestingly it's computer analysis feature went through a notable
progressions of approaches:

First it was server sided stockfish. Later they compiled stockfish via
emscripten to .js so that analysis could run locally. This recently became
PNACL for speed and finally even more recently WebAssembly for portability.
Pretty cutting edge for the community of such an old game!

~~~
virtualwhys
Interesting, lichess server-side is written in Scala, but client is straight
js/jquery. I'd think they'd switch to Scala.js at some point, but if it works
as is maybe no need to change anything...

~~~
dyeje
I'd be surprised if they did use Scala.js. It's not even at 1.0 yet and I
imagine the ecosystem surrounding it is a tiny fraction of vanilla JS.

~~~
virtualwhys
Scala.js has been stable for quite some time (0.6 is effectively 1.0 but
author has been holding off on giving the 1.0 blessing). Ecosystem is indeed
tiny compared to vanilla JS, but aside from Typescript what alt-js project's
ecosystem isn't miniscule?

The value proposition of Scala.js, GHCJS, Bucklescript, etc. are static types,
2-way interop, and all the features of the host language representable in
javascript (which is incredible).

Lichess' approach works quite well, I have no issue with jQuery on the client
while doing the heavy lifting on the server; not everything needs to be a 20MB
SPA.

------
komaromy
Not just strong; it hasn't failed to place at least second in any TCEC season
(the de facto computer chess world championship) since 2013 [0].

[0]
[https://en.wikipedia.org/wiki/Top_Chess_Engine_Championship#...](https://en.wikipedia.org/wiki/Top_Chess_Engine_Championship#Tournament_results)

~~~
K_REY_C
The stalemate game referenced in the article is amazing. I've never seen it
before and it's incredible.

[http://www.chessgames.com/perl/chessgame?gid=1714659](http://www.chessgames.com/perl/chessgame?gid=1714659)

~~~
bfstein
I'm so confused by the endgame. Why did white move its queen to F4? How did
the last sequence of moves end in a stalemate?

~~~
dmurray
A stalemate [0] occurs when the side to move has no legal moves but is not in
check. Note that a stalemate is a special case of a draw: every stalemate is a
draw but not every draw is by stalemate. In the final position, if Black
captures the rook, it is stalemate. If he does not, White will keep giving
check on the seventh rank and the game will soon be a draw by repetition[1].

This game is particularly special because before 46. Bb3 White has six pieces,
all of which have legal moves, making stalemate apparently unlikely and
checkmate inevitable from Black's aggressively placed Queen and Knights. It's
surprising to a human that within a few moves, White is able to force Black to
capture or block all 6 of those pieces and give stalemate. There are famous
combinations from human play where one side manages to sacrifice "desperado"
pieces for stalemate [2][3], but nothing so ingenious as this one.

Specifically, Queen to f4 forces Black to both capture the Queen and block the
pawn on f3.

[0][https://en.m.wikipedia.org/wiki/Stalemate](https://en.m.wikipedia.org/wiki/Stalemate)
[1][https://en.m.wikipedia.org/wiki/Threefold_repetition](https://en.m.wikipedia.org/wiki/Threefold_repetition)
[2][http://www.chessgames.com/perl/chessgame?gid=1252040](http://www.chessgames.com/perl/chessgame?gid=1252040)
a famous example [3][https://chess-
db.com/public/game.jsp?id=4500512.14117908.508...](https://chess-
db.com/public/game.jsp?id=4500512.14117908.50842880.28874) a less well known
example I witnessed in person. An amateur woman shocks a top grandmaster.

~~~
barrkel
Bishop to b3 is forced - nothing else would stop Queen to d1 and checkmate.
Actually, most of the game plays itself beyond 42 or so. It's remarkable that
it got into that position, though.

------
billforsternz
For Windows computers Tarrasch Chess GUI
[http://www.triplehappy.com](http://www.triplehappy.com) is a very simple way
to experiment with Stockfish (it's installed as the default engine).
Disclosure: I am the author of the Tarrasch Chess GUI.

------
glinscott
Very cool to see Stockfish up here :). One of the cool parts is that the
testing framework is fully open as well, at
[http://tests.stockfishchess.org/tests](http://tests.stockfishchess.org/tests).
It's been pretty amazing to watch the progress of SF since it was put on
github by Marco and Joona.
[http://spcc.beepworld.de/](http://spcc.beepworld.de/) has some nice graphs.
Those graphs are in ELO scale as well, so a linear line is getting
exponentially stronger.

Currently for example, there 87 machines, contributing 341 cores of computing
power for testing patches. That's pretty awesome for completely volunteer
driven community!

------
posnet
Wow, it's only 8000 lines of code.

~~~
dfan
Pull requests are regularly rejected for increasing the size of the codebase,
even if they slightly improve the strength of the engine. It's hard to argue
with the results.

------
shpx
Someone organized a tournament of iterated prisoner's dilemma with access to
the opponent's source code. Can't seem to find examples of anyone trying this
with chess on google.

[http://lesswrong.com/lw/hmx/prisoners_dilemma_with_visible_s...](http://lesswrong.com/lw/hmx/prisoners_dilemma_with_visible_source_code/)

------
unicornporn
If you're on an Android, here's a great open-source client:

[https://f-droid.org/repository/browse/?fdfilter=droidfish&fd...](https://f-droid.org/repository/browse/?fdfilter=droidfish&fdid=org.petero.droidfish)

[https://play.google.com/store/apps/details?id=org.petero.dro...](https://play.google.com/store/apps/details?id=org.petero.droidfish)

------
atemerev
Wow, this is BY FAR the best C++ code I ever saw!

It should be a study in itself.

------
1ba9115454
Chess can be life changing. To get to any decent level you have to think how
your opponent will respond to your next move.

I found myself applying this to day to day life situations.

------
nojvek
Could some one explain how stock fish does its magic? What are the underlying
algos it's using to beat humans like a fly swat.

------
ch8230
Here's a very simple web client I wrote if you want to give Stockfish a whirl:
[https://chessui.com/](https://chessui.com/)

Shameless plug I know but I'm posting it for those who want to give it a shot
against stockfish.

------
Aron
So how are all the magical constants optimized?

~~~
lenocinor
I also want to know this.

~~~
xoroshiro
Most ideas are tested by an awesome framework. The basic idea is people donate
cpu time to test out different versions of stockfish. Truly in the spirit of
open source!
[http://tests.stockfishchess.org/tests](http://tests.stockfishchess.org/tests)

As for "magic numbers", parameters are done by automated tuning. Disclaimer:
I'm not an expert at this. There are too many parameters to attempt to
optimize everything globally, so it looks like only certain variables are
selected (this probably requires lots of domain knowledge) and optimized at a
time using something that resembles a gradient descent of sorts. You can read
more about it here:
[https://chessprogramming.wikispaces.com/Stockfish%27s+Tuning...](https://chessprogramming.wikispaces.com/Stockfish%27s+Tuning+Method)

There are also other tuning methods. notably, the one used by another chess
engine, Texel. Which is also interesting and used by several strong engines.
The chess programming wiki is a really good resource if you want to read more.

Finally,I can't find it, but I've read that Stockfish is so strong, that
Andscacs, another strong chess engine that participates in the TCEC, was tuned
by minimizing the standard deviation of its evaluation function with that of
Stockfish. That sort of blew my mind when I first read it.

~~~
Aron
Thanks for the links. Their optimization approach isn't particularly
sophisticated. Not saying I know how to do better, but wouldn't be surprised
if it existed.

------
mrcactu5
is this an effective tool for beginners?

~~~
TylerE
Depends on what you want?'

To play against...no. It will crush you like a cockroachh. it will crush a
grandmaster like a cockroach....running on a smartphone.

~~~
edko
Browsing the source code, I was not able to find an openings database. Is it
so strong in openings theory that it is able to compute it on the fly?

~~~
joeyrobert
UCI chess engines typically defer opening book to the GUI consuming it. So if
you were using Stockfish with Arena or Tarrasch, that would handle the opening
book. Stockfish will start calculating when it is out of the book. This is all
configurable, of course.

~~~
Philomath
I had no idea openings were so fixed from the computers point of view. Does
this mean that in order to become a better player it is a must to learn all
the openings as a book?

~~~
PikelEmi
Up to an ELO rating at 2000 (and even beyond that) there is no need to
memorize openings. It is much more important to learn the basic opening and
development ideas. Even if you play against non-masters who have memorized
some openings you can easily crunch them by the basic ideas. It takes master
level to go from memorize to actually understand how a given opening works.

~~~
TylerE
Really if your're good enough...

Magnus Carlsen spends very very little time on memorizing openings.

------
bambax
According to this page

[http://www.computerchess.org.uk/ccrl/404/](http://www.computerchess.org.uk/ccrl/404/)

Stockfish has the highest ELO of all engines... but how can an open-source
engine be best? How don't the other engines learn from it and become at least
as good, if not better?

