【发布时间】:2013-05-09 11:11:37
【问题描述】:
我正在寻找一种使用 matlab 与具有 uci 协议的国际象棋引擎进行通信的方法。 国际象棋引擎是rybka,它是一个exe文件。当我运行 rybka.exe 时,我可以通过 dos 命令提示符进行通信,但我想通过 matlab 进行通信。 我想我必须使用streampipe和stdin和stdout,但我不知道如何使用它。
我在 Python 中找到了这段代码,它运行良好,但我正在寻找一个 matlab 版本:
import subprocess, time
engine = subprocess.Popen(
'a.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)
【问题讨论】: