Currently i want to make a simple winboard protocol driver, but i don't know where to start. I have read this page (H.G. Muller Winboard Protocol Driver), but it is too complicated for me :(
So i search how to make a very simple code to communicate to the winboard and found this page (Communicating with XBoard (chess engine) (C++/C) Stackoverflow). I understand the main idea is to get some input from winboard and print something to give winboard a command. I also tried the code made by Eric Thoma in that page, with a few changes.
#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
}
}
}
but nothing have change, when i run it by making a shortcut to the winboard and the simple protocol's exe file, my code is not moving any chess piece.
C:\WinBoard-4.7.3\WinBoard\winboard.exe -cp -fcp C:\WinBoard-4.7.3\WinBoard\testdriver.exe -scp "GNUChess"
My Question is:
- sorry if i looked like ridiculous here :( am i code it right?
- how can i just make a simple move without making the entire engine (without pondering and analyzing the user moves)? whatever the user will move the chess piece, i will just make 1 move, for example a7a5. it is just to make me know the flow of this winboard protocol.
Thanks before..