Interfacing With External Program

4 visualizzazioni (ultimi 30 giorni)
Rajendra
Rajendra il 19 Mag 2011
I am making a chess playing robot which will be controlled online by matlab through serial interface. Currently, I need to interface with a chess engine. It should go like this. The chess engine is running separately. I send it string queries such as "move e2-e4" It returns string answers such as "bestmove g2-g4" I don't see where I can start. Can someone please link me to some example communication with external programs. I don't have C-source code of the program. Just an exe.

Risposta accettata

Daniel Shub
Daniel Shub il 19 Mag 2011
If you were not in MATLAB how would you call the chess engine? You can call external exe files with system.
doc system
  3 Commenti
Daniel Shub
Daniel Shub il 19 Mag 2011
Did you look at the documentation for system?
try:
[status, result] = system('c:\ChessEnginePath\engine.exe move e2-e4')
Rajendra
Rajendra il 19 Mag 2011
I Tried this
[status, result] = system('c:\ChessEnginePath\engine.exe')
(trying
[status, result] = system('c:\ChessEnginePath\engine.exe move e2-e4') will issue error, becasue the engine don't accept arguments during starting)
Then the program runs in matlab command window itself with a blinking cursor!
I can input commands to it, but no output shows up. Finally after I quit the engine ('quit' command), all of its outputs now show-up in result variable
I want the program to run separately and I want to send it commands only occasionally since I need to do other tasks meanwhile.
Thanks for your help.

Accedi per commentare.

Più risposte (1)

Clemens
Clemens il 19 Mag 2011
On a similar problem I used the program expect to talk to the "bad" program for me. Say as mediator. (manual is at eg http://www.tcl.tk/man/expect5.31/expect.1.html and there are many samples online )
In your case the comand should look like:
[status,result] = system(...
'expect -c ''spawn engine; send "move e2-e4\r"; close;''')
It can be installed on windows via cygwin (as I did) or mingw.

Categorie

Scopri di più su Board games in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by