thomasahle / sunfish

Sunfish: a Python Chess Engine in 111 lines of code
https://www.chessprogramming.org/Sunfish
Other
2.95k stars 543 forks source link

Simple wrapper class for sunfish #79

Closed WieeRd closed 3 years ago

WieeRd commented 3 years ago

First of all, thanks for your great work! I'm using sunfish for my LED chessboard project and it's working great.

But to me personally, sunfish's interface was quite confusing at first.
So I wrote simple & intuitive wrapper class that simplifies things.
ex) hist.append(hist[-1].move(move)) -> fish.push_san('a2a4')

I tried to resemble python-chess's behavior,
and (maybe) planning to (someday) add actual compatibility with it if you accept this pull request

thomasahle commented 3 years ago

Hi WieeRd, Have you considered just using the uci.py or xboard.py files with python-chess directly? That seems like the easiest way to get perfect python-chess like behavior.

WieeRd commented 3 years ago

If I'm not mistaken, those are interface for other chess softwares that communicate through stdin/stdout right?
What I wanted to do is to provide most intuitive way to use Sunfish inside other python codes.
Here, I rewrote main() and selfplay() from sunfish.py and test.py using sunfish_class.py.
I think it greatly simplifies usage of sunfish and makes the code much more readable.
Could be useful to other coders like me, who are trying to sunfish as a module inside their code.

thomasahle commented 3 years ago

I'm just saying, isn't it easier to just do:

>>> import chess, chess.engine
>>> engine = chess.engine.SimpleEngine.popen_uci(["/usr/bin/python3", "-u", "uci.py"]
>>> board = chess.Board()
>>> engine.play(board, chess.engine.Limit(time=0.1))
<PlayResult at 0x7f1035527100 (move=d2d4, ponder=d7d5, info={}, draw_offered=False, resigned=False)>

Then you get the full python-chess API

WieeRd commented 3 years ago

Oh wow I did not know that feature existed.
Looks very useful indeed.
Guess my code is now useless :(

thomasahle commented 3 years ago

Not useless, it's still a nice example for others to learn about chess programming :-)

Btw, the UCI.py script lacks a lot of features in order to be completely useful. If you would like to contribute improvements, that would be really appreciated!