Debugging a Program Designed For WinBoard

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Re: Debugging a Program Designed For WinBoard

Postby beneficii » 07 Oct 2010, 18:53

H.G.Muller wrote:If it starts with 4 integers, WB considers it thinking output. And if /engineDebugOutput=1, anything the engine sends, no matter how incompliant, should be copied to the debug file. So if it is not there, it means WB did not receive it, which must mean the engine did not actually send it.

Either the engine somehow hangs in the input loop, or the output is not flushed...

In my engines the test for input is like this, however:

Code: Select all
int unbuffered_input(int init)
{
    static int pipe;
    static HANDLE inp;
    DWORD cnt;

    if(init)
    {   inp = GetStdHandle(STD_INPUT_HANDLE);
    } else
    {   if(!PeekNamedPipe(inp, NULL, 0, NULL, &cnt, NULL)) return 1;
        return cnt;
    }
}


I'm not sure. Is WB that different from just opening the EXE? It does not get stuck then, and the engine does send the output and the move.

Also, I know from the debug output on WB, the engine responds properly to the "quit" command even though it was sent during the time the engine should have been thinking. So that would suggest the engine does not get stuck.

As for the input function, I have 2 separate functions, one for when the engine is thinking, and one for when the engine is not thinking.

EDIT: I will test the /engineDebugOutput=1 statement once I get off from work today. Having checked and double-checked the engine output, I'm pretty sure it's correct, but it's still worth a test, I think.

EDIT 2: I should note that in addition, the engine, on the statement right before the statement that calls the search function (this is after the engine gets out of the input loop), sends the statement "# searching" to WB. That DOES show in the debug file.
beneficii
 
Posts: 43
Joined: 07 May 2010, 05:17

Re: Debugging a Program Designed For WinBoard

Postby beneficii » 07 Oct 2010, 21:22

H.G.Muller wrote:Are you sure this rutine write_out is indeed used for ptinting thinking output and move?


I'm sorry, as I did not answer this question: Yes, write_output() is called any time the engine writes output. I think it would be much better just to have the same function for every time you write output, instead of doing different functions or writing the steps multiple times.
beneficii
 
Posts: 43
Joined: 07 May 2010, 05:17

Re: Debugging a Program Designed For WinBoard

Postby beneficii » 08 Oct 2010, 01:22

Ok, I'm trying /engineDebugOutput=1, but it didn't do anything. Does it have to be used in conjunction with /debug?
beneficii
 
Posts: 43
Joined: 07 May 2010, 05:17

Re: Debugging a Program Designed For WinBoard

Postby beneficii » 08 Oct 2010, 02:00

OK, I figured it out. Other than the "# searching" comment which is written right before the search is called (i.e. there is no waiting for input between that comment being written and the search), WB is just not receiving any output from the engine during the search. Now, outside the search WB will receive output, but not in the search. I use the exact same function for writing output whether in or out of the search, the write_output() function. Here is the printing of the engine output (score, node count, etc.):

write_output("%i %i %i %i %s\n", *depth, *score, time_e, *count, pv.c_str());

Here is the sending of the move:

write_output("move %s\n", pmove.c_str());

I mean, this is basically correct formatting and it would not be buffered, just like everything outside of the search calling the same write_output() function is not buffered either, right?
beneficii
 
Posts: 43
Joined: 07 May 2010, 05:17

Re: Debugging a Program Designed For WinBoard

Postby beneficii » 08 Oct 2010, 02:38

Here is the 2 machines debug (with engine debug output on):

Code: Select all
recognized 'omega' (-1) as variant omega
WinBoard 4.4.3 + dachess
Reset(1, 0) from gameMode 0
recognized 'omega' (-1) as variant omega
GameEnds(0, (null), 2)
shuffleOpenings = 0
TC string = '+40/10'
mps=40 tc=600000 inc=0
TC string = '+40/10'
mps=40 tc=600000 inc=0
StartChildProcess (dir="C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\dachess\Release") dachess
656 >first : xboard
protover 2
672 <first :
766 <first : feature ping=1 setboard=1 playother=1 san=0 usermove=1 time=1 draw=1
781 >first : accepted ping
781 >first : accepted setboard
781 >first : accepted playother
781 >first : accepted san
891 >first : accepted usermove
906 >first : accepted time
906 >first : accepted draw
906 <first : feature sigint=1 sigterm=1 reuse=1 analyze=0
906 >first : accepted sigint
906 >first : accepted sigterm
906 >first : accepted reuse
906 >first : accepted analyze
906 <first : feature colors=0 ics=0 name=0 pause=1 nps=0 debug=1 memory=0 smp=0 done=1
906 >first : accepted colors
906 >first : accepted ics
906 >first : accepted name
906 >first : accepted pause
906 >first : accepted nps
906 >first : accepted debug
906 >first : accepted memory
906 >first : accepted smp
906 >first : accepted done
922 >first : new
random
922 >first : variant omega
922 >first : level 40 10 0
922 >first : post
922 >first : hard
922 >first : easy
922 >first : ping 1
922 <first : pong 1
3359 >first : force
StartChildProcess (dir="C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\dachess\Release") dachess
3859 >second: xboard
protover 2
3875 <second:
3875 <second: feature ping=1 setboard=1 playother=1 san=0 usermove=1 time=1 draw=1
3875 >second: accepted ping
3875 >second: accepted setboard
3875 >second: accepted playother
3875 >second: accepted san
3875 >second: accepted usermove
3875 >second: accepted time
3875 >second: accepted draw
3875 <second: feature sigint=1 sigterm=1 reuse=1 analyze=0
3875 >second: accepted sigint
3875 >second: accepted sigterm
3875 >second: accepted reuse
3891 >second: accepted analyze
3891 <second: feature colors=0 ics=0 name=0 pause=1 nps=0 debug=1 memory=0 smp=0 done=1
3891 >second: accepted colors
3891 >second: accepted ics
3891 >second: accepted name
3891 >second: accepted pause
3891 >second: accepted nps
3891 >second: accepted debug
3891 >second: accepted memory
3891 >second: accepted smp
3891 >second: accepted done
3906 >second: new
random
3906 >second: variant omega
3906 >second: level 40 10 0
3906 >second: post
3906 >second: hard
3906 >second: easy
3906 >second: ping 1
3906 >second: force
3922 >first : computer
3922 >second: computer
TC string = '+40/10'
mps=40 tc=600000 inc=0
TC string = '+40/10'
mps=40 tc=600000 inc=0
time odds: 1.000000 1.000000
3922 >first : time 60000
3922 >first : otim 60000
book hit = (NULL)
3922 >first : go
nps: w=-1, b=-1
4078 <second: pong 1
4172 <first : # searching
GameEnds(46, xboard exit, 2)
GE(46, xboard exit, 2) bare king k=22 color=24
Interrupting first
10766 >first : result * {xboard exit}
10781 >second: result * {xboard exit}
10781 >first : force
10781 >first : ping 2
10781 >second: force
10781 >second: ping 2
10781 >first : quit
10844 >second: quit


(The engines quit just fine. Notice the "# searching" comment, but no other output from the search?)

Here is machine white:

Code: Select all
recognized 'omega' (-1) as variant omega
WinBoard 4.4.3 + dachess
Reset(1, 0) from gameMode 0
recognized 'omega' (-1) as variant omega
GameEnds(0, (null), 2)
shuffleOpenings = 0
TC string = '+40/10'
mps=40 tc=600000 inc=0
TC string = '+40/10'
mps=40 tc=600000 inc=0
StartChildProcess (dir="C:\Documents and Settings\Administrator\My

Documents\Visual Studio 2010\Projects\dachess\Release") dachess
625 >first : xboard
protover 2
625 <first :
657 <first : feature ping=1 setboard=1 playother=1 san=0 usermove=1 time=1

draw=1
657 >first : accepted ping
657 >first : accepted setboard
657 >first : accepted playother
672 >first : accepted san
672 >first : accepted usermove
672 >first : accepted time
672 >first : accepted draw
672 <first : feature sigint=1 sigterm=1 reuse=1 analyze=0
672 >first : accepted sigint
672 >first : accepted sigterm
672 >first : accepted reuse
672 >first : accepted analyze
672 <first : feature colors=0 ics=0 name=0 pause=1 nps=0 debug=1 memory=0

smp=0 done=1
672 >first : accepted colors
672 >first : accepted ics
672 >first : accepted name
672 >first : accepted pause
672 >first : accepted nps
672 >first : accepted debug
672 >first : accepted memory
672 >first : accepted smp
672 >first : accepted done
688 >first : new
random
688 >first : variant omega
704 >first : level 40 10 0
704 >first : post
704 >first : hard
704 >first : easy
704 >first : ping 1
719 <first : pong 1
TC string = '+40/10'
mps=40 tc=600000 inc=0
TC string = '+40/10'
mps=40 tc=600000 inc=0
time odds: 1.000000 1.000000
2672 >first : time 60000
2672 >first : otim 60000
book hit = (NULL)
2672 >first : go
nps: w=-1, b=-1
2672 <first : # searching
GameEnds(46, xboard exit, 2)
Interrupting first
18922 >first : result * {xboard exit}
18922 >first : force
18922 >first : ping 2
18922 >first : quit
beneficii
 
Posts: 43
Joined: 07 May 2010, 05:17

Re: Debugging a Program Designed For WinBoard

Postby H.G.Muller » 08 Oct 2010, 05:58

Well, the logical conclusion if you use the same function you know that works for writing the Thinking Output, and it does not appear, that function is never called.

The behavior with WB could be very different as from the command line:

1) PeekNamedPipe could always return a non-null error code when the engine is used from the command line, because the input is not a pipe.
2) output library functions do test if their output is a terminal or a file/pipe, and make buffering decisions based on that.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Debugging a Program Designed For WinBoard

Postby beneficii » 08 Oct 2010, 16:35

H.G.Muller wrote:Well, the logical conclusion if you use the same function you know that works for writing the Thinking Output, and it does not appear, that function is never called.

The behavior with WB could be very different as from the command line:

1) PeekNamedPipe could always return a non-null error code when the engine is used from the command line, because the input is not a pipe.
2) output library functions do test if their output is a terminal or a file/pipe, and make buffering decisions based on that.


This will seem very foolish, but I just solved the problem last night not long before going to bed. I tested with "# comments" to see how far the search got, and you were right, I was using PeekNamedPipe() incorrectly; I rewrote the input function (which I can post later today) to make it more like yours, and it resolved the problem. I matched the computer against itself, and got quite a game out of it (black won, with 102 moves):

[Event "Computer Chess Game"]
[Site "HOME-294D466A0E"]
[Date "2010.10.07"]
[Round "-"]
[White "dachess"]
[Black "dachess"]
[Result "0-1"]
[TimeControl "40/1200"]
[Variant "omega"]
[Annotator "1. +0.45 1... +0.00"]

1. Ch2 {+0.45/6 30} Ng7 {+0.00/6 30} 2. Nb2 {+0.40/6 30} Cc7 {+0.05/5 30}
3. Cc2 {+0.35/5 30} Ch7 {+0.05/5 30} 4. Ng2 {+0.30/5 30} Wj7 {-0.05/6 30}
5. Wj2 {+0.40/5 30} Nd7 {+0.05/5 30} 6. Wa2 {+0.25/5 30} Wi4 {+1.37/6 30}
7. f4 {-1.37/6 30} Wxj1 {+1.37/6 30} 8. Rh0 {-1.68/6 30} Wxg0 {+1.42/6 30}
9. Rxg0 {-1.68/6 30} e6 {+1.60/6 30} 10. e4 {-1.51/6 30} f5 {+1.63/5 30}
11. d3 {-1.55/6 30} Wa7 {+1.74/6 30} 12. Cc4 {-1.77/6 30} Bh5 {+1.93/5 30}
13. c3 {-1.74/6 30} j5 {+1.71/5 30} 14. Wb5 {-1.61/6 30} Ra9 {+1.91/6 30}
15. Bg3 {-1.98/6 30} Bd6 {+2.00/6 30} 16. e5 {-1.75/6 30} Be7 {+1.78/6 30}
17. Ca6 {-2.04/5 30} Qb9 {+2.17/6 30} 18. Wxa8 {-2.17/5 30} Rxa8
{+2.06/6 30} 19. Cxa8 {-2.49/6 30} Qxa8 {+2.22/6 30} 20. Ch4 {-2.22/5 30}
Bf7 {+2.59/6 30} 21. Cf2 {-2.52/5 30} O-O {+2.60/6 30} 22. Nc4 {-2.55/5 30}
Bj3 {+2.76/5 30} 23. Ch2 {-2.57/6 30} b5 {+2.75/6 30} 24. Nce3 {-2.79/6 30}
Wb6 {+2.97/6 30} 25. i2 {-3.16/6 30} Bg6 {+3.27/6 30} 26. c4 {-3.08/6 30}
Qxa1 {+3.61/6 30} 27. cxb5 {-3.60/6 30} Qa5+ {+3.73/6 30} 28. Be1
{-3.59/6 30} Qxb5 {+3.73/6 30} 29. Nc4 {-3.69/6 30} Wc5 {+3.78/6 30} 30.
Wg3 {-3.62/5 30} Ra9 {+3.94/6 30} 31. Nh4 {-3.90/6 30} Bi4 {+4.11/6 30} 32.
Qc2 {-4.12/6 30} Ra1 {+4.11/5 30} 33. Bc3 {-4.06/6 30} Ra7 {+4.06/6 30} 34.
Ng2 {-3.76/6 30} i5 {+3.84/5 30} 35. Wf2 {-3.79/6 30} Bg6 {+3.69/5 30} 36.
Ke0 {-3.62/5 30} Qb8 {+3.75/6 30} 37. Ch3 {-3.69/5 30} i4 {+3.92/6 30} 38.
Cg3 {-3.87/6 30} Qw4 {+3.87/5 30} 39. b4 {-3.43/6 30} Wb8 {+3.34/6 0.7} 40.
Ra0 Rxa0+ 41. Qxa0 {-3.30/6 31} Ki9 {+3.29/5 31} 42. Nd6 {-3.29/5 31} Kj9
{+3.30/6 31} 43. Qw1 {-3.16/5 31} Ci7 {+3.20/6 31} 44. h2 {-3.16/5 31} Nh5
{+3.21/6 31} 45. Ce3 {-3.18/6 31} h6 {+3.32/5 31} 46. i3 {-3.08/6 31} Bh7
{+3.26/6 31} 47. Ne8 {-3.28/6 31} Cc6 {+3.38/6 31} 48. Nd6 {-3.61/6 31} g6
{+3.54/6 31} 49. b5 {-3.54/6 31} Cc7 {+3.80/6 31} 50. Cf3 {-3.75/6 31} Wc5
{+3.87/6 31} 51. Ne8 {-3.80/6 31} Cb7 {+4.29/6 31} 52. Qb1 {-4.29/6 31} Ci5
{+4.29/6 31} 53. d4 {-4.25/6 31} Wb6 {+4.26/6 31} 54. Ba1 {-4.13/6 31} Kw3
{+4.13/6 31} 55. Nd6 {-3.86/6 31} Cc7 {+3.90/6 31} 56. Qc1 {-3.68/6 31} Qb8
{+3.68/6 31} 57. Kd0 {-3.89/5 31} Wc9 {+3.93/5 31} 58. Re0 {-3.88/6 31} Nf8
{+3.80/5 31} 59. Ne8 {-3.43/6 31} Cd7 {+2.76/6 31} 60. Nxc9 {-2.77/6 31}
Qxc9 {+2.75/6 31} 61. b6 {-2.72/6 31} Cb7 {+3.01/6 31} 62. Wc3 {-2.97/6 31}
Nd7 {+3.14/5 31} 63. Wd6 {-1.47/7 31} Bxd6 {+1.93/7 31} 64. exd6
{-2.06/7 31} Cxb6 {+2.06/6 31} 65. Rxe6 {-2.06/6 31} Ng7 {+1.82/6 31} 66.
Re0 {-2.01/7 31} Cxd6 {+2.01/6 31} 67. Nh4 {-2.04/6 31} c7 {+2.25/6 31} 68.
d5 {-2.17/6 31} Nf9 {+2.39/6 31} 69. g2 {-2.39/6 31} Ne7 {+2.72/6 31} 70.
Qd1 {-3.05/6 31} Qh9 {+3.13/5 31} 71. h3 {-3.38/6 31} g5 {+3.46/7 31} 72.
fxg5 {-2.71/7 31} hxg5 {+3.68/7 31} 73. Qj1 {-4.00/7 31} ixh3 {+4.45/7 31}
74. Qj4 {-3.86/6 31} Ci4 {+5.60/7 31} 75. Qh6 {-6.59/7 31} gxh4
{+6.59/7 31} 76. gxh3 {-6.59/7 31} Cg2 {+6.57/7 31} 77. Rj0 {-6.53/7 31}
hxi3 {+6.41/7 31} 78. Rxj5 {-6.35/7 31} Cf2+ {+9.34/7 31} 79. Cxf2
{-9.34/7 31} Qxd5+ {+9.98/8 0.7} 80. Bd4 Bxj5 81. Qi5 {-10.86/7 31} Bh7
{+11.41/7 31} 82. Qh5 {-11.46/8 31} Nf6 {+11.66/8 31} 83. Qd1 {-12.33/7 31}
Ne4 {+12.33/7 31} 84. Ba7 {-12.63/7 31} Qb7 {+12.93/7 31} 85. Qj7
{-12.93/8 31} Bg6 {+13.14/8 31} 86. Be3 {-13.71/7 31} Qb2+ {+14.70/7 31}
87. Kd1 {-14.30/7 31} Nxf2+ {+17.56/7 31} 88. Ke1 {-17.52/8 31} Nxh3
{+17.56/7 31} 89. Qe2 {-17.66/7 31} Qe5 {+17.63/7 31} 90. Bh6 {-17.61/7 31}
Qg3+ {+17.62/7 31} 91. Kf1 {-17.69/7 31} Qg1+ {+20.34/7 31} 92. Ke0
{-20.34/8 31} Nf2+ {+20.24/7 31} 93. Kd0 {-20.48/8 31} Qh0+ {+20.48/7 31}
94. Ke1 {-23.38/8 31} Cd4 {+23.38/7 31} 95. Qf1 {-23.66/8 31} Qxh6
{+23.66/7 31} 96. Qe2 {-31.15/8 31} Qc1+ {+31.15/7 31} 97. Kf0
{-31.37/8 31} Cd2+ {+31.37/7 31} 98. Qxd2 {-31.73/9 31} Qxd2+ {+31.58/8 31}
99. Kg1 {-99.92/9 31} Nh3+ {+31.77/8 31} 100. Kf1 {-99.94/9 31} Qd1+
{+99.95/8 31} 101. Kg2 {-99.96/9 31} Qg1+ {+99.97/8 31} 102. Kxh3
{-99.98/9 31} Qh2# {+99.99/9 30}
{Xboard adjudication: Checkmate} 0-1


Now, this engine is written to play a commercial chess variant, so I don't know if there might be legal issues with releasing it. I've tried contacting the copyright holders, but got no response. What do y'all think?

Thanks for all your and Dann Corbitt's help! :D
beneficii
 
Posts: 43
Joined: 07 May 2010, 05:17

Re: Debugging a Program Designed For WinBoard

Postby H.G.Muller » 08 Oct 2010, 17:43

Yo would have to figure out if Omega Chess is protected by a patent (and if so, in which countries), and if it is a registered trademark. It cannot be protected by copyright, as you are not copying anything. If it is a trademark you will not be allowed to use it, but you can simply rename it (e.g. 'Wizzard Chess'). If it is a patent, it would likely cover software that plays it too, and there is not much you can do.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Debugging a Program Designed For WinBoard

Postby Dann Corbit » 08 Oct 2010, 19:49

I am glad to see that you got things working.
Sometimes very simple problems are the really hard ones to solve.
Dann Corbit
 

Re: Debugging a Program Designed For WinBoard

Postby beneficii » 08 Oct 2010, 23:42

H.G.Muller wrote:Yo would have to figure out if Omega Chess is protected by a patent (and if so, in which countries), and if it is a registered trademark. It cannot be protected by copyright, as you are not copying anything. If it is a trademark you will not be allowed to use it, but you can simply rename it (e.g. 'Wizzard Chess'). If it is a patent, it would likely cover software that plays it too, and there is not much you can do.


Some good news in that department. On their website, they list their trademark, copyrights, and patents, all of which is registered in the USA.

For the trademark, any usage of it in the WinBoard code (as in VariantOmega) would seem to be nominal use (that is, it simply describes the set of rules it is using), because it is not misleading users that this is from the Omega Chess company itself or in any way representing them. I am not titling either one "Omega Chess," only that I would be describing that WinBoard supports the Omega Chess rules, and that dachess (my engine) is designed to play Omega Chess. As I've read, a simple description that something supports a trademarked product is not a violation of the trademark, at least not in the U.S.

The copyrights are for the wizard and champion "character[s]" and fall under Visual Material. I don't think this applies to the engine or to the WinBoard GUI, which has my own original drawings of the 2 new pieces--in other words, I didn't copy the pieces. (The Omega Chess website also provides fonts downloadable for free that they say you can use in newspapers in the like.)

The patents are for the "ornamental design" of the "chess piece head[s]" of the wizard and champion. No other patents are mentioned on the website and I can find no other patents relating to Omega Chess on the Patent Office's website.

Because of this, and because they ignored me when I told them I already made WinBoard able to play Omega chess, it seems that it's fine to use this engine and the version of WinBoard that supports Omega Chess.
beneficii
 
Posts: 43
Joined: 07 May 2010, 05:17

Re: Debugging a Program Designed For WinBoard

Postby beneficii » 08 Oct 2010, 23:43

Dann Corbit wrote:I am glad to see that you got things working.
Sometimes very simple problems are the really hard ones to solve.


Thanks. ^_^ I found out my program was sending the time elapsed to the engine in milliseconds instead of centiseconds. I'm
glad that things like that are now my biggest concerns. :mrgreen:
beneficii
 
Posts: 43
Joined: 07 May 2010, 05:17

Previous

Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 19 guests