如何使用Matlab与uci协议进行通信 [英] how to communicate with uci protocol using matlab

查看:188
本文介绍了如何使用Matlab与uci协议进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用matlab与具有uci协议的国际象棋引擎进行通信的方法. 国际象棋引擎是rybka,它是一个exe文件.当我运行rybka.exe时,我可以通过dos命令提示符进行通信,但是我想通过matlab进行通信. 我想我必须使用streampipe以及stdin和stdout,但是我不知道如何使用它.

I'm looking for a method to communicate with a chess engine with uci protocol using matlab. The chess engine is rybka and its an exe file. When I run the rybka.exe, I can communicate via dos command prompt but I want do that via matlab. I think I have to use streampipe and stdin and stdout but I don't know how use it.

我在Python中找到了此代码,并且可以正常工作,但是我正在寻找Matlab版本:

I found this code in Python and it works fine but I'm looking for a matlab version:

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命令:

If it's just a case of using the exe file and capturing the output you can use the system command to capture the output. For example I can run the system's dir command in the following way:

>> [~, 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

另请参阅:从Matlab运行C程序的可执行文件并获取输出

这篇关于如何使用Matlab与uci协议进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆