how to communicate with uci protocol using matlab

半城伤御伤魂 提交于 2019-12-22 09:56:06

问题


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.

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)

回答1:


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

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

See also: Running C program's executable from Matlab and getting the output



来源:https://stackoverflow.com/questions/16460383/how-to-communicate-with-uci-protocol-using-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!