@Fergus: I ran into something strange. The include file for automation with the PTA uses an identifier piececount, like it is an associative array that tells for each piece label how many there are on the board. It is used like
set nr + #nr elem #type piececount;
I cannot find a desciption of it in the GAME-code tutorial, though. Did it ever exist, and is it deprecated? Or has it been a figment of my imagination all the time? I cannot print it either; printr piececount; just prints the word 'piececount'.
The strange thing is that elem #type piececount evaluates to 1 if type has the value K or k. (Which is usually the only value it gets, as it is in a loop that has the purpose of counting the number of royals left, and K is usually the only royal type.) I would not expect that from an undefined variable, and indeed there is one King on the board. If type has the value of a piece label that is not on the board, the value does seem undefined. And apparently 1 + undefined equals 0, which is also strange. But nr ends at 0 because of this, leading to a win claim...
[Edit] For piece types that are on the board, piececount indeed appears to work as one should guess from the name. But for piece types not on the board elem #type piececount appears to evaluate to something strange, rather than 0. I now assigned it to a variable a, and print #a then produces output '#a'. Now I have seen this before for undefined variables, so I expected if not #a: set a 0; endif; to solve the problem, assuming 'undefined' would be interpreted as false. (Or is this a JavaScript expectation?) But not so; the if-statement does not trigger, and adding the undefined variable to a variable nr that already has a non-zero value appears to reset it to 0.
[Edit2] It does work as intended when I do this:
set a elem #type piececount;
set b 0;
if var a:
set b var a;
endif;
set nr + #nr #b; // count them
Using #a instead of var a it just keeps interpreting that as a literal. Can this be simplified to set nr + #nr var a; ? I am afraid to try it, because I already spoiled one GC game by experimenting...
@Fergus: I ran into something strange. The include file for automation with the PTA uses an identifier piececount, like it is an associative array that tells for each piece label how many there are on the board. It is used like
I cannot find a desciption of it in the GAME-code tutorial, though. Did it ever exist, and is it deprecated? Or has it been a figment of my imagination all the time? I cannot print it either; printr piececount; just prints the word 'piececount'.
The strange thing is that elem #type piececount evaluates to 1 if type has the value K or k. (Which is usually the only value it gets, as it is in a loop that has the purpose of counting the number of royals left, and K is usually the only royal type.) I would not expect that from an undefined variable, and indeed there is one King on the board. If type has the value of a piece label that is not on the board, the value does seem undefined. And apparently 1 + undefined equals 0, which is also strange. But nr ends at 0 because of this, leading to a win claim...
[Edit] For piece types that are on the board, piececount indeed appears to work as one should guess from the name. But for piece types not on the board elem #type piececount appears to evaluate to something strange, rather than 0. I now assigned it to a variable a, and print #a then produces output '#a'. Now I have seen this before for undefined variables, so I expected if not #a: set a 0; endif; to solve the problem, assuming 'undefined' would be interpreted as false. (Or is this a JavaScript expectation?) But not so; the if-statement does not trigger, and adding the undefined variable to a variable nr that already has a non-zero value appears to reset it to 0.
[Edit2] It does work as intended when I do this:
Using #a instead of var a it just keeps interpreting that as a literal. Can this be simplified to set nr + #nr var a; ? I am afraid to try it, because I already spoiled one GC game by experimenting...