Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Stockfish – Strong Open-Source Chess Engine (stockfishchess.org)
198 points by mabynogy on March 26, 2017 | hide | past | favorite | 50 comments


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!


It's a community that knows low level CS/AI well. The chess programming wiki [1] is quite the knowledge hole for everything from bit twiddling hacks to obscure search algorithms.

[1] https://chessprogramming.wikispaces.com


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...


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.


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.


Wow, WebAssembly! I knew that Stockfish was really technical, and I spent some time looking at its source. But I did not know (even though I used to regularly use it) that lichess was also open source and that the chess community was also bleeding edge.


UCI is undocumented for the most part... Or was that the ICS protocol? No clue, it's been a while. Everyone learns it by taking to other people.



It was ICS, not UCI, oops.


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#...


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


For anyone else out there who may be a chess imbecile like myself... it took me a while to figure out why black king doesn't take white rook:

It's because if they do, white has no legal moves, but king isn't in check. This condition, where a player can't move, but the king currently isn't in check, results in a stalemate (which is considered a draw).

Therefore, white's baiting of black into that position by sacrificing pieces is interesting.


Thank you, I'm also a chess imbecile and was mystified.


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?


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


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.


(Have barely played chess since I was a kid, but guessing below until you get a better/accurate answer.)

White was in trouble before throwing away the bishop as the black queen was in a deadly position, so it looked to get any free pieces it had blocked from moving as a viable strategy at aiming for a draw.

As for the stalemate, I assume the 50-move rule, part (a)? It was either going to draw through losing the rook or via 50 moves without losing/taking a piece.

"The game is drawn, upon a correct claim by the player having the move, if (a) he writes on his scoresheet, and declares to the arbiter his intention to make a move which shall result in the last 50 moves having been made by each player without the movement of any pawn and without the capture of any piece, or [snipped]"

https://en.wikipedia.org/wiki/Fifty-move_rule


No, three-fold repetition would happen long before fifty moves transpired. That's the normal conclusion of perpetual check.

https://en.wikipedia.org/wiki/Perpetual_check


The White move to f4 put the Black king in check; if White hadn't put the Black king in check, Black would have checkmated with Queen to a1.


For Windows computers Tarrasch Chess GUI 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.


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. 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/ 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!


Wow, it's only 8000 lines of code.


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.


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...



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

It should be a study in itself.


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.


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.


Here's a very simple web client I wrote if you want to give Stockfish a whirl: https://chessui.com/

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


So how are all the magical constants optimized?


I also want to know this.


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

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...

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.


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.


is this an effective tool for beginners?


I will say no.

It's tough - maybe impossible - for engines to really accurately simulate lower level play. You usually get one of two outcomes : A) an opponent who plays 10 moves like God and then drops a rook out of thin air or B) essentially random moves.

Beginners have little use or value from the deep analysis engines can provide as well. Once they're stronger then they benefit more but until then it's just an opponent who stomps you every game and you can't even understand it when it tries to tell you why.

The most effective tools for beginning players will be playing other players (online or OTB) who are around the same level or slightly stronger and daily tactics training via tactical puzzles see: http://chesstempo.com, http://chess24.com and a host of others.

As well, the St. Louis Chess Club has a ton of great videos with GMs Seirawan, Finegold, Akobian, and others, starting at the beginner range and going up. I think beginners can get a lot of value out of their lectures.

https://www.youtube.com/user/STLChessClub


Stockfish is fantastic for analyzing your games to find where to improve. Don't use it until you've gone over the game first, though. You want to develop your own ability to recognize mistakes and then use the engine to check your work.

It's just like using a calculator while learning math: do the work first and then check for mistakes with the calculator.


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.


You can set the skill level. As a complete chess novice, I can do okay at very low difficulty. A level or two above the minimum and it completely wrecks me though.

For anyone interested in playing with it yourself, you can use python-chess (https://pypi.python.org/pypi/python-chess) to set up / play against the engine (or make engines play against each other) without having to directly use the UCI commands.

edit: It looks like there are quite a few other front-ends that will work with Stockfish. Fritz and PyChess look popular. I just used python-chess for a project a while ago.


With a lower skill level it plays weird, almost useless to learn from compared to playing other humans.


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?


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.


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?


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.


Really if your're good enough...

Magnus Carlsen spends very very little time on memorizing openings.


Even in professional chess, openings are almost "by the book". There are quite a few main lines of openings and play is almost always along one of them, or variants thereof.


There's a variant of Stockfish called "Brainfish" that has a way of incorporating information about the opening. More info here https://chessprogramming.wikispaces.com/Brainfish and here http://spcc.beepworld.de/ (ratings)


Yes


Yes.

Get PCID vs SCID and have it analyze your games. Generally speaking, beginners make obvious mistakes, and Stockfish will automatically find those mistakes you make.

Every now and then, you miss an obscure "Checkmate in 12-moves" that Stockfish will see... just ignore those that are too difficult for you to visualize yourself. Otherwise, its excellent to have a 3300+ Elo player double-checking your moves after each game.


There are substantial differences in how people and computers play chess, at least with current algorithms (stockfish included.) If you want to learn to play chess against people, computer opponents can help in your training, over-the-board games are an absolute must as well.


According to this page

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?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: