Winboard and Buddhichal

Discussions about the WinBoard protocol. Here you can also report bugs and request new features.

Moderators: hgm, Andres Valverde

Winboard and Buddhichal

Postby ademkika » 17 Apr 2016, 20:19

Hi to all,

I'm using buddhichal to comunicate with Matlab to send moves into Winboard but how can I get some extra information like when it is in checkmate or when I write in 'out.txt' an illegal move it stop the games, how can I handle these things?
ademkika
 
Posts: 8
Joined: 17 Apr 2016, 16:34

Re: Winboard and Buddhichal

Postby H.G.Muller » 17 Apr 2016, 21:33

WinBoard will send a 'result' command to the engine (which according to the Buddhichal description should appear in the out.txt file) when the game finishes. That should include checkmate.

When the engine sends an illegal move, WinBoard will forfeit the engine if legality testing is on. This will also cause a 'result' command to be sent to the engine.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Winboard and Buddhichal

Postby ademkika » 17 Apr 2016, 21:42

No it doesn't send the information in out.txt. For example if i take a figure in winboard it's this 'AxA6' where X present that a figure is not there and in out.txt is for example 'usermove A8A6'.
ademkika
 
Posts: 8
Joined: 17 Apr 2016, 16:34

Re: Winboard and Buddhichal

Postby H.G.Muller » 18 Apr 2016, 08:22

I don't understand what you are doing. Are you playing as a human against Buddhichal, and making a move with the mouse on WinBoard's display? In that case WinBoard should only accept legal moves, and illegal moves would not even be sent to the engine (Buddhichal). What is AxA6? Was that a move that delivered checkmate? What is 'not there'?

When you start WinBoard with the 'Additional option' (in the Startup dialog) -debug it will create a file winboard.debug, in which you can see what exactly it sent to Buddhichal. If it does not terminate the game on checkmate it could be that 'Detect mates' in the Adjudication Options menu dialog is not ticked.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Winboard and Buddhichal

Postby ademkika » 18 Apr 2016, 16:33

Lets make things clear. I'm trying to make a chess playing robot, and to send human moves to computer I'm using buddhichal chess engine since it supports sending moves and getting computer moves through .txt files, respectively out.txt and in.txt files, while all xboard output messages are saved in dump.txt file.

The problem is that, if human makes an invalid move, and his move is sent through buddhichal using out.txt file then winboard shows a dialog which says that there is an invalid move, and both clocks are stopped, the game is over. But I wanna avoid that, I don't wanna end the game but I just wanna say to the user that "Hey you made this invalid move, so go back to previous state and make another move" and continue the game where is left without touching something at Winboard. I can continue the game where is left using Ctrl + T command which resets clocks, but that means something has to be done using mouse or keyboard (which I wanna avoid), is there any command that I can send which set new time to clocks?!

The other problem is that when computer check mates against human, no messages (outputs) are generated, only at Move History. I tried -debug option and checked winboard.debug file but there wasn't any information which tells if there is checkmate.

So is there any workaround that could help me, or I should add some code at Winboard application?
Last edited by ademkika on 18 Apr 2016, 18:31, edited 1 time in total.
ademkika
 
Posts: 8
Joined: 17 Apr 2016, 16:34

Re: Winboard and Buddhichal

Postby H.G.Muller » 18 Apr 2016, 18:26

If you want WinBoard to do that, I am afraid you would have to add code to it. WinBoard does not have a mode where it lets an engine that makes an illegal move take the move back. This because with a real engine (for which WinBoard is designed) that almost always means the engine just repeats the same illegal move again, and that would then go on forever.

Of course it would likely be simpler to add code to Buddhichal to check the move legality, so that it only passes legal moves to WinBoard. If the user does an illegal move iBuddhichal could then send a "telluser" command to WinBoard instead to make WinBoard pop up a dialog with the request the user to take the move back and play a legal one instead.

WinBoard has undocumented options /firstPseudo and /secondPseudo, which tell it that the first or second engine is not a real engine but a communication device disguised as engine that should have more power thannormal engines. If such an option is used WinBoard will accept 'time' and 'otim' commands (normally sent in the other direction) from the engine to synchronize the clocks.

WinBoard should send a command "result 1-0 {XBoard adjudication: checkmate}" to the engine when a game ends in checkmate, when 'Detect mates' is switched on.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Winboard and Buddhichal

Postby ademkika » 18 Apr 2016, 19:20

In Winboard, on a normal play between human and chess engine, on drag&drop there is a control that checks for illegal move and if there is an illegal move Winboard shows an error. Can I use the same method for for testing moves sent from human through buddhichal before sending move command to Winboard? Im really having difficulties at compiling Winboard!!!
ademkika
 
Posts: 8
Joined: 17 Apr 2016, 16:34

Re: Winboard and Buddhichal

Postby H.G.Muller » 18 Apr 2016, 22:06

When a human makes an illegal move WinBoard refuses the move, and tells the human so. Because from a human you can expect he will change the move now he knows it is illegal. On engines this is pointless. When you force them to take the move back and let them think again, they would just do the same illegal move. So WinBoard never does that.

I am sorry, but you are trying to use a piece of software for something it was not designed for. You should not be surprised if that does not work. The only reason you can do this at all is that Buddhichal is mediating between Mathlab and WinBoard, and it is Buddhichal's task in this setup to transform the output of Mathlab into something that will have the desired effect on WinBoard. If sending illegal moves to WinBoard cannot have the desired effect, Buddhichal should not do it.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Winboard and Buddhichal

Postby ademkika » 18 Apr 2016, 22:41

Haha, I think we're having a misunderstanding (correct me if I'm wrong). I'm trying to do this whole thing (that you're trying me to help) to tell the human for illegal moves or checks from other engine (which one I don't care for).

Buddhichal send humans move to Winboard, so if there is any illegal move, human will be notified and wont make the same illegal move again. Anyway, I have to make a workaround so thank your for your time, I really appreciate it.

Any hint for compiling Winboard (last question)?
ademkika
 
Posts: 8
Joined: 17 Apr 2016, 16:34

Re: Winboard and Buddhichal

Postby H.G.Muller » 19 Apr 2016, 07:32

The WInBoard source tar ball contains a makefile.gcc for compiling with gcc under Cygwin. But it works only for gcc 3.4.4 (which is what I am using), and the newer Cygwin C compilers do not understand the option -mno-cygwin anymore.

You could try to compile it with a MinGW compiler, after removing the -mno-cygwin option from the makefile.gcc. But I have never tried that myself.

Would it be sufficient for your needs when WinBoard would respond to an illegal move from an engine by sending "undo" back to that same engine (instead of forwarding the move to the opponent engine, which it would normally do)? I have a pretty clear idea what should be changed to achieve that. (In the routine 'HandleMachineMove' in backend.c, after it has established by calling ParseOneMove that the move was illegal.) The problem is that Buddhichal might not do anything with that "undo" command. You could also just let WinBoard pop up an error message to warn the user by calling DisplayMessage(), (Or DisplayMoveError?) and perhaps let it make a sound, and ignore the move otherwise. But then, when the human would take the move back in response to the popup, Mathlab would think it is another move, and send that through WinBoard too, which would again lead to the same popup and sound. Plus that I am not sure whether the popups would ever disappear without clicking their OK button or the board display. WinBoard does have a mode where move errors do not lead to a popup, but are printed in the message field above the board, though.

If you know exactly what you want changed, but are not able to compile it, I can make a compiled version for you.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Winboard and Buddhichal

Postby ademkika » 27 Apr 2016, 17:54

I was able to compile WInboard and I was able to write messages that are printed above the board (which you mentioned) to a text file, which helps me to detect whether there is for example "check" (which means opponent should check his king cause its in danger). So far so good, the only thing left that I need is that on illegal move made by human (supposing human its playing for the first time) i want to warn user and allow him to remake his move (legal move). In file backend.c i founded code which check is message gotten by machine (in my case buddhichal) is "move" and if so winboard tries to execute that move. Inside this if statement ther is this code
Code: Select all
if (!ParseOneMove(machineMove, forwardMostMove, &moveType,
                              &fromX, &fromY, &toX, &toY, &promoChar)) {
       /* Machine move could not be parsed; ignore it. */
     snprintf(buf1, MSG_SIZ*10, _("Illegal move \"%s\" from %s machine"),
          machineMove, _(cps->which));
       DisplayMoveError(buf1);
            snprintf(buf1, MSG_SIZ*10, "Xboard: Forfeit due to invalid move: %s (%c%c%c%c via %c%c) res=%d",
                    machineMove, fromX+AAA, fromY+ONE, toX+AAA, toY+ONE, killX+AAA, killY+ONE, moveType);
       if (gameMode == TwoMachinesPlay) {
         GameEnds(machineWhite ? BlackWins : WhiteWins,
                       buf1, GE_XBOARD);
       }
which checks for move legality. In this if statement if move is illegal game ends, but i dont want to end, I want to replace code for game ending with code which scans for a new move command by buddhichal (newest move) and till:
Code: Select all
ParseOneMove(machineMove, forwardMostMove, &moveType,
                              &fromX, &fromY, &toX, &toY, &promoChar)
returns true, which means move is llegal (which since is a human move its supposed that second or third move must be legal). I hope i made my self clear. Any idea how to add this "recursivity" thing?
ademkika
 
Posts: 8
Joined: 17 Apr 2016, 16:34

Re: Winboard and Buddhichal

Postby H.G.Muller » 27 Apr 2016, 21:06

As WinBoard hasn't really done anything that left a permanent impression at this point, you can just do a 'return;' to abort any further handling of the illegal move. That causes the move to be completely ignored. If Buddhichal sends another move, (hopefully a legal one this time) it will cause WinBoard to call HandleMachineMove again.

You coulld alter the message in buf1 that you show through DisplayMoveError in "Illegal move, please take it back and make another one" (as the user is probably not really interested in the name of the machine that made it). You could also call PlayIcsAlarmSound(), and set that sound to something scary (like 'Penalty' or 'Laser') through the Sound menu to attract the player's attention. Or set it to an external WAV file in which you recorded a spoken message requesting a takeback.

You should probably take measures to prevent that Bhuddichal would interpret the takeback itself already as another move. It would of course be illegal again, but that would lead to a second error message.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Winboard and Buddhichal

Postby ademkika » 28 Apr 2016, 22:48

I first tried removing the code that ends the game but buddhichal excepts a message from opponent engine in a form "usermove ..." in order to read the text file and send the new move to Winboard again. So i wanted to force buddhichal for reading and sending a new move to Winboard by trying to send a fake command that could tell buddhichal that its his turn to send a new move. I tried these two commands
Code: Select all
SendToProgram("usermove", cps);
         SendToICS("usermove");
but its not working.
ademkika
 
Posts: 8
Joined: 17 Apr 2016, 16:34

Re: Winboard and Buddhichal

Postby H.G.Muller » 28 Apr 2016, 23:18

SendToICS won't do anything, as you are not connected to an ICS.

What exactly is not working? Have you looked in the winboard.debug file to see what WinBoard sends to Buddhichal? Perhaps Buddhichal is not working as you expect it to. "usermove" without a move is not a valid WB protocol command. And are you sure a linefeed is appended to it?
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Winboard and Buddhichal

Postby ademkika » 28 Apr 2016, 23:50

Its working now. Thank you so much for your help, really thank you. I changed this block of code
Code: Select all
if (!ParseOneMove(machineMove, forwardMostMove, &moveType,
         &fromX, &fromY, &toX, &toY, &promoChar)) {
         /* Machine move could not be parsed; ignore it. */
         snprintf(buf1, MSG_SIZ * 10, _("Hey human you made an illegal move \"%s\"..."),
            machineMove, _(cps->which));
         DisplayMoveError(buf1);
         /*snprintf(buf1, MSG_SIZ * 10, "Xboard: Forfeit due to invalid move: %s (%c%c%c%c via %c%c) res=%d",
            machineMove, fromX + AAA, fromY + ONE, toX + AAA, toY + ONE, killX + AAA, killY + ONE, moveType);*/
         if (gameMode == TwoMachinesPlay) {
            /*GameEnds(machineWhite ? BlackWins : WhiteWins,
            buf1, GE_XBOARD);*/
         }
         SendToProgram("usermove\n", cps); //added this to fake a usermove so that buddhichal could send a new move with "\n was necessary i think"
         return;
      }
. Thank you again :)
Last edited by ademkika on 29 Apr 2016, 00:22, edited 1 time in total.
ademkika
 
Posts: 8
Joined: 17 Apr 2016, 16:34

Re: Winboard and Buddhichal

Postby noname003 » 15 Feb 2018, 08:39

ademkika wrote:I was able to compile WInboard and I was able to write messages that are printed above the board (which you mentioned) to a text file, which helps me to detect whether there is for example "check" (which means opponent should check his king cause its in danger). So far so good, the only thing left that I need is that on illegal move made by human (supposing human its playing for the first time) i want to warn user and allow him to remake his move (legal move). In file backend.c i founded code which check is message gotten by machine (in my case buddhichal) is "move" and if so winboard tries to execute that move. Inside this if statement ther is this code
Code: Select all
if (!ParseOneMove(machineMove, forwardMostMove, &moveType,
                              &fromX, &fromY, &toX, &toY, &promoChar)) {
       /* Machine move could not be parsed; ignore it. */
     snprintf(buf1, MSG_SIZ*10, _("Illegal move \"%s\" from %s machine"),
          machineMove, _(cps->which));
       DisplayMoveError(buf1);
            snprintf(buf1, MSG_SIZ*10, "Xboard: Forfeit due to invalid move: %s (%c%c%c%c via %c%c) res=%d",
                    machineMove, fromX+AAA, fromY+ONE, toX+AAA, toY+ONE, killX+AAA, killY+ONE, moveType);
       if (gameMode == TwoMachinesPlay) {
         GameEnds(machineWhite ? BlackWins : WhiteWins,
                       buf1, GE_XBOARD);
       }
which checks for move legality. In this if statement if move is illegal game ends, but i dont want to end, I want to replace code for game ending with code which scans for a new move command by buddhichal (newest move) and till:
Code: Select all
ParseOneMove(machineMove, forwardMostMove, &moveType,
                              &fromX, &fromY, &toX, &toY, &promoChar)
returns true, which means move is llegal (which since is a human move its supposed that second or third move must be legal). I hope i made my self clear. Any idea how to add this "recursivity" thing?


Thank you for help. :D

บุคคลสำคัญ

การสร้างความมั่นใจ
noname003
 
Posts: 4
Joined: 14 Feb 2018, 03:51


Return to WinBoard development and bugfixing

Who is online

Users browsing this forum: No registered users and 10 guests