Check out Atomic Chess, our featured variant for November, 2024.

Enter Your Reply

The Comment You're Replying To
🕸Fergus Duniho wrote on Sun, May 20, 2018 12:45 PM UTC:

I just fixed a bug in the code. A Queen is not supposed to be able to pass through check, but the way the code was enforcing this rule, it was ignoring checks from a piece captured by the Queen. This is because it was evaluating the legality of the Queen's move after the Queen had moved, and at that point, the piece the Queen had captured was no longer on the board. Here is what the code originally looked like:

// This is for evaluating actual moves by the Queen
sub Q from to:
  if not fn Q var from var to:
    die Your Queen may not move from #from to #to;
  endif;
  store;
  for pt path #from #to:
    move #to #pt;
    if sub checked var pt and != var pt var from and != var pt var to:
      die You may not move your Queen through check.;
    endif;
    restore;
  next;
  return true;
endsub;

It first checks whether it is a legal Queen move, and if it is not, it is illegal. That much is good. It then stores the current position and starts looping through the path between its origin and its destination. That much is also good. The problem is that it is working with the position after the Queen has moved. Note that inside the loop, it moves the Queen from #to to #pt. It should not be doing this. Instead, the position should have been restored to what it was before the Queen moved, and each iteration through the loop should move the Queen from its original space to the space along its path that the loop has reached. To fix this, I added "store before" to the Pre-Move code for each side, and I rewrote this subroutine to look like this:

// This is for evaluating actual moves by the Queen
sub Q from to:
  my pt;
  if not fn Q var from var to:
    die Your Queen may not move from #from to #to;
  endif;
  store;
  for pt path #from #to:
    restore before;
    move #from #pt;
    if sub checked var pt:
      die You may not move your Queen through check.;
    endif;
  next;
  restore;
  return true;
endsub;

Note that I also deleted the "and != var pt var from and != var pt var to" part from one of the lines. This was making sure that the position indicated was not the Queen's original space or its destination, but these positions were not actually included in the path anyway, as the path function just returns the shortest path between two spaces. When the two spaces are adjacent, it returns no positions. Apart from that, the main change was to distinguish between "restore before" and just "restore". The former would restore the position before the Queen moved, and the latter would restore the position to what it was after the Queen moved.


Edit Form

Comment on the page Caïssa Britannia

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.