Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Is there a UCI interface on linux yet?

Author: Joseph Tadeusz

Date: 14:45:50 03/17/05

Go up one level in this thread


On March 17, 2005 at 16:59:52, Ryan B. wrote:

>Does anyone know of a chess interface for linux that supports UCI?  Thanks.
>
>-Ryan

I sometimes use this code to quickly analyse a position with Glaurung or Fruit.
It is based on http://www.gidforums.com/t-3369.html
My old Suse 7 can't run Jose.

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(){

  pid_t pid;
  int rv,dummy;
  int  commpipe[2];    /* This holds the fd for the input & output of the pipe
*/

  /* Setup communication pipeline first */
  if(pipe(commpipe)){
    fprintf(stderr,"Pipe error!\n");
    exit(1);
  }

  /* Attempt to fork and check for errors */
  if( (pid=fork()) == -1){
    fprintf(stderr,"Fork error. Exiting.\n");  /* something went wrong */
    exit(1);
  }

  if(pid){
    /* A positive (non-negative) PID indicates the parent process */
    dummy = dup(1); // see dup man page
    dup2(commpipe[1],1);  /* Replace stdout with out side of the pipe */
    close(commpipe[0]);    /* Close unused side of pipe (in side) */
    setvbuf(stdout,(char*)NULL,_IONBF,0);  /* Set non-buffered output on stdout
*/
    printf("uci\n");
    printf("ucinewgame\n");
    printf("isready\n");
    printf("position fen 3r1r2/pb3pkp/1pn2Np1/2p1PP2/8/b2BQ3/qP4PP/3R1R1K w - -
\n");
    printf("go infinite\n");
    wait(&rv);        /* Wait for child process to end */
  }
  else{
    /* A zero PID indicates that this is the child process */
    dup2(commpipe[0],0);  /* Replace stdin with the in side of the pipe */
    close(commpipe[1]);    /* Close unused side of pipe (out side) */
    /* Replace the child fork with a new process */
//    if(execl("glaurung","glaurung",NULL) == -1){
    if(execl("fruit","fruit",NULL) == -1){
      fprintf(stderr,"execl Error!");
      exit(1);
    }
  }
  return 0;
}




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.