jeudi 5 mars 2015

Basic communication between Python and Stockfish


Vote count:

0




I have tried to issue commands to the Stockfish chess engine via Python taking various examples from the web (all pretty similar), but none has worked as intended for me.


Here is one code example which I have tried:



import subprocess, time

engine = subprocess.Popen(
'stockfish-x64.exe',
universal_newlines=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)

def put(command):
print('\nyou:\n\t'+command)
engine.stdin.write(command+'\n')

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('\t'+text)

get()
put('uci')
get()
put('setoption name Hash value 128')
get()
put('ucinewgame')
get()
put('position startpos moves e2e4 e7e5 f2f4')
get()
put('go infinite')
time.sleep(3)
get()
put('stop')
get()
put('quit')


This is supposed to trigger a series of commands to the Stockfish engine, but unfortunately for me it does not get past:



engine:
Stockfish 2.2.2 JA SSE42 by Tord Romstad, Marco Costalba and Joona Kiiski


and it just hangs there. I have tried multiple very similar code examples, but the same thing happens every time. I suspect the problem is at my end. Could anyone help?



asked 36 secs ago







Basic communication between Python and Stockfish

Aucun commentaire:

Enregistrer un commentaire