Check out Symmetric Chess, our featured variant for March, 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

Devingt Chess. Decimal chess with 20 pieces per side including Sages (moving as Camels).[All Comments] [Add Comment or Rating]
🕸Fergus Duniho wrote on Sun, Apr 3, 2022 07:58 PM UTC in reply to Jean-Louis Cazaux from 04:38 PM:

castling: the K may move 2 OR 3 sq towards the R

I just added some subroutines to the fairychess include file for this. These are castle2, castlepos2, and stalemated2, which are substitutes for castle, castlepos, and stalemated. Unlike castle and castlepos, castle2 and castlepos2 take four arguments instead of two. The first two are the same as before, the from and to coordinates for the King. These should be followed by the from and to coordinates for the piece the King is castling with. Unlike castle, which will handle all possible castling moves in the direction of the King's move, castle2 specifies a specific castling move. The stalemated2 subroutine differs from stalemated by calling castlepos2 and by writing out legal castling moves as two-piece moves.

The code in the preset also has to be changed to accommodate this. This line should be added in the Pre-Game code:

allow moves 2

You will also have to set different values for bcastle and wcastle. Instead of giving them a list of all the spaces a King may castle to, each should be given a list of fully described castling moves. Each should appear as four coordinates in parentheses in the same order they are fed into castle2. For your game, you would want to include four sets of coordinates for each King, one for each specific castling move.

In the Post-Move sections, castling moves have to be handled separately from regular moves. This means that the King subroutine should be rewritten to not include castling. An example of what to do can be seen in the preset for Miller's Spherical Chess, which uses the versions of these subroutines from the logical include file. The relevant code looks like this for White:

if isupper alias $prevmoved:
  if == $prevmoved K and == $moved R:
    if == $origin a1:
      gosub castle2 e1 c1 a1 d1;
    elseif == $origin h1:
      gosub castle2 e1 g1 h1 f1;
    else:
      die $moves "is illegal. Go back and try again.";
    endif;
  elseif != $prevmoved P or != $moved P or != $prevdest $dest:
    die "Except for castling or pawn promotion, you may not move twice on the same turn.";
  endif;
elseif ...

This uses the variable $prevmoved for the previous value of $moved. Usually, $prevmoved will have the piece last moved by the opponent. This block of code will run if the piece in $prevmoved belongs to the player moving, which happens in a two-part move. In Chess, these would be castling or pawn promotion. In a castling move, $prevmoved will have the player's own King. Using this variable saved me from having to write code like I did for multi-move variants. If it's not a castling move, it returns an error unless it is a pawn promotion. This lets the code exclude other double moves. Note that this code would have to be tweaked for your game.

Finally, the Post-Game code should use stalemated2 instead of stalemated.