Page 1 of 1

Problem integrating Crafty with Windows GUI

PostPosted: 05 Sep 2009, 17:50
by ignacioalex
Hi all,

I'm developing an application to play chess and I'm trying to integrate its GUI with Crafty 23.0. It is written in Java, and communication with the engine is handled through standard input/output pipes using the Winboard 2 protocol.

On Linux everything seems to be working fine so far. However, on Windows Crafty complains about some illegal moves which in fact are valid legal moves. Some examples are (Crafty is playing black):

1. e4 d5 2. exd5 (illegal move exd5?)
1. e4 c6 2. d4 d5 3. exd5 (illegal move exd5?)
1. e4 e5 2. Nf3 d6 3. d4 Nf6 4. dxe5 Nxe4 5. exd6 (illegal move exd6?)

These problems do not occur when I'm running Crafty's executable directly from the command line (cmd.exe), only when it's accessed as a subprocess of my Java application.

I managed to compile Crafty's source code on Windows using Eclipse/CDT and MinGW's GCC compiler with debug flags on, but when I try to attach to the Crafty subprocess gdb crashes and I get a Windows dialog message saying that crafty.exe has performed an illegal operation and needs to be shut down.

Other things I've tried without success:

- Explicitly setting the communication stream encoding to ASCII, UTF-8 or ISO 8859-1.
- Sending the move as e4xd5, e4d5 or Pxd5.
- Turning off Winboard protocol's san feature: Crafty complains with an error message.

Any idea or suggestion is welcome!

Cheers,

Alex

Re: Problem integrating Crafty with Windows GUI

PostPosted: 06 Sep 2009, 19:43
by H.G.Muller
My suggestion is that you print all communication between engine and GUI on a log file, together with a time mark. Then you will see quicly enough what is going wrong.

Re: Problem integrating Crafty with Windows GUI

PostPosted: 06 Sep 2009, 20:34
by ignacioalex
Below is a sample Crafty log file. After my GUI communicating exd5 Crafty complains the move is illegal.

Unfortunately I don't know what's going on inside the C code, as the development environment I'm familiar with fails to attach to the external subprocess...

Thanks,

Alex

book learning disabled


Crafty v23.0 (1 cpus)

White(1): skill 50
skill level set to 50%
White(1): xboard
White(1): protover 2
feature ping=1 setboard=1 san=1 time=1 draw=1
feature sigint=0 sigterm=0 reuse=1 analyze=1
feature myname="Crafty-23.0" name=1
feature playother=1 colors=0
feature variants="normal,nocastle"
feature done=1
White(1): accepted ping
White(1): accepted setboard
White(1): accepted san
White(1): accepted time
White(1): accepted draw
White(1): accepted sigint
White(1): accepted sigterm
White(1): accepted reuse
White(1): accepted analyze
White(1): accepted myname
White(1): accepted name
White(1): accepted playother
White(1): accepted colors
White(1): accepted variants
White(1): accepted done
White(1): hard
pondering enabled.
White(1): level 0 5 0
game/300 seconds primary time control
White(1): new
White(1): e4
time used: 4.14
book moves {e5, c5, c6, d5}
book 0.0s 1% d5! Nc3
Black(1): d5
time used: 0.00
White(2): Nc3 [pondering]
book moves {c6, d4, dxe4, Nf6}
book 0.0s 17% Nf6 e5
White(2): exd5
Illegal move: exd5

Re: Problem integrating Crafty with Windows GUI

PostPosted: 08 Sep 2009, 13:46
by H.G.Muller
Well, I don't know how to read Crafty logs. In particular it is not clear what is input, what is output, and which are just comments on internal state.

Re: Problem integrating Crafty with Windows GUI

PostPosted: 08 Sep 2009, 14:38
by ignacioalex
Everything following the White(?): prompt is input from my GUI; everything else is Crafty's output.

I think the relevant part are the last two lines:

White(2): exd5
Illegal move: exd5

my GUI inputs exd5 and Crafty complains that the move isn't legal. Maybe at this point there is something wrong going on in the C code that I can't diagnose.

Maybe someone with a compiled debug version of Crafty on Windows could try to attach a debugger to my GUI??? I would be glad to post its binary in this case.

Re: Problem integrating Crafty with Windows GUI

PostPosted: 08 Sep 2009, 20:18
by H.G.Muller
I would think it is more relevant what the

White(2): Nc3 [pondering]

means. If an engine first receives Nc3, then exd5 becomes illegal, because it is no longer white's turn.

Re: Problem integrating Crafty with Windows GUI

PostPosted: 08 Sep 2009, 20:46
by Guenther Simon
H.G.Muller wrote:I would think it is more relevant what the

White(2): Nc3 [pondering]

means. If an engine first receives Nc3, then exd5 becomes illegal, because it is no longer white's turn.


Exactly. It seems to me this was send as a real move.

Guenther

Re: Problem integrating Crafty with Windows GUI

PostPosted: 09 Sep 2009, 14:59
by ignacioalex
I'm sorry, that's the only line following the White(?): prompt which was not input from my GUI! :) It was output from Crafty while it was pondering on my next move (this is set by the "hard" command).

Below follows a new log file I generated with pondering off (set by the "easy" command), and now everything you see after a White(?): prompt was really input from my GUI.

Thanks,

Alex
--------------------------------------------------

book learning disabled


Crafty v23.0 (1 cpus)

White(1): skill 50
skill level set to 50%
White(1): xboard
White(1): protover 2
feature ping=1 setboard=1 san=1 time=1 draw=1
feature sigint=0 sigterm=0 reuse=1 analyze=1
feature myname="Crafty-23.0" name=1
feature playother=1 colors=0
feature variants="normal,nocastle"
feature done=1
White(1): accepted ping
White(1): accepted setboard
White(1): accepted san
White(1): accepted time
White(1): accepted draw
White(1): accepted sigint
White(1): accepted sigterm
White(1): accepted reuse
White(1): accepted analyze
White(1): accepted myname
White(1): accepted name
White(1): accepted playother
White(1): accepted colors
White(1): accepted variants
White(1): accepted done
White(1): easy
pondering disabled.
White(1): level 0 5 0
game/300 seconds primary time control
White(1): new
White(1): e4
time used: 1.57
book moves {e5, c5, c6, d5}
book 0.0s 1% d5! Nc3
Black(1): d5
time used: 0.00
White(2): exd5
Illegal move: exd5
White(2): quit

Re: Problem integrating Crafty with Windows GUI

PostPosted: 09 Sep 2009, 17:50
by H.G.Muller
So the line starting with Black(1): is also Crafty output?

Could there be carriage returns or other invisible characters appended to the line that makes Crafty reject exd5?

If I were you I first would try it with another engine. E.g. a UCI engine under Polyglot, and then make a Polyglot log.

Re: Problem integrating Crafty with Windows GUI

PostPosted: 10 Sep 2009, 21:48
by ignacioalex
I think I have found the problem: it was a simple issue with Crafty's C code.

I described it in details and posted a fix here:

http://www.talkchess.com/forum/viewtopi ... 549#290549

Thank's for helping out!