Check out Alice Chess, our featured variant for June, 2024.

Enter Your Reply

The Comment You're Replying To
H. G. Muller wrote on Sat, Jun 22 02:26 PM UTC in reply to Fergus Duniho from 01:06 PM:

Anyway, your code employs huge tables that somehow define how a piece moves, and I don't understand how these work.

The format used to encode (possibly complex) moves in the table is to split those into a sequence of rides ('legs'). Each ride is characterised by four parameters: maximum number of steps, x-step, y-step, and an integer where each bit corresponds to a 'power' that the leg has. (Like can-capture-destination, can-move-to-destination, can-e.p.-capture-to-destination, base steps cannot jump, base steps must jump, can-hop-over-destination, initial-move-only, must have as many steps as previous ride, etc.) Each move is encoded as the number of legs N, followed by N leg descriptions of four numbers each. The moves of a piece are tabulated all behind the other, the end indicated by a dummy move of zero legs (i.e. just a 0).

For example, an orthodox Rook would be encoded as four simple slides in different directions:

1 99  0  1 3
1 99  1  0 3
1 99  0 -1 3
1 99 -1  0 3
0

Where the 3 stands for can-move (1) and can-capture (2). The 99 is used to indicate an unlimited range. For leapers this would be 1. The moves of all pieces are all stored one after the other in the same array 'legdefs'; I use functions with the name of the piece label that return the index in legdefs where the moves for that piece starts.

A bent rider like Griffon would have moves consisting of two legs, like

1  1 1 1 3
2  1 1 1 1
  99 1 0 3
2  1 1 1 1
  99 0 1 3
...

(showing one simple F move, and two bent slides). The first leg of the latter is a (1,1) leap to an empty square, the second leg an unlimited-range slide with (1,0) or (0,1) step that can move or capture.

There is a GAME-code routine NextLeg which interprets the table in order to lay out all tabulated moves for a given piece on the board, and for each move it can make to a valid final destination it then calls a routine to do something with that move. (Like comparing it to the input move, or add it to the array of legal moves for highlighting.)

There is a slight complexity: normally you only have to worry about (pseudo-)legality for the last move in the game, and do that in Post-Game code. The earlier moves were already vetted in the turn they were entered. So you can take them at face value, performing them 'no questions asked'. This does not work for moves with implied side effects (i.e. board mutations not indicated in the move notation), such as e.p. capture. Such moves would have to be generated for every move in the game, and if the explicit part matches the stored move, the generated side effect would have to be performed as well.

To this end moves with implied side effects are always stored behind all others, and the routine that returns the index of the first move to be tried for a piece of that name has a parameter that indicates whether you want to try all its moves, or only those with implied side effects. By convention pieces without such special moves point to an empty movelist (a single 0), stored at the start of legdefs.


Edit Form

Comment on the page Game Courier Logs

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.
Avoid Inflammatory Comments
If you are feeling anger, keep it to yourself until you calm down. Avoid insulting, blaming, or attacking someone you are angry with. Focus criticisms on ideas rather than people, and understand that criticisms of your ideas are not personal attacks and do not justify an inflammatory response.
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.