Comments/Ratings for a Single Item
I have the following script, without any result:
function BadZone(toFile, toRank, pieceType, color, fromFile, fromRank) { if(pieceType != 14) return 0; if(imi != 1 && imi != 2) return 0; return (fromRank != (color ? toRank + 1 : toRank - 1)); }

Well, that looks OK. If you would post a link to the page where you have it, I could have a look at it, and maybe we could have some progress...
These are the articles in question:
https://www.chessvariants.com/rules/grand-apothecary-chess-alert
https://www.chessvariants.com/rules/grand-apothecary-chess-classic
https://www.chessvariants.com/rules/grand-apothecary-chess-modern
Any of them would do.

OK, I found the problem. It turns out that the variable 'imi' was copied directly from the board, where it also contains color and highlighting information, besides the piece type. So these bits have to be stripped first by taking (imi & 511) to be left with the type. I suppose I should change the Diagram script to already do this by itself when storing imi, rather than when using it. For now you can fix it by using
<script> function BadZone(toFile, toRank, pieceType, color, fromFile, fromRank) { if(pieceType != 14) return 0; if((imi & 511) > 2) return 0; return (fromRank > toRank + 1 || fromRank < toRank - 1); } </script>
This also fixes the problem that the highlighting function is also called to highlight the selected piece itself (so that fromRank equals toRank), and we don't want to suppress that. So I changed the test for suppressing only moves of more than 1 rank.
Note that it still wouldbe able to e.p. capture when imitating a pawn.
The longer moves are still shown. I'm not sure if the ai internally makes only 1 step moves. The enpassant and promotion rights are probably still there needing more BadZone functions, probably.
Also all these things should be done manually in the game courier generated script. Isn't that true?

I can confirm that the BadZone function has no effect in the page at the link you gave. The weird thing is that when I ask the page source of that page, copy the Diagram in it to a local HTML page on my own computer, and open it in the browser, the distant moves do get suppressed. I have no idea why it doesn't work on your page. If I look in the browser console I do not get any error messages from the JavaScript on your page.
The problem is that I cannot experiment on your page; only you have access to it. This is why I copied to my own computer, but the copy shows no errors, so there is nothing to debug. Perhaps you can try the following: add as a first line in the BadZone routine the line
return 1;
This should suppress every move of every piece, and even prevent the highlighting of the piece itself. If that has no effect, I am pretty sure that the routine BadZone never gets called.
When I had put return 1 all moves where indeed suppressed.
Is there a mail of yours where I can send my password to you, so you can work on it? Then after you are done I just change the password.

OK, so the routine is in fact called. Try the following. Below the script add a place where we can print debug output:
<p id="debug"></p>
Then inside the BadZone routine add a line
document.getElementById("debug").innerHTML += 'BadZone(' + toFile + ',' + toRank + ',' + pieceType + ',' + color + ',' + fromFile + ',' + toFile + ') imi =' + imi + '<br>';
Then we can get an impression of what goes wrong.
I get these errors, after a few moves:
BadZone(3,3,1,0,undefined,3) imi =undefined BadZone(3,4,1,0,undefined,3) imi =undefined BadZone(3,5,1,0,undefined,3) imi =undefined BadZone(3,6,1,0,undefined,3) imi =undefined BadZone(3,4,1,0,undefined,3) imi =undefined BadZone(3,5,1,0,undefined,3) imi =undefined BadZone(3,6,1,0,undefined,3) imi =undefined BadZone(1,4,1,0,undefined,1) imi =undefined BadZone(1,5,1,0,undefined,1) imi =undefined BadZone(1,6,1,0,undefined,1) imi =undefined BadZone(4,4,1,0,undefined,4) imi =undefined BadZone(4,5,1,0,undefined,4) imi =undefined BadZone(4,6,1,0,undefined,4) imi =undefined BadZone(7,4,1,0,undefined,7) imi =undefined BadZone(7,5,1,0,undefined,7) imi =undefined BadZone(7,6,1,0,undefined,7) imi =undefined BadZone(8,4,1,0,undefined,8) imi =undefined BadZone(8,5,1,0,undefined,8) imi =undefined BadZone(8,6,1,0,undefined,8) imi =undefined BadZone(10,4,1,0,undefined,10) imi =undefined BadZone(10,5,1,0,undefined,10) imi =undefined BadZone(10,6,1,0,undefined,10) imi =undefined BadZone(5,5,1,0,undefined,5) imi =undefined BadZone(5,6,1,0,undefined,5) imi =undefined BadZone(6,5,1,0,undefined,6) imi =undefined BadZone(6,6,1,0,undefined,6) imi =undefined BadZone(3,3,0,0,undefined,3) imi =1073741825 BadZone(3,6,1,0,undefined,3) imi =1073741825 BadZone(5,9,1,1024,undefined,5) imi =1073741825 BadZone(5,8,1,1024,undefined,5) imi =1073741825 BadZone(5,7,1,1024,undefined,5) imi =1073741825 BadZone(5,8,1,1024,undefined,5) imi =1073741825 BadZone(5,7,1,1024,undefined,5) imi =1073741825 BadZone(6,8,1,1024,undefined,6) imi =1073741825 BadZone(6,7,1,1024,undefined,6) imi =1073741825 BadZone(1,9,1,1024,undefined,1) imi =1073741825 BadZone(1,8,1,1024,undefined,1) imi =1073741825 BadZone(1,7,1,1024,undefined,1) imi =1073741825 BadZone(3,9,1,1024,undefined,3) imi =1073741825 BadZone(3,8,1,1024,undefined,3) imi =1073741825 BadZone(3,7,1,1024,undefined,3) imi =1073741825 BadZone(4,9,1,1024,undefined,4) imi =1073741825 BadZone(4,8,1,1024,undefined,4) imi =1073741825 BadZone(4,7,1,1024,undefined,4) imi =1073741825 BadZone(7,9,1,1024,undefined,7) imi =1073741825 BadZone(7,8,1,1024,undefined,7) imi =1073741825 BadZone(7,7,1,1024,undefined,7) imi =1073741825 BadZone(8,9,1,1024,undefined,8) imi =1073741825 BadZone(8,8,1,1024,undefined,8) imi =1073741825 BadZone(8,7,1,1024,undefined,8) imi =1073741825 BadZone(10,9,1,1024,undefined,10) imi =1073741825 BadZone(10,8,1,1024,undefined,10) imi =1073741825 BadZone(10,7,1,1024,undefined,10) imi =1073741825 BadZone(5,7,1,0,undefined,5) imi =1073742849 BadZone(5,9,0,0,undefined,5) imi =1073742849 BadZone(4,3,1,0,undefined,4) imi =1073742849 BadZone(4,4,1,0,undefined,4) imi =1073742849 BadZone(4,5,1,0,undefined,4) imi =1073742849 BadZone(4,6,1,0,undefined,4) imi =1073742849 BadZone(4,4,1,0,undefined,4) imi =1073742849 BadZone(4,5,1,0,undefined,4) imi =1073742849 BadZone(4,6,1,0,undefined,4) imi =1073742849 BadZone(1,4,1,0,undefined,1) imi =1073742849 BadZone(1,5,1,0,undefined,1) imi =1073742849 BadZone(1,6,1,0,undefined,1) imi =1073742849 BadZone(7,4,1,0,undefined,7) imi =1073742849 BadZone(7,5,1,0,undefined,7) imi =1073742849 BadZone(7,6,1,0,undefined,7) imi =1073742849 BadZone(8,4,1,0,undefined,8) imi =1073742849 BadZone(8,5,1,0,undefined,8) imi =1073742849 BadZone(8,6,1,0,undefined,8) imi =1073742849 BadZone(10,4,1,0,undefined,10) imi =1073742849 BadZone(10,5,1,0,undefined,10) imi =1073742849 BadZone(10,6,1,0,undefined,10) imi =1073742849 BadZone(5,5,1,0,undefined,5) imi =1073742849 BadZone(5,6,1,0,undefined,5) imi =1073742849 BadZone(6,5,1,0,undefined,6) imi =1073742849 BadZone(6,6,1,0,undefined,6) imi =1073742849 BadZone(3,7,1,0,undefined,3) imi =1073742849 BadZone(4,3,0,0,undefined,4) imi =1073741825 BadZone(4,6,1,0,undefined,4) imi =1073741825 BadZone(6,9,1,1024,undefined,6) imi =1073741825 BadZone(6,8,1,1024,undefined,6) imi =1073741825 BadZone(6,7,1,1024,undefined,6) imi =1073741825 BadZone(6,8,1,1024,undefined,6) imi =1073741825 BadZone(6,7,1,1024,undefined,6) imi =1073741825 BadZone(5,6,1,1024,undefined,5) imi =1073741825 BadZone(4,6,1,1024,undefined,4) imi =1073741825 BadZone(1,9,1,1024,undefined,1) imi =1073741825 BadZone(1,8,1,1024,undefined,1) imi =1073741825 BadZone(1,7,1,1024,undefined,1) imi =1073741825 BadZone(3,9,1,1024,undefined,3) imi =1073741825 BadZone(3,8,1,1024,undefined,3) imi =1073741825 BadZone(3,7,1,1024,undefined,3) imi =1073741825 BadZone(4,9,1,1024,undefined,4) imi =1073741825 BadZone(4,8,1,1024,undefined,4) imi =1073741825 BadZone(4,7,1,1024,undefined,4) imi =1073741825 BadZone(5,9,1,1024,undefined,5) imi =1073741825 BadZone(5,8,1,1024,undefined,5) imi =1073741825 BadZone(7,9,1,1024,undefined,7) imi =1073741825 BadZone(7,8,1,1024,undefined,7) imi =1073741825 BadZone(7,7,1,1024,undefined,7) imi =1073741825 BadZone(8,9,1,1024,undefined,8) imi =1073741825 BadZone(8,8,1,1024,undefined,8) imi =1073741825 BadZone(8,7,1,1024,undefined,8) imi =1073741825 BadZone(10,9,1,1024,undefined,10) imi =1073741825 BadZone(10,8,1,1024,undefined,10) imi =1073741825 BadZone(10,7,1,1024,undefined,10) imi =1073741825 BadZone(6,7,1,0,undefined,6) imi =1073742849 BadZone(6,9,0,0,undefined,6) imi =1073742849 BadZone(4,2,8,0,undefined,4) imi =1073742849 BadZone(4,5,8,0,undefined,4) imi =1073742849 BadZone(3,3,8,0,undefined,3) imi =1073742849 BadZone(4,4,8,0,undefined,4) imi =1073742849 BadZone(4,5,8,0,undefined,4) imi =1073742849 BadZone(3,3,8,0,undefined,3) imi =1073742849 BadZone(4,4,8,0,undefined,4) imi =1073742849 BadZone(7,5,8,0,undefined,7) imi =1073742849 BadZone(7,4,8,0,undefined,7) imi =1073742849 BadZone(4,2,0,0,undefined,4) imi =1073741832 BadZone(4,5,8,0,undefined,4) imi =1073741832 BadZone(5,10,1,1024,undefined,5) imi =1073741832 BadZone(5,9,1,1024,undefined,5) imi =1073741832 BadZone(5,8,1,1024,undefined,5) imi =1073741832 BadZone(5,9,1,1024,undefined,5) imi =1073741832 BadZone(5,8,1,1024,undefined,5) imi =1073741832 BadZone(5,6,1,1024,undefined,5) imi =1073741832 BadZone(4,6,1,1024,undefined,4) imi =1073741832 BadZone(6,6,1,1024,undefined,6) imi =1073741832 BadZone(1,9,1,1024,undefined,1) imi =1073741832 BadZone(1,8,1,1024,undefined,1) imi =1073741832 BadZone(1,7,1,1024,undefined,1) imi =1073741832 BadZone(3,9,1,1024,undefined,3) imi =1073741832 BadZone(3,8,1,1024,undefined,3) imi =1073741832 BadZone(3,7,1,1024,undefined,3) imi =1073741832 BadZone(4,9,1,1024,undefined,4) imi =1073741832 BadZone(4,8,1,1024,undefined,4) imi =1073741832 BadZone(4,7,1,1024,undefined,4) imi =1073741832 BadZone(6,9,1,1024,undefined,6) imi =1073741832 BadZone(6,8,1,1024,undefined,6) imi =1073741832 BadZone(7,9,1,1024,undefined,7) imi =1073741832 BadZone(7,8,1,1024,undefined,7) imi =1073741832 BadZone(7,7,1,1024,undefined,7) imi =1073741832 BadZone(8,9,1,1024,undefined,8) imi =1073741832 BadZone(8,8,1,1024,undefined,8) imi =1073741832 BadZone(8,7,1,1024,undefined,8) imi =1073741832 BadZone(10,9,1,1024,undefined,10) imi =1073741832 BadZone(10,8,1,1024,undefined,10) imi =1073741832 BadZone(10,7,1,1024,undefined,10) imi =1073741832 BadZone(5,8,1,0,undefined,5) imi =1073742849 BadZone(5,10,0,0,undefined,5) imi =1073742849 BadZone(4,1,18,0,undefined,4) imi =1073742849 BadZone(3,3,18,0,undefined,3) imi =1073742849 BadZone(2,5,18,0,undefined,2) imi =1073742849 BadZone(1,7,18,0,undefined,1) imi =1073742849 BadZone(0,9,18,0,undefined,0) imi =1073742849 BadZone(3,3,18,0,undefined,3) imi =1073742849 BadZone(2,5,18,0,undefined,2) imi =1073742849 BadZone(1,7,18,0,undefined,1) imi =1073742849 BadZone(0,9,18,0,undefined,0) imi =1073742849 BadZone(4,1,0,0,undefined,4) imi =1073741842 BadZone(1,7,18,0,undefined,1) imi =1073741842 BadZone(6,10,1,1024,undefined,6) imi =1073741842 BadZone(6,9,1,1024,undefined,6) imi =1073741842 BadZone(6,8,1,1024,undefined,6) imi =1073741842 BadZone(6,9,1,1024,undefined,6) imi =1073741842 BadZone(6,8,1,1024,undefined,6) imi =1073741842 BadZone(5,6,1,1024,undefined,5) imi =1073741842 BadZone(4,6,1,1024,undefined,4) imi =1073741842 BadZone(6,6,1,1024,undefined,6) imi =1073741842 BadZone(1,9,1,1024,undefined,1) imi =1073741842 BadZone(1,8,1,1024,undefined,1) imi =1073741842 BadZone(3,9,1,1024,undefined,3) imi =1073741842 BadZone(3,8,1,1024,undefined,3) imi =1073741842 BadZone(3,7,1,1024,undefined,3) imi =1073741842 BadZone(4,9,1,1024,undefined,4) imi =1073741842 BadZone(4,8,1,1024,undefined,4) imi =1073741842 BadZone(4,7,1,1024,undefined,4) imi =1073741842 BadZone(7,9,1,1024,undefined,7) imi =1073741842 BadZone(7,8,1,1024,undefined,7) imi =1073741842 BadZone(7,7,1,1024,undefined,7) imi =1073741842 BadZone(8,9,1,1024,undefined,8) imi =1073741842 BadZone(8,8,1,1024,undefined,8) imi =1073741842 BadZone(8,7,1,1024,undefined,8) imi =1073741842 BadZone(10,9,1,1024,undefined,10) imi =1073741842 BadZone(10,8,1,1024,undefined,10) imi =1073741842 BadZone(10,7,1,1024,undefined,10) imi =1073741842 BadZone(6,8,1,0,undefined,6) imi =1073742849 BadZone(6,10,0,0,undefined,6) imi =1073742849 BadZone(4,0,14,0,undefined,4) imi =1073742849 BadZone(4,1,14,0,undefined,4) imi =1073742849 BadZone(4,2,14,0,undefined,4) imi =1073742849 BadZone(4,3,14,0,undefined,4) imi =1073742849 BadZone(4,4,14,0,undefined,4) imi =1073742849

OK, the problem obviously is that 'imi' is not defined. I am pretty sure I uploaded the version that updates 'imi' also on user moves yesterday, but it turns out the old version was still on the CVP website. So somehow th upload must have failed. I now uploaded it again, and this fixes the problem. You can remove the document... line from the BadZone function now.
This is done. It works correctly. What about enpassant and promotion?

Promotion is done based on the piece type, so if the Joker is not amongst the promotable pieces, it will not promote. Only moves are immitated.
Because you have two different kinds of Pawns the test for it becomes complicated. In any case the destination square must be empty. But then for normal Pawns diagonal moves must be excluded, and for Berolinas the straight moves. So omething like
if(board[toRank][toFile] & 511) { if(pieceType == 1) return (toFile != fromFile); if(pieceType == 2) return (toFile == fromFile); }
This should be in another function BadZone2 for example, isn't it?

No, ther can be only one function BadZone, which must detect all moves you want to forbid, and return true (non-zero) for those (and false or 0 for the others). So you have to put this in BadZone just before the final return statement (which would otherwise return 'false', because in e.p. capture you only advance one rank)
It works well, HG, Thank you and a happy new year.

Well, actually it doesn't, because I messed up. One should not test pieceType (which will always be 14 at this point), but imi, to decide which moves to forbid. In addition, I tested for a full square, rather than an empty. The following routine should work: it first declares OK all non-imitator moves, all imitations of non-pawns, and all moves to occupied squares. At that point only non-capture pawn imitations are left, and advances of more than 1 rank can be flagged as illegal. finally it tests for e.p. depending on which pawn type is imitated.
function BadZone(toFile, toRank, pieceType, color, fromFile, fromRank) { if(pieceType != 14) return 0; if((imi & 511) > 2) return 0; if(board[toRank][toFile] & 511) return 0; if(fromRank > toRank + 1 || fromRank < toRank - 1) return 1; if(imi == 1) return (toFile != fromFile); return (toFile == fromFile); }
@HG,
In these games:
https://www.chessvariants.com/play/pbm/play.php?game=Grand+Apothecary+Chess+1&settings=Applet
https://www.chessvariants.com/play/pbm/play.php?game=Grand+Apothecary+Chess+2&settings=Applet
https://www.chessvariants.com/play/pbm/play.php?game=Grand+Apothecary+Chess+3&settings=Applet
castling is supposed to work like described here:
https://www.chessvariants.com/rules/grand-apothecary-chess-alert
https://www.chessvariants.com/rules/grand-apothecary-chess-classic
https://www.chessvariants.com/rules/grand-apothecary-chess-modern
but it does not. It just give fast castling with the rook. I see that this line:
set partners (b2 k2 b13 k13);
should contain the cannons initial position also. That is easy to solve. But I have no idea about the fast castling. May you help me with making the necessary modifications?

I am not sure why you refer to 'fast castling'. Is that the type of castling proposed by Kevin Pacey in his wide-board variants? Neither the Diagram nor the GAME-code produced by it do support such castling.
The Cannon would have to be in the partners set to allow castling with it. How far the King moves on castling is defined in the moves of the King; castlings are defined in the legdefs table as two-leg moves, the first leg being the slide that has to be used to find the partner, and the second leg (only attempted when a partner could be reached) indicates the leap the King should make. Your presets appear to define both 2-step and 3-step castlings for the King.
A problem is that the castling moves you define on the King are not critical w.r.t. the partner they use; any piece in the partner set would do. So it would not be possibe to only allow 2-step castling with a Rook, but not with a Cannon.
Well if I move my king on top of the rook is castles (3 squares king move). What is w.r.t?

With respect to
In the first preset, when I select the King (after clearing away pieces between King and Rook) it highlights all squares between King and Rook. If I then click the second of that, it does a 2-step castling. I have little doubt that on clicking the 3rd it would do a 3-step castling. If I click on the Rook (which is also highlighted) it does a 4-step castling.
Ok, this means I have to do a separate castling subrountine but that is very difficult, so if you have any advice, I'd gladly take it.

I guess you could use the applet-generated code like 2-, 3- or 4-step castling is always possible, with both Rook and Cannon (adding the latter to the 'partners' array). Like it already seems to be. And then supply a function 'BadZone' in GAME code to suppress the two cases you do not want (2-step for Cannon and 4-step for Rook). You would have to set a variable 'zonal' to true in the Pre-Game code to cause this BadZone function to be called.
The function BadZone will get called with 5 parameters: origin, destination, locust square, drop square, and piece to drop on the latter. For castling the castling partner will be on the locust square. I don't think your variants have locust capture other than e.p., so when the locust square is in the 'partners' array you can be sure it is a castling, and there is no need to test whether it was actually a King that was moved.
I would do it as follows:
set rooks (b2 k2 b13 k13); set badCannon (e2 i2 e13 i13); def BadZone match #locust #partners and cond match #locust #rooks match #dest rooks match #dest #badCannon =O =dest =locust =D =P; set zonal true;
This would declare the move invalid when the locust victim is one of the castling partners (match #locust #partners), AND, depending on whether it is one of the Rooks (match #locust #rooks) whether the destination square (of the King) is on the Rook (match #dest #rooks) or whether the destination square is two steps away from the King (match #dest #badCannon).
With the following code:
set partners (b2 k2 b13 k13 a2 l2 a13 l13); // 'rook' locations for castling set badCannon (e2 i2 e13 i13); def BadZone match #locust #partners and cond match #locust #rooks match #dest rooks match #dest #badCannon =O =dest =locust =D =P; set zonal true;
I'm getting this error:
213 if #zonal 214 verify not fn BadZone #orisqr #destsqr #locustsqr #dropsqr #unload 215 endif
at line 214
25 comments displayed
Permalink to the exact comments currently displayed.
No, it does not. It is not in the table. (In fact the Diagram uses piece type = 250 for holes internally.) The Diagram should be put on the HTML page that contains the Diagram. It should not matter where. There is no way to relate the script to a specific Diagram, however. So if there are more than a single Diagram on the same page, they will all use the BadZone function defined in the script.