winboard interface questions

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mike_bike_kite
Posts: 98
Joined: Tue Jul 26, 2011 12:18 am
Location: London

winboard interface questions

Post by mike_bike_kite »

I've altered my little program to make it play as an engine but I'm having issues getting it to interface properly with WinBoard and presumably every other similar interface. I'm a little unclear of the dialogue that's expected at the start (and yes I've read lots of pages).

Code: Select all

C:\WinBoard\WinBoard>winboard.exe -cp -fcp  "java -jar chess.jar engine" -scp "java -jar chess.jar engine"
<xboard
<new
<result * &#123;xboard exit&#125;
<null
The above dialogue is currently being read. The < means an input from winboard etc while the > shows an output. It reads the command "xboard" and just outputs a new line. It is then sent the command "new" and I set the program as black and wait for a move but I don't get anything. I tried outputting a newline, I tried outputting a move but it stays quiet. When I quit WinBoard I then get the "result" and "null" sent to me.

What do I need to do? Is there an example dialogue I can look at?

The following was what I was expecting:

Code: Select all

<xboard
>
<new
<e2e4
>e7e5
<g1f3
>b8c6
<quit
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: winboard interface questions

Post by hgm »

Well that you don't see the ">newline" that your program prints in a log that your program makes can be only the fault of your program...

It seems strange, though, that you do not receive the move from WinBoard. In fact after "xboard" WinBoard would immediately send "protover 2", and even that does not show up. It seems like you are missing most of the stuff that WB sends (e.g. "new" is always sent immediately followed by "random").

Could you try to run with the extra option -debug,

winboard.exe -cp -fcp "java -jar chess.jar engine" -scp "java -jar chess.jar engine" -debug

and then post the winboard.debug file that will be made in the WinBoard folder, to see how it looks from WinBoard's end?
mike_bike_kite
Posts: 98
Joined: Tue Jul 26, 2011 12:18 am
Location: London

Re: winboard interface questions

Post by mike_bike_kite »

Don't worry, I'm under know illusions, I know it's a problem with my program (or more accurately my understanding of the winboard interface) but I just didn't know how to get any further :)

The debug file is :

Code: Select all

recognized 'normal' (-1&#41; as variant normal
recognized 'normal' (-1&#41; as variant normal
WinBoard 4.5.2a + java
Reset&#40;1, 0&#41; from gameMode 0
recognized 'normal' (-1&#41; as variant normal
GameEnds&#40;0, &#40;null&#41;, 2&#41;
shuffleOpenings = 0
TC string = '&#58;40/300'
mps=40 tc=300000 inc=0
TC string = '&#58;40/300'
mps=40 tc=300000 inc=0
StartChildProcess &#40;dir=".") java -jar chess.jar engine
nice engine proc to 10
812 >first &#58; xboard
protover 2
1437 <first &#58; 
10828 >first &#58; new
random
10828 >first &#58; level 40 5 0
10828 >first &#58; post
10828 >first &#58; hard
GameEnds&#40;28, xboard exit, 2&#41;
18343 >first &#58; result * &#123;xboard exit&#125;
18343 >first &#58; force
18343 >first &#58; quit
I can see a level command in your log but not in mine. I'm not sure what the random bit does. My own log just shows:

Code: Select all

<xboard
>
<new
<result * &#123;xboard exit&#125;
<null
[/code]
mike_bike_kite
Posts: 98
Joined: Tue Jul 26, 2011 12:18 am
Location: London

Re: winboard interface questions

Post by mike_bike_kite »

hgm wrote:Well that you don't see the ">newline" that your program prints in a log that your program makes can be only the fault of your program...
Sorry was trying lot's of different options to get the two speaking together and must have taken an earlier log in my first post. It does send a blank line in return. It doesn't seem to receive the level command though. Not sure why.
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: winboard interface questions

Post by hgm »

The winboard.debug indeed shows it received the newline. There is no need to send this, but is does not hurt either, as empty lines will be ignored. (All command you send should end in a newline, though!) Although it might not be obvious from the winboard.debug, the commands 'random' and 'protover 2' are sent too. The are not preceded by a time-stamp in the log, because they are send combined with the previous commandas a single string (containing an internal newline).

So the point where it goes wrong is the reception of the 'protover2'. For some reason your program does skip some of the input. I don't know Java at all, so I can only guess what is the reason. You only seem to process input until the first newline occurring in it, and then skip all remaining characters that were received at the same time. Or perhaps there is a rule in Java that the input buffer is cleared the moment you send output, so that printing the newline in response to 'xboard' would make you lose the 'protover 2' that is still in the buffer. (That would not explain why you don't see the 'level 40 5 0', though...)
mike_bike_kite
Posts: 98
Joined: Tue Jul 26, 2011 12:18 am
Location: London

Re: winboard interface questions

Post by mike_bike_kite »

It appeared to be a buffering issue and I've managed to get a little further but it's still not playing any moves. It just seems to wait after it posts the instruction "hard". I did try posting my first move e2e4 after receiving "hard" but this made no difference.

WinBoard does say it's starting the chess engine and then the message goes away but no moves appear on the board.

winboard.debug:

Code: Select all

recognized 'normal' (-1&#41; as variant normal
recognized 'normal' (-1&#41; as variant normal
WinBoard 4.5.2a + java
Reset&#40;1, 0&#41; from gameMode 0
recognized 'normal' (-1&#41; as variant normal
GameEnds&#40;0, &#40;null&#41;, 2&#41;
shuffleOpenings = 0
TC string = '&#58;40/300'
mps=40 tc=300000 inc=0
TC string = '&#58;40/300'
mps=40 tc=300000 inc=0
StartChildProcess &#40;dir=".") java -jar chess.jar engine
nice engine proc to 10
687 >first &#58; xboard
protover 2
10703 >first &#58; new
random
10703 >first &#58; level 40 5 0
10703 >first &#58; post
10703 >first &#58; hard
GameEnds&#40;28, xboard exit, 2&#41;
25062 >first &#58; result * &#123;xboard exit&#125;
25062 >first &#58; force
25062 >first &#58; quit
and for what it's worth this is my log :

Code: Select all

Connecting to WinBoard
<xboard &#58; ignored
<protover &#58; ignored
<2 &#58; ignored
<new &#58; done
<random &#58; ignored
<level 40 5 0 &#58; done
<post &#58; ignored
<hard &#58; ignored
<result &#58; done
<* &#58; ???
<&#123;xboard &#58; ???
<exit&#125; &#58; ???
<force &#58; done
<quit &#58; done
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: winboard interface questions

Post by hgm »

Well, according to the winboard.debug, no moves were sent by WinBoard to the engine. Did you actually play any moves? At the start of a game the engine is set to play black, so WinBoard is now waiting for the human to enter a move, so it can relay it to the engine. Letting the engine print a move for white while it is supposed to play black is a protocol violation, and the move will be ignored by WinBoard (assuming it is a move from a previous game that arrived with some delay).

From the posted logs it seems your communication runs fine now. But for the command parsing you seem to still have a problem with commands that are not a single word: the parameters to the result command are parsed like they are separate commands, rather than read away and processed. After recognizing a command you should at least read away everything upto and including the next newline, before starting to recognize new commands.
mike_bike_kite
Posts: 98
Joined: Tue Jul 26, 2011 12:18 am
Location: London

Re: winboard interface questions

Post by mike_bike_kite »

The move is waiting to be sent but I'm not sure when to send it. Should it be after "xboard" or after "hard"? And what do I do if it's playing black? Is there an example dialogue that shows what to send (and when)?

I was sort of expecting that the program should wait until it gets sent a "go" before sending a move (if it's white) or should just reply with a move if it's given a move (black). Obviously this is not the case.

On the plus side I'm very nearly there.
mike_bike_kite
Posts: 98
Joined: Tue Jul 26, 2011 12:18 am
Location: London

Re: winboard interface questions

Post by mike_bike_kite »

I'm now ignoring to the end of the line after getting commands I can't process. This does make the logging look more sensible but doesn't make it register any moves. I also tried sending a move "e2e4" after getting the input "hard" but this made no difference.

My log shows :

Code: Select all

Connecting to WinBoard
<xboard &#58; ignored
<protover 2 &#58; ignored
<new &#58; done
<random &#58; ignored
<level 40 5 0 &#58; done
<post &#58; ignored
<hard &#58; done
>e2e4
<result * &#123;xboard exit&#125; &#58; done
<force &#58; done
<quit &#58; done
and winboard debug shows :

Code: Select all

recognized 'normal' (-1&#41; as variant normal
recognized 'normal' (-1&#41; as variant normal
WinBoard 4.5.2a + java
Reset&#40;1, 0&#41; from gameMode 0
recognized 'normal' (-1&#41; as variant normal
GameEnds&#40;0, &#40;null&#41;, 2&#41;
shuffleOpenings = 0
TC string = '&#58;40/300'
mps=40 tc=300000 inc=0
TC string = '&#58;40/300'
mps=40 tc=300000 inc=0
StartChildProcess &#40;dir=".") java -jar chess.jar engine
nice engine proc to 10
765 >first &#58; xboard
protover 2
10765 >first &#58; new
random
10765 >first &#58; level 40 5 0
10765 >first &#58; post
10765 >first &#58; hard
10781 <first &#58; e2e4
GameEnds&#40;28, xboard exit, 2&#41;
21781 >first &#58; result * &#123;xboard exit&#125;
21781 >first &#58; force
21781 >first &#58; quit
It seems to receive the move but just doesn't show it on screen. I kill the program after about 10 seconds and I think that generates the GameEnds message.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: winboard interface questions

Post by Evert »

mike_bike_kite wrote:The move is waiting to be sent but I'm not sure when to send it. Should it be after "xboard" or after "hard"? And what do I do if it's playing black? Is there an example dialogue that shows what to send (and when)?

I was sort of expecting that the program should wait until it gets sent a "go" before sending a move (if it's white) or should just reply with a move if it's given a move (black). Obviously this is not the case.

On the plus side I'm very nearly there.
You can send a move when there's a game in progress and if it's your move.
By default the engine plays black, but you should implement the commands for setting the colour the engine plays.