title: Communicating with XBoard (chess engine) (C++/C)
body: <p>I was just toying around with making a basic chess engine. I was able to get a lot of advice from <a href="http://web.archive.org/web/20070704121716/http://www.brucemo.com/compchess/programming/alphabeta.htm" rel="nofollow">http://web.archive.org/web/20070704121716/http://www.brucemo.com/compchess/programming/alphabeta.htm</a>, but the real site is down and not all the pages are archived. (Anyone know where to find a full version of Bruce's site?)</p>
  
  <p>But now to the real question: how do I communicate with XBoard? I understand it is via stdin and stdout, but I've been having problems in code. Basically, to get started, I just want to </p>
  
  <ol>
  <li>receive input from XBoard and print it to the console/screen </li>
  <li>Give a move of hard-coded input to XBoard and have it make the move </li>
  <li>program utility functions and have a random chess ai which chooses random moves. </li>
  </ol>
  
  <p>After that, I can start implementing real things like alpha-beta searching.</p>
  
  <p>I am stuck on the first two things right now. Here is some code I have tried to write/borrowed.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #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;
  }
  </code></pre>
  
  <p>I am just getting back into C after about 6 months break and this is the first project that I have used stdin/stdout pipelines to communicate with another program (minus a few basic programs) so I would appreciate any help and any explanations. I know programming a chess engine is a herculean task, but I have already programmed the rules of chess before and what I can find of Bruce's site is absolutely amazing.</p>