I want to make this community aware of a python package I built that wraps the Stockfish engine in an easy-to-use Engine class.
Here's the link to the project site: https://pypi.python.org/pypi/pystockfish.
This is the only module in the Python package repository that seamlessly integrates a back-end engine. It fills a void allowing you to easily port the Stockfish engine into any other python-based chess application you may have. The package also includes a Match class to play two engines against each other.
I built it for research I'm doing into thinking depth and was directed by a member of the Stockfish community to your message board. I'm interested in any comments, criticism, and feedback from the Chess Programming community.
I'm available to answer any questions as I work on extending the documentation and the next iteration of the package. I hope you find it useful.
Sincerely,
Jarret
>>> from pystockfish import *
>>> deep = Engine(depth=20)
>>> deep.setposition(['e2e4'])
>>> deep.bestmove()
{'info': 'info depth 10 seldepth 13 score cp -40 nodes 33303 nps 951514 time 35 multipv 1 pv b8c6 g1f3 g8f6 b1c3 e7e5 f1b5 f8d6 e1g1 e8g8 d2d4 e5d4 f3d4 a7a6', 'ponder': 'g1f3', 'move': 'b8c6'}
>>> deep.setposition(['e2e4','e7e5'])
>>> deep.bestmove()
{'info': 'info depth 10 seldepth 2 score cp 40 nodes 4230 nps 1057500 time 4 multipv 1 pv g1f3 g8f6 b1c3 b8c6 f1b5 f8d6 e1g1 e8g8 d2d4 e5d4 f3d4 a7a6', 'ponder': 'g8f6', 'move': 'g1f3'}
>>> shallow = Engine(depth=10)
>>> match = Match(engines={'deep': deep, 'shallow':shallow})
>>> match.run()
'deep'
Python and Stockfish (pystockfish)
Moderators: hgm, Dann Corbit, Harvey Williamson
-
iamjarret
- Posts: 6
- Joined: Sun Dec 01, 2013 4:57 pm
- Location: New York
-
Daniel Shawul
- Posts: 4185
- Joined: Tue Mar 14, 2006 11:34 am
- Location: Ethiopia
Re: Python and Stockfish (pystockfish)
Isn't this a wrapper to a UCI interface, not just for stockfish? I guess that many people had written scripts to automate all sorts of testing, including Winboard engines as well. Btw your link has a 'dot' at the end that breaks it.
-
lucasart
- Posts: 3232
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: Python and Stockfish (pystockfish)
There is no 'void' to fill. The correct way to proceed is not to interface Stockfish in Python, but to write an UCI-compatible interface in Python.iamjarret wrote: It fills a void allowing you to easily port the Stockfish engine into any other python-based chess application you may have. The package also includes a Match class to play two engines against each other.
There is already PyChess, which is nice and pretty, although really amateurish programing, and not at all oriented towards engine vs engine play.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
-
iamjarret
- Posts: 6
- Joined: Sun Dec 01, 2013 4:57 pm
- Location: New York
Re: Python and Stockfish (pystockfish)
Thanks Daniel - here's the link again: https://pypi.python.org/pypi/pystockfish
-
flok
Re: Python and Stockfish (pystockfish)
Nice!
Usefull for little experiments and such.
I can see myself using this.
Usefull for little experiments and such.
I can see myself using this.
-
iamjarret
- Posts: 6
- Joined: Sun Dec 01, 2013 4:57 pm
- Location: New York
-
iamjarret
- Posts: 6
- Joined: Sun Dec 01, 2013 4:57 pm
- Location: New York
Re: Python and Stockfish (pystockfish)
Writing a UCI interface is solving a different problem; which is "how can I use all UCI chess engines in Python?" You'd end up building another XChess or Pychess and I wanted to build something light weight. The problem I'm solving is different; namely "how can I easily and transparently use the stockfish engine in python for engine vs. engine play?" And in that respect there is a void, even in your own words, Pychess is not designed for engine vs. engine play and it's not transparent.
-Jarret
-Jarret
-
iamjarret
- Posts: 6
- Joined: Sun Dec 01, 2013 4:57 pm
- Location: New York
Re: Python and Stockfish (pystockfish)
**RELEASE**
Pystockfish is a Python interface for the stockfish engine to run engine vs. engine matches, and version 1.0.1 is now compatible with Python 3!
PYPI:
https://pypi.python.org/pypi/pystockfish/1.0.1
GITHUB:
https://github.com/iamjarret/pystockfish/
Thanks everyone,
Jarret
Pystockfish is a Python interface for the stockfish engine to run engine vs. engine matches, and version 1.0.1 is now compatible with Python 3!
PYPI:
https://pypi.python.org/pypi/pystockfish/1.0.1
GITHUB:
https://github.com/iamjarret/pystockfish/
Thanks everyone,
Jarret
-
lucasart
- Posts: 3232
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: Python and Stockfish (pystockfish)
This could replace cutechess-cli, if you develop the match functionality a bit more (and allow for concurrency). Would be nice for fishtest, as cutechess-cli is a cumbersome depandancy (complicated to compile for Windows, requires tons of Qt stuff).iamjarret wrote:**RELEASE**
Pystockfish is a Python interface for the stockfish engine to run engine vs. engine matches, and version 1.0.1 is now compatible with Python 3!
PYPI:
https://pypi.python.org/pypi/pystockfish/1.0.1
GITHUB:
https://github.com/iamjarret/pystockfish/
Thanks everyone,
Jarret
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
-
JoshPettus
- Posts: 730
- Joined: Fri Oct 19, 2012 2:23 am
Re: Python and Stockfish (pystockfish)
In a game where every millisecond can count, wouldn't you want your interface between two engines to be fast as possible? Why would python be a good solution for this? I fully expect I have some misconceptions on the matter, so I'm curious. Why is this a better solution then say xboard which is in C?