H. G. Muller wrote on Sat, Aug 8, 2020 02:26 PM UTC:
I have now implemented shuffling for the Applet-generated rule-enforcing GAME code. Because this involved some subroutines that could be of general use, I placed the code in a separate include file, which can also be included in hand-crafted presets, through:
include /membergraphics/MSply-test-applet-for-chess-variants/shuffle.txt;
To make the variant into one with a shuffled initial position, one then only has to specify (in the Pre-Game section) an array of what pieces have to be shuffled, and call the master shuffling routine. E.g.
set shuffleset (B N Q);
gosub ShuffleSetup;
would randomly shuffle all Bishops, Knights and Queens. Black would normally be shuffled the same way as white, unless you specify a shuffle for black separately:
set shuffleset (B N Q);
set blackshuffle (b n q);
gosub ShuffleSetup;
would independently shuffle the white and black pieces.
There are some ways to restrict the shuffle, for instance for the purpose of ensuring the Bishops stay on opposite shades. For that purpose there are some extra arrays you could specify. In particular, piece types mentioned in the array 'shaded' will be kept on the shade they were orignally on. In that case those pieces should not be mentioned in the shuffleset. E.g.
set shuffleset (N R Q K);
set shaded (B);
gosub ShuffleSetup;
If black is to be shuffled independently, it must have its own 'blackshaded' for this purpose.
An even more severe restriction one can impose is that certain piece types must remain positioned (left-right) symmetrically. This is useful if you don't want to shuffle the King-side and Queen-side wings independently, but preserve the overall symmetry. E.g. to optionally cause swapping of the Bishops with King and Queen you can do:
set shuffleset (K Q);
set symmetrized (B);
gosub ShuffleSetup;
In orthodox chess this would then result in one of the back ranks RNBKQBNR, RNBQKBNR, RNKBBQNR or RNQBBKNR. Currently this mode of shuffling cannot be combined with shade-preserving shuffles; you should not define 'shaded' and 'symmetrized' both. The blackshuffle would use an equivalent array 'blacksym'.
There finally is a possibility to restrict the shuffle in such a way that one piece will end up between two others. For this an array 'centralize' has to be defined, with two or three piece types, the first of which must occur only once, and there must be exactly two of the others in the setup. That first-mentioned piece will then always end up between the two others. This is useful in Chess960, where we could do
set shuffleset (N R Q K);
set shaded (B);
set centralize (K R);
gosub ShuffleSetup;
So far for the simple applications. It is also possible to specify a complex sequence of shuffles. This is mainly intended for interpreting Pre-Game code generated by the Play-Test Applet. But it is not so complex that it is impossible to specify such a shuffle by hand. The idea is to provide an array of arrays 'shufflespecs', where each shuffle is specified by three consecutive elements of the 'outermost' array. These three elements are then used as the shuffleset, symmetrized and shaded settings for that shuffle step. If some of those are not needed, they should be set to 0. E.g.
set shufflespecs
( (A C) // shuffleset 1
(N) // symmetrized 1
0 // shaded 1 (absent)
(Q A C) // shuffleset 2
0 // symmetrized 2 (absent)
0 // shaded 2 (absent)
(N) // shuffleset 3
(B) // symmetrized 3
0 // shuffleset 3 (absent)
0 // make symmetric
);
The final 0 requests that black's position should be the mirror image of white's. If you want to shuffle black independently, you must omit that 0. But then you would have to specify all the shuffle steps in the array also with black pieces, or black would not be shuffled at all. In the example (starting from the setup of Capablanca Chess) you would force swapping of the B and N on both wings, or leave them unaffected, to decide whether super-pieces go onto the b- and i-file or the c- and h-file. The second shuffle would then permute all three super-pieces over the assigned locations. Finally, the Knight and Bishop might be swapped on both wings, or not at all.
I have now implemented shuffling for the Applet-generated rule-enforcing GAME code. Because this involved some subroutines that could be of general use, I placed the code in a separate include file, which can also be included in hand-crafted presets, through:
To make the variant into one with a shuffled initial position, one then only has to specify (in the Pre-Game section) an array of what pieces have to be shuffled, and call the master shuffling routine. E.g.
would randomly shuffle all Bishops, Knights and Queens. Black would normally be shuffled the same way as white, unless you specify a shuffle for black separately:
would independently shuffle the white and black pieces.
There are some ways to restrict the shuffle, for instance for the purpose of ensuring the Bishops stay on opposite shades. For that purpose there are some extra arrays you could specify. In particular, piece types mentioned in the array 'shaded' will be kept on the shade they were orignally on. In that case those pieces should not be mentioned in the shuffleset. E.g.
If black is to be shuffled independently, it must have its own 'blackshaded' for this purpose.
An even more severe restriction one can impose is that certain piece types must remain positioned (left-right) symmetrically. This is useful if you don't want to shuffle the King-side and Queen-side wings independently, but preserve the overall symmetry. E.g. to optionally cause swapping of the Bishops with King and Queen you can do:
In orthodox chess this would then result in one of the back ranks RNBKQBNR, RNBQKBNR, RNKBBQNR or RNQBBKNR. Currently this mode of shuffling cannot be combined with shade-preserving shuffles; you should not define 'shaded' and 'symmetrized' both. The blackshuffle would use an equivalent array 'blacksym'.
There finally is a possibility to restrict the shuffle in such a way that one piece will end up between two others. For this an array 'centralize' has to be defined, with two or three piece types, the first of which must occur only once, and there must be exactly two of the others in the setup. That first-mentioned piece will then always end up between the two others. This is useful in Chess960, where we could do
So far for the simple applications. It is also possible to specify a complex sequence of shuffles. This is mainly intended for interpreting Pre-Game code generated by the Play-Test Applet. But it is not so complex that it is impossible to specify such a shuffle by hand. The idea is to provide an array of arrays 'shufflespecs', where each shuffle is specified by three consecutive elements of the 'outermost' array. These three elements are then used as the shuffleset, symmetrized and shaded settings for that shuffle step. If some of those are not needed, they should be set to 0. E.g.
The final 0 requests that black's position should be the mirror image of white's. If you want to shuffle black independently, you must omit that 0. But then you would have to specify all the shuffle steps in the array also with black pieces, or black would not be shuffled at all. In the example (starting from the setup of Capablanca Chess) you would force swapping of the B and N on both wings, or leave them unaffected, to decide whether super-pieces go onto the b- and i-file or the c- and h-file. The second shuffle would then permute all three super-pieces over the assigned locations. Finally, the Knight and Bishop might be swapped on both wings, or not at all.