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

Enter Your Reply

The Comment You're Replying To
🕸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.


Edit Form

Comment on the page Devingt Chess

Conduct Guidelines
This is a Chess variants website, not a general forum.
Please limit your comments to Chess variants or the operation of this site.
Keep this website a safe space for Chess variant hobbyists of all stripes.
Because we want people to feel comfortable here no matter what their political or religious beliefs might be, we ask you to avoid discussing politics, religion, or other controversial subjects here. No matter how passionately you feel about any of these subjects, just take it someplace else.
Quick Markdown Guide

By default, new comments may be entered as Markdown, simple markup syntax designed to be readable and not look like markup. Comments stored as Markdown will be converted to HTML by Parsedown before displaying them. This follows the Github Flavored Markdown Spec with support for Markdown Extra. For a good overview of Markdown in general, check out the Markdown Guide. Here is a quick comparison of some commonly used Markdown with the rendered result:

Top level header: <H1>

Block quote

Second paragraph in block quote

First Paragraph of response. Italics, bold, and bold italics.

Second Paragraph after blank line. Here is some HTML code mixed in with the Markdown, and here is the same <U>HTML code</U> enclosed by backticks.

Secondary Header: <H2>

  • Unordered list item
  • Second unordered list item
  • New unordered list
    • Nested list item

Third Level header <H3>

  1. An ordered list item.
  2. A second ordered list item with the same number.
  3. A third ordered list item.
Here is some preformatted text.
  This line begins with some indentation.
    This begins with even more indentation.
And this line has no indentation.

Alt text for a graphic image

A definition list
A list of terms, each with one or more definitions following it.
An HTML construct using the tags <DL>, <DT> and <DD>.
A term
Its definition after a colon.
A second definition.
A third definition.
Another term following a blank line
The definition of that term.