Page 1 of 1
Winboard and Buddhichal
Posted:
17 Apr 2016, 20:19
by ademkika
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?
Re: Winboard and Buddhichal
Posted:
17 Apr 2016, 21:33
by H.G.Muller
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.
Re: Winboard and Buddhichal
Posted:
17 Apr 2016, 21:42
by ademkika
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'.
Re: Winboard and Buddhichal
Posted:
18 Apr 2016, 08:22
by H.G.Muller
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.
Re: Winboard and Buddhichal
Posted:
18 Apr 2016, 16:33
by ademkika
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?
Re: Winboard and Buddhichal
Posted:
18 Apr 2016, 18:26
by H.G.Muller
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.
Re: Winboard and Buddhichal
Posted:
18 Apr 2016, 19:20
by ademkika
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!!!
Re: Winboard and Buddhichal
Posted:
18 Apr 2016, 22:06
by H.G.Muller
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.
Re: Winboard and Buddhichal
Posted:
18 Apr 2016, 22:41
by ademkika
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)?
Re: Winboard and Buddhichal
Posted:
19 Apr 2016, 07:32
by H.G.Muller
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.
Re: Winboard and Buddhichal
Posted:
27 Apr 2016, 17:54
by ademkika
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?
Re: Winboard and Buddhichal
Posted:
27 Apr 2016, 21:06
by H.G.Muller
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.
Re: Winboard and Buddhichal
Posted:
28 Apr 2016, 22:48
by ademkika
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.
Re: Winboard and Buddhichal
Posted:
28 Apr 2016, 23:18
by H.G.Muller
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?
Re: Winboard and Buddhichal
Posted:
28 Apr 2016, 23:50
by ademkika
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
Re: Winboard and Buddhichal
Posted:
15 Feb 2018, 08:39
by noname003
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.
บุคคลสำคัญการสร้างความมั่นใจ