front-ending

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
hgm
Posts: 27814
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: front-ending

Post by hgm »

odomobo wrote: Thu May 07, 2020 12:39 amHowever, it might just be simpler to implement fen than to implement drops (or roughly as simple).
Well, of course all of this is dead simple. Even providing an existing engine that has a non-standard command-line interface with enough CECP understanding to play automated games with it under XBoard should be at most a 10-min jub of someone who already knows the engine. So basically all we say here is nitpicking.

But parsing FEN is more complex than parsing drop moves. In the end a FEN will still do multiple calls to a routine PutPiece(type, square), which would also be the back-end for the drop-move. The recognition of the latter is really trivial:

Code: Select all

if(line[1] == '@') PutPiece(line[0], N_FILES*(line[3]-'1') + (line[2]-'a'));
A FEN parser will be at least 5 times more complex.

To play automated games under WinBoard at the default TC only requires:

Code: Select all

while(1) {
  static int myColor = 1, stm=0; // 0 = white, 1 = black
  if(stm == myColor) {
    ThinkAndPlayMove(); // the engine is supposed to have that function
    printf("move %s\n", moveText); // this would usually just be an adaptation of the format ThinkAndPlayMove() prints the move in
    stm ^= 1;
  }
  fflush(stdout);
  line = ReadLine(); // the engine is supposed to have that function
  if(!strcmp(line, "go")) myColor = stm;
  else if(!strcmp(line, "force")) myColor = 2; // neither color
  else if(isdigit(line[1])) stm ^= 1, ParseAndPlayMove(line); // the engine is supposed to have that function
}
This already allows you to play gauntless with the engine starting from opening lines, when you install the engine with the WinBoard option /xreuse.

To prevent some annoying pauses (while waiting for timeouts) at the start and end of a game you could add

Code: Select all

  else if(!strcmp(line, "quit")) exit(0);
  else if(!strcmp(line, "protover 2")) printf("feature done=1\n");
Hardly rocket science...
odomobo
Posts: 96
Joined: Fri Jul 06, 2018 1:09 am
Location: Chicago, IL
Full name: Josh Odom

Re: front-ending

Post by odomobo »

hgm wrote: Thu May 07, 2020 11:31 am A FEN parser will be at least 5 times more complex.
Hm yeah, seems reasonable.
hgm wrote: Thu May 07, 2020 11:31 am To play automated games under WinBoard at the default TC only requires: ...
So based on this, I guess this is already a solved problem. The only piece missing, I would argue, is this isn't very well documented (or rather, it's buried in too much documentation).

I think it would be useful to have a quickstart guide for interfacing with winboard, maybe on the chessprogramming wiki perhaps. I find the CECP documentation pretty overwhelming, but I think that's just the nature for such a comprehensive protocol. I'll say that from my perspective, I always figured a pretty robust implementation was required in order for that to work (perhaps I'm a bit dense).
User avatar
hgm
Posts: 27814
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: front-ending

Post by hgm »