r/ComputerChess • u/Uspecd • Nov 11 '25
How to run a python chess.engine.Protocol ?
Hello 😀 Nice to meet youall
I’m new to chess programming and I’ve been experimenting with building engines to play against each other. I want to restart more properly, so I tried creating a random UCI engine using the `python-chess` library.
I’ve implemented a RandomProtocol(chess.engine.Protocol) class, overriding the abstract methods. But I can’t figure out how to run it as a UCI-compatible bot. Here’s what I tried for the entry point:
if __name__ == "__main__":
async def main():
await RandomProtocol.popen(sys.stdin.readline().strip())
asyncio.run(main())I suspect I’m misunderstanding how to start a UCI engine :thinking: or maybe I have it all wrong.
Could someone please help me or point me to a place where I can find some guidance?
Thanks in advance
View all comments
Show parent comment
1
u/Uspecd Nov 12 '25
Thanks! Previously, I already built an executable engine with
pyinstaller, and so that part works (and it was good opponent when I loaded it in the Arean GUI).I had written the whole UCI protocol from scratch, but I’d like to restart using a lib like
python-chessto avoid reinventing the wheel. Classes likechess.engine.Protocolorchess.engine.SimpleEngineseem to handle most of the UCI logic, so I tried extending them (e.g.RandomProtocol(chess.engine.Protocol)).What I can’t figure out is how to write the main function of the
your_script.pyto actually popen/convert/run (? ¯_(ツ)_/¯ ?) the protocol as a UCI engine.