gpt4 book ai didi

matlab - 如何使用matlab与uci协议(protocol)进行通信

转载 作者:行者123 更新时间:2023-12-02 09:39:52 25 4
gpt4 key购买 nike

我正在寻找一种使用 matlab 通过 uci 协议(protocol)与国际象棋引擎进行通信的方法。国际象棋引擎是rybka,它是一个exe文件。当我运行 rybka.exe 时,我可以通过 dos 命令提示符进行通信,但我想通过 matlab 进行通信。我想我必须使用流管道、标准输入和标准输出,但我不知道如何使用它。

我在 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)

最佳答案

如果只是使用 exe 文件并捕获输出,您可以使用 system 命令来捕获输出。例如,我可以通过以下方式运行系统的 dir 命令:

>> [~, output] = system('dir')

output =

ant ant.cmd antRun.bat antenv.cmd envset.cmd runant.pl
ant.bat antRun antRun.pl complete-ant-cmd.pl lcp.bat runant.py

文档:http://www.mathworks.com/help/matlab/ref/system.html

另请参阅:Running C program's executable from Matlab and getting the output

关于matlab - 如何使用matlab与uci协议(protocol)进行通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16460383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com