Many chess variants have special rules in addition to pieces with unusual moves and boards of other sizes. For the purpose of my Interactive Diagram, which is supposed to allow easy embedding of a GUI + simple AI for as large a variety of chess variants as possible, I invented the following method for describing a large number of such rules.
First I want to point out that what I call a 'piece type' is a piece that can make the same steps anywhere on the board. (I won't handle boards of irregular topology.) One often encounters rules where this is not the case. E.g. in Xiangqi a Pawn gets extra moves on the opponent's half ('across the River'). Without loss of generality this can be implemented by considering the pieces of different type depending on where the stand, and change their type on moves that transport them into a zone where they move different from where they came from. I.e. 'promote' them based on where they land. This could be a 'disguised promotion', where the piece ID and image associated with the type are not altered.
Morph
In the Interactive Diagram I implemented this by allowing a 'morph' to be assigned to every piece type. This is a board-size table, encoded as string by separating the board ranks by slashes. Other characters correspond to squares, and can contain the piece ID for the type a piece would morph to when it lands on that square. A period indicates nothing special happens on the corresponding square. To resolve ambiguity, if two types are represented by the same ID, mentioning that ID in the morph of one of those would always refer to the other.
Apart from indicating such forced type changes, other events associated with arriving at a given square can be encoded in the morph as well. E.g. confinement to board zones (as for the King in Xiangqi, which cannot leave the 3x3 Palace zone) can be indicated by labeling squares where the type cannot go by an exclamation point (!). Game termination by reaching a goal square (often called 'capture the Flag' winning condition) can be indicated by labeling the goal squares by a + or #, depending on whether the moves that can do this must be legal, or can also be pseudo-legal. E.g. in King of the Hill the four central squares in the morph for the King would be labeled with a +.
Finally a promotion with the usual choice can be indicated by labeling a square with an asterisk (*). This can be used to implement promotion zones of arbitrary shape.
Capture Matrix
Other special rules often address effects independent of location, but dependent on the type of move. In particular, whether the move is a capture, and if so, what was captured. E.g. in Kyoto Shogi pieces toggle their type on every move, and in micro-Shogi on every capture. Type-dependent promotions occur in Werewolf Chess, where any non-royal piece capturing a Werewolf changes into one. Or in Gholem Chess, where a Gholem needs to be captured twice before it disappears, and after the first capture will turn into a Half-Gholem of the same color as the captured Gholem (so promotion on capture to an opponent piece!).
All such rules can be summarized in a 'capture matrix'. This is a table where each row represents the type of the moved piece, and each column the type of the piece that was captured (where the first colun is for an empty square, i.e. a non-capture). Again the capture matrix is encoded as a string where the rows are separated by slashes, and each other character labels a specific capture of one type by another. If the capture is labeled by a piece ID, the capturing piece will promote to that type as a consequence of the move. A lower-case ID here means promotion to an opponent piece.
Also here it is convenient to allow labels for other effects than promotion. Again the exclamation point (!) means that the capture is not possible at all. This can be used to indicate 'iron' pieces (which cannot be captured at all), or pieces that cannot capture each other (as an anti-trading rule), but can be captured by all other pieces. It can also be used to indicate Stratego-like capture rankings. I used a % to indicate a more-subtle anti-trading rule, where the thus-labeled capture is only forbidden when the victim is protected. (Such a rule is used in Chu Shogi.) It would in principle also be possible to indicate captures that result in game termination, i.e. type-selective royalty.
Since some variants allow friendly capture, the capture matrix can also have columns for that. This can be used in variants where you can merge pieces, e.g. a Bishop capturing a friendly Rook would result in a Queen on the target square.
Some pieces have moves that must 'hop' over another piece. E.g. a Cannon in Korean Chess moves as a Rook, but only beyond the first obstacle on the Rook path. But a Cannon cannot hop over another Cannon. The capture matrix can also indicate such type-specific bans on hopping, by labeling the piece-obstacle type combination with ^. The ban also applies to friendly Cannons, so here it is useful to have the friendly columns in the matrix as well.
Shorthand
To avoid excessive writing in variants with many piece types, the strings representing the morph board or capture matrix can be abbreviated. For the capture matrix the FEN system, where a number automatically represents that number of empty square (which conceivably could be used here to indicate a number of non-special attacker-victim combinations) is not ideal, though. In the FEN it worked because one seldomly encounters large stretches of identical pieces (except for Pawns in the start position). But for the capture matrix this is quite usual, e.g. when a piece promoted into an improved type for every capture that it makes. So a number here indicates the number of repetitions of the preceding symbol. Only when the number appears at the start of the row it implies the repeated symbol to be a dot (i.e. nothing special happens).
Rows don't have to be finished; non-labeled attacker-victim combinations are assumed to be non-special. I.e., the row is completed with dots. If an = sign is encountered this has a special meaning: it completes the enemy part of the capture matrix as non-special, and then copies that part of the row to the friendly captures, making use of the fact that the friendly columns come after the enemy ones. This is very convenient when bans for hopping apply to friendly as well as enemy hops. But by continuing the row after the =, one can still overrule the copied symbols.
A row containing only a double quote (") means it repeats the previous row. A double quote followed by a number would repeat that row the mentioned number of times.
In the morph boards it works a bit different: an unfinished rank will be filled by repeating the filled part as often as needed. This makes it easy to create regular patterns. E.g. if we want a piece to morph to Knight on every dark square of an 8x8 board we could write .N/N./.N/N./.N/N./.N/N., and the .N would expand to .N.N.N.N . A rank containing only a single character would be entirely filled with it. An empty rank indicates all squares on that rank are non-special.
Parametrizing chess variants
Moderator: Ras
-
- Posts: 28353
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller