Communication with XBoard (Chess Engine) (C ++ / C)

I just played with the basic chess engine. I managed to get a lot of advice from http://web.archive.org/web/20070704121716/http://www.brucemo.com/compchess/programming/alphabeta.htm , but the real site does not work, and not all pages are archived. (Does anyone know where to find the full version of Bruce's site?)

But now to the real question: how do I communicate with XBoard? I understand that this is through stdin and stdout, but I have code problems. Basically, for starters, I just want

  • get input from XBoard and print it on the console / screen
  • Move the hard-coded input to the XBoard and make the transition
  • Utility functions and have random ai chess that select random moves.

After that, I can begin to implement real things, such as alpha beta search.

I'm stuck on the first two things right now. Here is the code I tried to write / borrow.

#include <iostream> #include <string.h> #include <stdio.h> #include <stdlib.h> #define STR_BUFF 256 using namespace std; int main (int argc, const char * argv[]) { char input[STR_BUFF]; char output[STR_BUFF]; while(true){ fflush(stdout); // read input if (!fgets(input, STR_BUFF, stdin)){ printf("terminated"); return 0;; } printf("%s", input); } return 0; } 

I am only returning to C after 6 months of break, and this is the first project in which I used the stdin / stdout pipelines to communicate with another program (minus a few basic programs), so I would appreciate any help and any explanation, I know That programming a chess engine is a Hercules task, but I have already programmed chess rules before, and what I can find on Bruce's website is just awesome.

+4
source share
2 answers

You do this almost right: get a command from XBoard using fgets , then report it using printf and fflush . (However, one thing is wrong: you do not need to "print the command to the console / screen", you do not communicate with the console / screen, you only read commands from the XBoard and send the moves back to the XBoard).

It would probably be easier to start with some existing code. Try reading sources for GNU Chess . Or download sources for any other chess engine that supports the XBoard protocol.

And here is another question with a lot of information about programming chess engines: " What are good resources for writing a chess engine?.

+3
source

I think you are looking for pipe () included in unistd.h. Take a look at Can popen () create bidirectional pipes like pipe () + fork ()? for notes during implementation.

+1
source

Source: https://habr.com/ru/post/1399664/


All Articles