【发布时间】:2014-02-27 06:10:35
【问题描述】:
目前我想做一个简单的winboard协议驱动程序,但我不知道从哪里开始。我已阅读此页面 (H.G. Muller Winboard Protocol Driver),但对我来说太复杂了:(
所以我搜索了如何制作一个非常简单的代码来与 winboard 进行通信并找到了这个页面 (Communicating with XBoard (chess engine) (C++/C) Stackoverflow)。我知道主要的想法是从 winboard 获取一些输入并打印一些东西给 winboard 一个命令。我也尝试了 Eric Thoma 在该页面中编写的代码,并进行了一些更改。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// four different constants, with values for WHITE and BLACK that suit your engine
#define WHITE 1
#define BLACK 2
#define NONE 0
#define ANALYZE 3
#define DEFAULT_FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
int main(int argc, const char * argv[]){
int stm; // side to move
int engineSide=NONE; // side played by engine
int i, score;
char inBuf[80], command[80];
while(1){
fflush(stdout);
if (stm == engineSide){
printf("move %s\n", "a7a5");
// change the stm?
continue;
}
fflush(stdout);
if (!fgets(inBuf, 80, stdin)) continue;
sscanf(inBuf, "%s", command);
if(!strcmp(command, "quit")){
break; // breaks out of infinite loop
}
if(!strcmp(command, "force")){
engineSide = NONE;
continue;
}
if(!strcmp(command, "go")){
engineSide = stm;
continue;
}
if(!strcmp(command, "exit")){
engineSide = NONE;
continue;
}
if(!strcmp(command, "new")){
engineSide = BLACK;
// change the stm?
continue;
}
if(!strcmp(command, "setboard")){
engineSide = NONE;
// change the stm?
continue;
}
if(!strcmp(command, "protover")){
printf("feature ping=1 setboard=1 colors=0 usermove=1 debug=1");
printf("feature done=1");
continue;
}
if(!strcmp(command, "ping")){
printf("pong%s", inBuf+4);
continue;
}
if(!strcmp(command, "usermove")){
//whatever
//i just want to try to move the chess piece
}
}
}
但没有任何变化,当我通过创建 winboard 和简单协议的 exe 文件的快捷方式运行它时,我的代码没有移动任何棋子。
C:\WinBoard-4.7.3\WinBoard\winboard.exe -cp -fcp C:\WinBoard-4.7.3\WinBoard\testdriver.exe -scp "GNUChess"
我的问题是:
- 对不起,如果我在这里看起来很可笑:(我编码对了吗?
- 我怎样才能在不制作整个引擎的情况下只做一个简单的动作(不考虑和分析用户动作)?无论用户移动棋子,我都会移动 1 步,例如 a7a5。只是为了让我知道这个 winboard 协议的流程。
之前谢谢..
【问题讨论】: