1

I've been trying to make a custom python engine, that uses UCI protocol to communicate it's moves. I'm able to understand how the UCI protocol works, but I don't understand how to make my python engine script communicate with the Arena GUI. I can only make it communicate with stockfish. I know what UCI commands i need to run but i don't know where to run them using python.

Please provide me with an example python script that supports being imported into Arena GUI and works with UCI protocol.

import subprocess
engine = subprocess.Popen(
    'cmd.exe',
    universal_newlines=True,
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    bufsize=1
)


def put(command):
    print('\nyou:\n\t'+command)
    engine.stdin.write(command+'\n')
l = ""
def get():
    # using the 'isready' command (engine has to answer 'readyok')
    # to indicate current last line of stdout
    engine.stdin.write('isready\n')
    print('\nengine:')
    while True:
        text = engine.stdout.readline().strip()
        if text == 'readyok':
            break
        if text != '':
            print(text)
        if text.split(' ')[0] == 'bestmove':
            ai.add_move(text.split(' ')[1])
            m = ai.make_move()
            put("position moves "+text.split(' ')[1]+'\n'+"position moves "+m+'\ngo')
        if text == 'isready':
            put("isreadyok")
        if text == 'isreadyok':
            ai = ChessAI('b')
            put('position startpos\ngo')
        if text == 'position startpos':
            ai = ChessAI('w')
        if text == 'go':
            put("bestmove "+ai.make_move())
        if text.split(' ')[0] == "position" and text.split(' ')[1] == "moves" and "position" in l:
            ai.add_move(text.split(' ')[2])
        if text == 'uci':
            put("id name CheezyChess\nid author itzcool\nuciok")
        l = text

# in case when white (they start first)
while True:
    get()
    
# in case when black
put('ucinewgame\nisready')
get()```

  • UCI is just an input/print protocol. Check out here : https://github.com/PaulJeFi/reglisse-chess/blob/main/src/Python/uci.py – LittleCoder Aug 25 '23 at 10:17

0 Answers0