Connecting engine to winboard

Discussions about Winboard/Xboard. News about engines or programs to use with these GUIs (e.g. tournament managers or adapters) belong in this sub forum.

Moderator: Andres Valverde

Connecting engine to winboard

Postby bergin » 23 Nov 2009, 00:31

Hi forum,

I read through some previous posts on how to send moves to winboard but couldnt find anything on how you set up winboard.

I thought I could start from here.

1) run winboard

2) execute this code:

Code: Select all
signal(SIGINT, SIG_IGN);
printf("move %s\n", "e2e4");
fflush(stdout);


3) somehow the move is made?

Thats about as far as I got!

Pointers please!
bergin
 
Posts: 4
Joined: 22 Nov 2009, 14:36

Re: Connecting engine to winboard

Postby H.G.Muller » 23 Nov 2009, 14:46

I think to run under WinBoard, you should at least wait for receiving a "go" command on your standard input before sending a move, or WinBoard might simply discard the move.

To run your "mock-up engine" under WinBoard, you should start WB through the startup dialog, and type the name of your executable in the field for the first engine. (Possibly followed by " /fd=FOLDERNAME" if your executable is not in the same older as wnboard.exe.)
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Connecting engine to winboard

Postby bergin » 24 Nov 2009, 00:54

Ok thanks. The idea in the code is that the human plays any move and the computer plays e7e5. I can get WB to load the program (a big move forward!) but on playing a move the program doesnt respond. How can I alter the code to make it work?

Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

int main(){

char line[256], command[256];
signal(SIGINT, SIG_IGN);
int computer_side, side;
printf("\n");
printf("feature time=0\n" );
fflush(stdout);

   for (;;){
      fflush(stdout);
      if (side == computer_side) {
         printf("move e7e5\n" );
         //alter_board
         continue;
      }

       if (!fgets(line, 256, stdin))
         break;
      sscanf(line, "%s", command);
      if (line[0] == '\n')
         continue;
      if (!strcmp(command, "go")) {
         side=1;
         computer_side = side;
         continue;
      }


      if (!strcmp(command, "quit"))
         break;
   }
return 0;
}

bergin
 
Posts: 4
Joined: 22 Nov 2009, 14:36

Re: Connecting engine to winboard

Postby H.G.Muller » 24 Nov 2009, 11:17

OK, my mistake. After receiving "new" (which you do not detect, but which will be sent), the engine is supposed to be set for playing black. So it does not receive a "go" command, just the move. So what you wrote now works only if you let the computer play white (which you originally did).

You don't initialize side and compute_side now (which is a bad idea for local variables at any rate). To make it work you should initialize computer_side to black, and side to white. And after sending a move, you should flip side, because now (when I let it play white) it keeps sending the same move forever. (And an illegal one on top of it, as it is a black move, but even if you would have sent a white move it would only be legal the first time you sent it.)
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Connecting engine to winboard

Postby bergin » 30 Nov 2009, 02:52

HG, Got it working fine, thanks! quite thrilling when you see it happening. no castling, en-passant or checks/doublechecks or mate but if I dont concentrate it will gain material advantage; also moves which are very counter-intuitive but perfectly good as moves.
bergin
 
Posts: 4
Joined: 22 Nov 2009, 14:36

Re: Connecting engine to winboard

Postby bergin » 02 Dec 2009, 01:49

.. and for those wanting to know how to get an engine to connect to winboard:

Code: Select all
// based on kerrigan's work
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "functions.h"

tile board[64];

int nodes=0;
char game_tree_log[10000];
int side, the_score;
int ply=0;
extern move pv[50][50];
extern int pv_length[50];
move movelist[200]  ;

int main(void){
 
   xboard();
}

void xboard(void){
   int count, computer_side, human_side;
   char line[256], command[256];
   move m;


   signal(SIGINT, SIG_IGN);
   printf("\n");

   initialise();
   count = find_legals( board, movelist);   
   computer_side = NOCOLOR;

   for (;;) {
      fflush(stdout);

      if (side == computer_side) {
         the_score = think(board);
         printf("move %s\n", convert_move_to_coordinate_notation(pv[0][0]));
         make_game_move(pv[0][0], board, count, movelist);
         ply = 0;
         count = find_legals( board, movelist);
         continue;
      }

      if (!fgets(line, 256, stdin))
         return;

      if (line[0] == '\n')
         continue;

      sscanf(line, "%s", command);

      if (!strcmp(command, "xboard"))
         continue;

      if (!strcmp(command, "new")) {
         initialise();
         count = find_legals( board, movelist);   
         computer_side = BLACK;
         human_side = WHITE;
         continue;
      }

      if (!strcmp(command, "quit"))
         return;

      if (!strcmp(command, "force")) {
         computer_side = NOCOLOR;
         continue;
      }

      if (!strcmp(command, "white")) {
         side = WHITE;
          count = find_legals( board, movelist);   
         computer_side = BLACK;
         human_side = WHITE;
         continue;
      }

      if (!strcmp(command, "black")) {
         side = BLACK;
          count = find_legals( board, movelist);   
         computer_side = WHITE;
         human_side = BLACK;
         continue;
      }

      if (!strcmp(command, "otim")) {
         continue;
      }

      if (!strcmp(command, "go")) {
         computer_side = side;
         human_side = BLACK;
         continue;
      }
      m = parse_move(line);
      if (side == human_side) {
         
         if ( m.from >=0){
            if(make_game_move(m, board, count, movelist)){
               printf("The selection is not on list: %s\n", line);
               fflush(stdout);
            }
         }
         else 
            printf("Error (unknown command): %s\n", command);
       }

   }
}



/*void play_chess(void){

   int computer_side, the_score;
   char s[256];
   int m;

   printf("\n");
   printf("Bergins Blunder\n");
   printf("\"help\" displays a list of commands.\n");
   printf("\n");

   initialise();
   count = find_legals( board, movelist);   
   computer_side = NOCOLOR;

   for (;;) {
      if (side == computer_side) {
         
         the_score = think(board);
         printf("Comp move %s\n", pv[0][0]);
         make_game_move(pv[0][0], board, count, movelist);
         ply = 0;
         count = find_legals( board, movelist);
         continue;



      }

      printf("bb> ");
      if (scanf("%s", s) == EOF)
         return 0;
      if (!strcmp(s, "on")) {
         computer_side = side;
         continue;
      }
      if (!strcmp(s, "off")) {
         computer_side = NOCOLOR;
         continue;
      }
      
      if (!strcmp(s, "st")) {
         scanf("%d", &max_time);
         max_time *= 1000;
         max_depth = 32;
         continue;
      }
      if (!strcmp(s, "sd")) {
         scanf("%d", &max_depth);
         max_time = 1 << 25;
         continue;
      }
      if (!strcmp(s, "undo")) {
         if (!hply)
            continue;
         computer_side = EMPTY;
         takeback();
         ply = 0;
         gen();
         continue;
      }
      if (!strcmp(s, "new")) {
         computer_side = NOCOLOR;
         initialise();
         count = find_legals( board, movelist);   
         continue;
      }
      if (!strcmp(s, "d")) {
         show_board();
         continue;
      }

      if (!strcmp(s, "bye")) {
         printf("Share and enjoy!\n");
         break;
      }

      if (!strcmp(s, "h")) {
         printf("on - computer plays for the side to move\n");
         printf("off - computer stops playing\n");
         printf("new - starts a new game\n");
         printf("d - display the board\n");

         printf("bye - exit the program\n");

         printf("Enter moves in coordinate notation, e.g., e2e4, e7e8Q\n");
         continue;
      }

      m = parse_move(s);
      if (m == -1 || !makemove(gen_dat[m].m.b))
         printf("Illegal move.\n");
      else {
         ply = 0;
         gen();
         print_result();
      }
   }
   return 0;
}*/

void initialise(void){
   
   char *startpos = "RNBQKBNR/PPPPPPPP/8/8/8/8/pppppppp/rnbqkbnr";   
   precompute_moves();
   load_board(startpos, board);
   side = WHITE;
}


bergin
 
Posts: 4
Joined: 22 Nov 2009, 14:36


Return to Winboard and related Topics

Who is online

Users browsing this forum: No registered users and 32 guests