Compiling ChessV 9.2

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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

Re: Compiling ChessV 9.2

Post by hgm »

smrf wrote:ChessV sometimes seems to switch colors when under pressure. I reported that repeatedly to its author. Maybe because of an errornous undo of moves, when potential mates will occur. But ChessV's author did not provide any corrected version since then, thus I stopped any testing of SMIRF vs. ChessV. Moreover the SMIRF project is sleeping ...
OK, so this is a known error in ChessV, then. I suspected such. This means that we can consider the conversion of ChessV to a WinBoard engine now complete.

I am going to give up debugging this, as the error seems to be burried very deep in ChessV. What I found out is this:

When ChessV gets a fail high in the root, it re-searches with an open window. This re-search then only searches the first move, and the routine list.MakeNextMove() fails on the second move. At least it says it does, but it is lying, as it did actually make the move. The move loop of SearchRoot() then thinks it is done, and returns without unmaking. (Because it assumes no move was made.)

The nex iteration of Think() then starts from a different position, with the other side to move, and (when after some more iterations time has run out) eventually will produce a move for the wrong side. On the ChessV board display I could see that both moves were made.

The version I have now should handle promotions automatically, and seems to behave reasonable at all WinBoard time controls. It is a 'Release' compile, which reaches reasonable depth (similar to Fairy-Max). The only thing it does not support is setting up a position. It can be downloaded (together with the modified source files) at:

http://home.hccnet.nl/h.g.muller/ChessV.zip
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Compiling ChessV 9.2

Post by hgm »

Strange, look at this game. It seems like ChessV is totally blind to promotions. I let it post now, so that WinBoard can put the ChessV depth/score in the PGN, and up to the last move before the promotion ChessV still thinks it is in the lead!

Code: Select all

[Event "Computer Chess Game"]
[Site "CHESS_LAPTOP"]
[Date "2009.09.24"]
[Round "-"]
[White "ChessV"]
[Black "Fairy-Max 4.8L"]
[Result "0-1"]
[TimeControl "40/300"]
[Variant "capablanca"]
[Annotator "1. -0.02   1... +0.25"]

1. Nc3 {-0.02/8 6} e6 {+0.25/7 4} 2.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+0.59/8 3}
33. Ce3 {+1.36/8 6} Qa4 {+0.47/7 1.4} 34. Nf4 {+1.77/8 8} Qxd4 {+0.17/8 3}
35. Nxg6+ {+1.94/7 8} hxg6 {+0.16/9 5} 36. Cd3 {+2.02/7 7} e5 {+0.13/9 2.1}
37. Cxd4 {+2.18/7 8} exd4 {-0.51/11 2.9} 38. Rfe1 {+1.89/8 7} d5
{-0.43/11 3} 39. c3 {+1.84/8 7} dxc3 {+0.28/10 4} 40. Rxc3 {+1.64/8 8} Kd6
{+0.36/10 5} 41. Rh3 {+1.96/7 5} j5 {+0.36/9 5} 42. Rh7 {+2.36/9 7} Rg8
{-0.58/11 4} 43. Ri7 {+2.44/9 6} Ng5 {-0.75/11 7} 44. Kh1 {+2.46/8 6} Nf3
{-0.64/10 4} 45. Re3 {+2.63/8 5} Ne5 {-0.62/10 5} 46. Rxi6 {+3.19/8 6} c6
{-0.60/11 57} 47. Ra3 {+3.57/8 5} d4 {-1.22/10 5} 48. Rj6 {+3.88/7 5} d3
{+0.22/11 4} 49. Ra4 {+3.82/6 6} Kd5 {+0.54/11 7} 50. Rxj5 {+2.94/7 5} d2
{+5.96/14 6} 51. Rxe5+ {+1.23/6 7} Kxe5 {+8.53/13 10} 52. i3 {+0.90/6 7}
d1=Q+ {+14.12/11 7} 53. Kg2 {-3.59/5 8} Qxa4 {+14.33/10 9} 54. h3
{-5.84/6 7} Qxa2+ {+15.40/8 2.2} 55. Kg3 {-999.98/12 4} Qxj2 {+17.52/9 7}
56. g5 {-999.98/12 2.8} Rf8 {+79.96/10 2.4} 57. h4 {-999.98/12} Rf2
{+79.97/28 2.2} 58. h5 {-999.99/12} Qh2+ {+79.98/28} 59. Kg4 gxh5#
{+79.99/28}
{} 0-1
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Compiling ChessV 9.2

Post by hgm »

It seems I can work around the bug by preventing fail high in the root: I now do all root searches with a fully open window. This seems to make ChessV play a lot better as well. Perhaps even when there is no color change on re-search, it could still play a random move. My guess is the problem is in move sorting. But the open-window trick avoids it.

Occasionally ChessV seems to ignore the input move. I have seen that twice now, both times when the input move was castling. Most castlings are accepted without problems, though.

The other obvious problem is that it seems blind to promotions in its search. People tell me tht ChessV 0.9.0 was less buggy than 0.9.2. Is this true? If so, can it be obtained anywhere?
User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 6:57 pm
Location: Washington, DC

Re: Compiling ChessV 9.2

Post by Greg Strong »

Yes, earlier versions didn't have the color-change problem. I'm not sure exactly which version introduced the problem, but 0.9 is fine I'm told. It can be downloaded here:

http://samiam.org/chessv/

I am going to take a look right now and do source code comparisons on the the two versions now and try to figure out what I changed that caused it.

Congratulations on getting it working with Winboard, H.G. I didn't realise you could just call WinMain from a console app and let all the windows run ... Sorry you've had so many problems. I pretty much stopped working on the code once I reached a point where I had wished that I had done almost everything differently. But now that there is interest, I'll put in some hours and turn out another good version (with source) folding winboard support into the main code base. Releasing a new version this weekend shouldn't be a problem...
User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 6:57 pm
Location: Washington, DC

Re: Compiling ChessV 9.2

Post by Greg Strong »

Ok, it looks like I changed the aspiration window code and screwed it up. Don't remember at all why I changed it, but I've put it back. I also reverted the code for the transposition table back because I had made some unfortunate changes to that also.

Also, I've rolled in all the command line/winboard support code written by H. G. as a separate build option. Thanks for doing this, H. G.!

I've got a couple of tiny things I still want to, and, of course, a little testing. I anticipate releasing the new version tomorrow evening.
xqcm168

Re: Compiling ChessV 9.2

Post by xqcm168 »

Greg Strong wrote:I've got a couple of tiny things I still want to, and, of course, a little testing. I anticipate releasing the new version tomorrow evening.
Waiting for your good news. :D
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Compiling ChessV 9.2

Post by hgm »

Greg Strong wrote:Also, I've rolled in all the command line/winboard support code written by H. G. as a separate build option. Thanks for doing this, H. G.!
I tried to arrange it in such a way that, when called without a command-line argument, ChessV would behave in exactly the same way as before. (I.e. not startup the input thread that looks at its stdin, and suppress the print statements to stdout.)

When run with an argument it seems to have a little quirk, though: when it s terminated from the WB interface through a quit command, it uses exit() to kill the entire app. But when you try to kill it by clicking the close button on the GUI (which you should not do when you run it under WinBoard, but you could do it by mistake), it kills the GUI thread, but not the console I/O thread.

The thing that is still sadly missing from WB protocol is the edit-position command (either setboard <FEN> or edit). This because it seemed ChessV did not support setting up a position, and it would require intricate knowledge of its internal game representaton to write one from scratch.

The most wrecking thing for its playing strength is currently that it does not see promotions coming; I hope you can fix that.

A practical problem is the naming of pieces, and how to indicate them in WB-protocol promotion moves. I currently use the moveInfo.promotion->GetFullName() method to understand the ChessV promotion moves, where I use the algorithm that a piece called "Knight" will be represented by 'n', and any other piece by its (decapitalized) initial character. This works for Capablanca, but there is in general no guarantee that no two pieces will start with the same character. And it causes problems when trying to run, (say) Schoolbook Chess as WB variant capablanca, because a Chancellor in Schoolbook Chess is caled a Marshall. Now the piece letters in WB can be configured as well, and the defaults actually are, on a per-variant basis, but unfortunately not on a per-engine basis. So configuring the R+N piece in WB as 'M' would solve the problem for ChessV "Schoolbook Chess", but then the opponent engine will likely not understand the promotion moves, unless it is also configurable in this respect (such as Fairy-Max). I guess the ultimate solution here is that I should allow the pieceToCharTable of WB to be set differently for each engine (as well as for PGN/FEN), which is not a ChessV problem. But a possible ambiguity of the letter-to-piece assignment should be solved in ChessV. Is there a beter way to obtain a suitable promotion character for a piece that is guaranteed to be unique within that variant?

One other minor issue: When I was adding printing of the WB RESULT command (1-0, 0-1 or 1/2-1/2) I got the impression that one of the popups you have ChessV show in native mode was the wrong way around. (Mentioning the same player as winner for a score-wise opposite case.) This code in ChessV is a bit messy, no doubt because it accumulated over time as you added more variants with non-standard winning conditions (I had the same problem in WB, when I wanted to make it determine that game result). Perhaps it would be good to replace it by a single end-of-game-test routine (that could be called both before and after the computer starts thinking, and after entering of a user move). You could independently determine a result (WhiteWins, BlackWins, Draw) and a reason string (checkmate, stalemate, king destroyed, bare king, check, insufficient mating material), that would then be used to print a WB result or format a message popup. It would then be much easier to keep the WinBoard patch localized; now I had to scatter printf calls all over the place in Board.cpp, and I am still not sure that I did it everywhere correctly.
User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 6:57 pm
Location: Washington, DC

Re: Compiling ChessV 9.2

Post by Greg Strong »

Setting up the board: ChessV does allow you to set up the board for beginning the game from a custom array. You do this by loading a save-game file (text file with SGF extension.) These files are not only for saving games in progress, but also for specifying customizations to games. You can change the piece starting positions, piece names, the evaluation of pieces, and even some rules (such as changing the castling rule in effect.) To change the array, you would add a line to the file like:

Code: Select all

$array = "rbqnkgnebr/pppppppppp/10/10/10/10/PPPPPPPPPP/RBQNKGENBR"
Note that the FEN can only have the pieces, not castling rights or 50-move counter or anything like that, as the purpose of the FEN code is only for specifying custom starting arrays, not for setting up mid-game positions. This is one of the small additions I'm putting into the winboard-compatible release - the ability to specify the filename of an SGF file instead of the name of a variant on the command line. You might want to use this, for example, for Schoolbook Chess matches where the other engine doesn't support the flexible castling rule. You would turn it off by loading the following SGF file:

Code: Select all

Schoolbook Chess
$castling-type = "standard"
I may also add code to receive the Winboard setboard command and translate that to an $array setting as long as the game hasn't started. ChessV doesn't allow you to edit the board of games in progress for reasons too boring to explain but basically boiling down to the fact that parts of the code are kind of sucky. For a full description of what you can do with a SGF file, see the extensability.doc file that comes with ChessV.

Not seeing promotions: Don't know what's up with this. Hopefully it was just a bug introduced when I changed the hashtable code which has now been reverted to the old version. Once that's fixed, probably the biggest problem related to playing strength will be the almost complete absence of any reasonable king safety code.

Naming of pieces/promotion notation: Now this ChessV actually handles very well. You need only call GetNotation() instead of calling GetFullName(), taking the first letter, and special-casing the Knight. These functions use the correct names/notations for the given variant (e.g., "Marshall" in Schoolbook) and have rules to ensure uniqueness/parsability... The notation must be unique within the variant, and two-character notations are accepted (which would be necessary in games with lots of piece types such as Chess with Different Armies, for example.) For a two-character notation, you can use the two characters directly if the first letter isn't already used for as a notation for another piece type. If it is, you put an underscore in front of it which simply tells ChessV that it is a two-character notation; the underscore is never displayed to the user.

End-of-game code: You're right, there is complicated code in lots of places to catch different end-of-game conditions, and it's lousy for exactly the reasons you specify. I think you did put the correct code in all the places you needed to - I'm sure that was a pain in the butt... it was a pain in the butt to merge it all in :) You said my code might be backwards on one of them. It certainly could be; I'll double check them!

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

Re: Compiling ChessV 9.2

Post by hgm »

Well, I guess that editing the position always implies a new game, so that is no problem. (WinBoard also clears its own internal game history when the user uses the edit-position menu.) WinBoard sends the setboard command only directly after the "new" and "variant" commands, when the default array is not used. The latter is of course always the case in shuffle games, where there is no default array.

So there is nothing against ChessV interpreting the setboard command as a "new" command with a different array.

WinBoard currently does not allow 2-character piece names, so I guess we should just hope this does not cause problems in practice in promotions.

Btw, ChessV does not support Knightmate???
User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 6:57 pm
Location: Washington, DC

Re: Compiling ChessV 9.2

Post by Greg Strong »

Ok, ChessV 0.9.4 is now available. It fixes the problems with the crashes and changing of colors, and incorporates Winboard support. It can be downloaded from http://www.samiam.org/chessv

Sorry, it doesn't support Knightmate, although it wouldn't be difficult to add. There are thousands of variants, and that one's pretty obscure ... I could add it to the next version, but didn't want to hold up the release.

Enjoy!