我正在研究C中的国际象棋编程和UCI命令的基本使用,我试图将Silvestro Fantacci C++ HelloWorld国际象棋引擎转换为C但没有成功.
参见Silvestro Fantacci C++ HelloWorld国际象棋引擎
以下是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#define BUFFERSIZE 50
int main(int argc, char **argv)
{
char line[BUFFERSIZE];
while(fgets(line, BUFFERSIZE, stdin) != NULL)
{
if (line == "uci")
{
printf("id name rpdHWchessengineinC\n");
printf("id author Richard\n");
printf("uciok\n");
}
else if (line == "isready")
printf("readyok\n");
else if (line == "ucinewgame")
; // nothing to do
else if (line == "position startpos moves e2e4\n")
; // nothing to do
else if (line == "go ") // SF HW code here: (Line.substr (0, 3) == "go ")
// Received a command like: "go wtime 300000 btime 300000 winc 0 binc 0"
printf("bestmove e7e5\n");
else
// Command not handled
printf("What? Try again there is an error\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我编译这个时,我会收到GCC的一些警告.
gcc -Wall -c "rpdHWchessengineinC.c" (in directory: C:\RPD_Computing_Programming\RPD_Chess_programming\RPD HelloWorld C engine)
rpdHWchessengineinC.c: In function 'main':
rpdHWchessengineinC.c:41:18: warning: comparison with string literal results in unspecified behavior [-Waddress]
rpdHWchessengineinC.c:47:23: warning: comparison with string literal results in unspecified behavior [-Waddress]
rpdHWchessengineinC.c:51:23: warning: comparison with string literal results in unspecified behavior [-Waddress]
rpdHWchessengineinC.c:55:23: warning: comparison with string literal results in unspecified behavior [-Waddress]
rpdHWchessengineinC.c:59:23: warning: comparison with string literal results in unspecified behavior [-Waddress]
Compilation finished successfully.
Run Code Online (Sandbox Code Playgroud)
然而该文件编译和构建,但在作为竞技场国际象棋gui中的UCI引擎添加时不响应移动1.e2e4(也不会在Windows命令提示符中响应..除了打印错误消息,例如:uci什么?尝试再次出现错误e2e4什么?再试一次有错误等)
我很感谢有用的回复,告诉我问题是什么以及如何解决这个问题,非常感谢.
XXXXXXXXXXXXXXXX-EDIT-XXXXXXXXXXXXXXXXXXXX
正如我在评论中提到的,代码编译构建和运行,但不会产生移动1 .... e7e5以响应Arena GUI中的1.e2e4,我仍然在寻找UCI示例来尝试解决此问题.新代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#define BUFFERSIZE 50
int main(int argc, char **argv)
{
char line[BUFFERSIZE];
while(fgets(line, BUFFERSIZE, stdin) != NULL)
{
if (strcmp (line, "uci")== 0)
{
printf("id name rpdHWchessengineinC\n");
printf("id author Richard\n");
printf("uciok\n");
}
else if(strcmp(line, "isready")== 0)
{
printf("readyok\n");
}
else if (strcmp (line, "ucinewgame") == 0)
{
// nothing to do
}
else if (strcmp (line, "position startpos moves e2e4\n") == 0)
{
// nothing to do
}
else if (strcmp (line, "go ") == 0)
// SF HW code here: Line.substr (0, 3) == "go ")
{
// Received a cmd like:"go wtime 300000 btime 300000 winc 0 binc0"
printf("bestmove e7e5\n");
}
else {
// Command not handled
printf("What? Try again..there is an error.\n");
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
XXXXXXXXXXXXXXXXXXX-End edit-XXXXXXXXXXXXXXXX