【问题标题】:how to communicate with uci protocol using matlabmatlab如何与uci协议通信
【发布时间】: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)

【问题讨论】:

    标签: matlab chess


    【解决方案1】:

    如果只是使用 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 1970-01-01
      • 2013-02-17
      相关资源
      最近更新 更多