Check out Grant Acedrex, our featured variant for April, 2024.


[ Help | Earliest Comments | Latest Comments ]
[ List All Subjects of Discussion | Create New Subject of Discussion ]
[ List Earliest Comments Only For Pages | Games | Rated Pages | Rated Games | Subjects of Discussion ]

Single Comment

A Wizard for GAME-Code Generation. A tutorial on using the Play-Test Applet for automating Game Courier presets.[All Comments] [Add Comment or Rating]
🕸Fergus Duniho wrote on Mon, Dec 28, 2020 06:15 PM UTC in reply to H. G. Muller from 10:25 AM:

What is the recommended way to handle resign (or drawn) in presets that have the checkbox ticked to not include moves in the code?

I don't believe the issue is with that in particular. In tests I just did with Extra Move Chess, resign and drawn worked as they should. Your code does some things differently, which I already mentioned below.

The GAME-code manual says that resign should not be used in code,

That may be a suggestion. I tried it directly in the code, and it did work. It made White resign as soon as he entered his first move.

but when I don't do anything about it, attempts of a user to resign will just draw an 'invalid move syntax' error message.

Is that the precise wording of the error message? Using multiple grep searchs, I did not find any text, PHP, or JavaScript file with code for that error message.

I can of course test for the input command to be 'resign' at the start of the ParseMove subroutine (and for efficiency reasons only do that test on the final move of the sequence, or even defer it to the point where it is rejected as a valid move). But what should I do then?

Yes, it may be a good idea to detect it before processing the move. If you are evaluating moves before playing them on the board, you want to evaluate resign and drawn moves differently. In Extra Move Chess, the code plays each move on the board before evaluating it. This is probably why it has no problem with resign or drawn.

Prefix thismove with MOVE: and offer it for execution?

That's what I would recommend. In general, you should be doing that for every move somewhere in your code.

And what happens to the control flow after that? Will it terminate execution of the remainder of the Post-Move code, or should I explicitly abort execution after it?

The resign, lost, won, and drawn commands all include return, which will exit the run_subroutine() function. This will end the current subroutine, and if the command occurs at the main level, this will end the entire GAME Code program. When moves are automatically included in the code, they are placed at the main level between the Pre-Move and Post-Move subroutine calls. But if you are executing the command from within a subroutine, it will exit only that subroutine, and program execution will continue from the point after that subroutine was called.

I have just modified these commands to exit the program entirely using the same method as the new exit command.

Incidentally, the end and stop commands are not particularly useful here. The end command works only on the main level, and the stop command just returns from the innermost call to run_subroutine(). There is no command for halting program execution from within a subroutine.* The die command uses PHP's exit() function, which exits the whole PHP script, but that's overkill for naturally ending the game. Ideally, you should be using MOVE: at the main level, or when your subroutine comes across resign or drawn, it should exit the subroutine with an error code, and the following code should immediately check whether the error code has been given and take appropriate action at the main level if it has.

* I just added the exit command, which does exit the GAME Code program.