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


[ Help | Earliest Comments | Latest Comments ]
[ List All Subjects of Discussion | Create New Subject of Discussion ]
[ List Latest Comments Only For Pages | Games | Rated Pages | Rated Games | Subjects of Discussion ]

Comments/Ratings for a Single Item

Later Reverse Order EarlierEarliest
The birth of 3 new variants - part 2 : Grand Apothecary Chess Modern[Subject Thread] [Add Response]
Aurelian Florea wrote on Mon, Aug 16, 2021 07:11 AM UTC in reply to H. G. Muller from Sun Aug 15 06:54 PM:

@HG, Yes, I was thinking about this!


H. G. Muller wrote on Sun, Aug 15, 2021 06:54 PM UTC in reply to Aurelian Florea from 04:47 PM:

Two possibilities:

1) Change the piece IDs in the description of the Interactive Diagram before you paste it into the Play-Test Applet.

2) Edit the GAME code generated by the Applet in order to change the IDs of the pieces you want changed. Piece labels occur in the function definitions and in the arrays behind the legdefs array with step descriptions, in the Pre-Game code.


Aurelian Florea wrote on Sun, Aug 15, 2021 04:47 PM UTC in reply to H. G. Muller from 09:32 AM:

@HG, It seems all well to me so far but the pictures used are the ones from the alfaerie many where the letters in use are from the interactive diagram. So it is difficult to read out. How do I fix this?


🕸Fergus Duniho wrote on Sun, Aug 15, 2021 12:11 PM UTC in reply to H. G. Muller from 09:32 AM:

In the routine below the variable 'sqr' stays 0 for all iterations. Only when I deleted the comma ("for (sqr piece) $space;") it runs through the square labels. Yet the GAME code manual suggest a comma should be present.

The Developer's Guide was wrong. I have corrected it. It uses spaces as separators, and when I used a comma, it added the comma to the variable name, so that this code worked:

foreach (key, var) spaces:
  echo #key, #var;
next;

But this code did not:

foreach (key, var) spaces:
  echo #key #var;
next;

(And thanks for fixing the dash problem; I would never have found that.)

It's important to remember that it was a minus sign, not a dash. When you use the # prefix before a variable name, it rewrites your code by replacing your variable with its value. Because it rewrote your code with a minus sign, your line of code was now trying to do subtraction. This threw a monkey wrench into your code in a way that a mere dash – which would be a meaningless string that was wider than a minus sign – would not have. Inserting the value of variables in this way is mainly intended for using variables with commands that do not process expressions (at all or for a certain argument). Within expressions, it is usually safer to use the var operator, which simply returns the variable value without rewriting your code. I believe functions are now an exception to this, since the following code prints 13, not 17:

set a 8;
def test + 9 #a;
set a 4;
print fn test;

H. G. Muller wrote on Sun, Aug 15, 2021 09:32 AM UTC:

@Fergus: In the routine below the variable 'sqr' stays 0 for all iterations. Only when I deleted the comma ("for (sqr piece) $space;") it runs through the square labels. Yet the GAME code manual suggest a comma should be present.

(And thanks for fixing the dash problem; I would never have found that.)

Yet another question: is there an elegant way to convert internal rank and file number to the square label? For games that need symmetric shuffling I first shuffle the white pieces, and then copy the white setup (color-flipped) to the black camp, and for that I have to derive the label of the mirror square. This is now done by a pretty complex calculation. Which only works if rank labeling is a consecutive range of integers.

@Aurelian: The FEN for your start position has one dash too many at the start. Otherwise it should work now. (At least the shuffling.)


🕸Fergus Duniho wrote on Sat, Aug 14, 2021 11:32 PM UTC in reply to H. G. Muller from 08:20 PM:

Here is the fixed subroutine:

sub GetSquares toshuffle:
  my sqr piece;
  // determine the squares the pieces in the given set are on.
  // the result is left in 3 global arrays:
  set left array;  // on left board half
  set light array; // as well as sorted by shade
  set dark array;
printr $space;
  for (sqr, piece) $space:
print . iter . #piece #sqr;
    if match var piece #toshuffle:
      if < * 2 file #sqr lastfile:  // left half
        push left #sqr;
      endif;
      if == color #sqr 1: // distinguish by shade
        push dark #sqr;
      else:
        push light #sqr;
      endif;
    endif;
  next;
print "got it";
endsub;

The actual fix was changing #piece to var piece in the conditional if match var piece #toshuffle:. There are subtle differences between these two ways of getting the values of variables. The way you were doing it embedded it into the line during pre-processing, and the problem with doing that was that its first value was -, which is also an operator. Changing it to var piece made sure that it treated the value as a string at the proper time and not as the minus operator.

I changed another line to use the color operator, because this might be a better way of doing what you want. This returns the color index associated with the space. Looking at the color values, I figured that the number 1 was being used for the dark squares.


H. G. Muller wrote on Sat, Aug 14, 2021 08:20 PM UTC in reply to Fergus Duniho from 08:00 PM:

When I clicked on that, I saw a listing of all the spaces. So, I presume it is working.

No, that just shows the printr $space before the loop worked. After that list of spaces it prints "iter0"  in the first and only iteration of the loop.

If things worked, you would not see anything printed; You would just see the diagram of the shuffled starting position.


🕸Fergus Duniho wrote on Sat, Aug 14, 2021 08:00 PM UTC in reply to H. G. Muller from 06:49 PM:

This routine is in the shuffle.txt file included in the preset Aurelian posted the link to 5 postings ago in this subject thread.

When I clicked on that, I saw a listing of all the spaces. So, I presume it is working.

Once you have shuffled the pieces, are you storing the results of the shuffling in a constant for later reuse?


H. G. Muller wrote on Sat, Aug 14, 2021 06:49 PM UTC in reply to Fergus Duniho from 06:30 PM:

There isn't that much context; it is in a subroutine, and sqr and piece are 'my' variables, which should pretty much decouple it from the remaining code:

sub GetSquares toshuffle:
  my sqr piece;
  // determine the squares the pieces in the given set are on.
  // the result is left in 3 global arrays:
  set left array;  // on left board half
  set light array; // as well as sorted by shade
  set dark array;
printr $space;
  for (sqr, piece) $space:
print . iter . #piece #sqr;
    if match #piece #toshuffle:
      if < * 2 file #sqr lastfile:  // left half
        push left #sqr;
      endif;
      if & 1 + file #sqr rank #sqr: // distinguish by shade
        push dark #sqr;
      else:
        push light #sqr;
      endif;
    endif;
  next;
print "got it";
endsub;

This routine is in the shuffle.txt file included in the preset Aurelian posted the link to 5 postings ago in this subject thread. That preset calls the routine ShuffleSetup (at the very bottom of the Pre-Game section), which eventually calls this routine. If you click that link it directly tries to execute the preset, which immediately exits after printing the $space array, and "iter0". It never gets to the "got it".

 


🕸Fergus Duniho wrote on Sat, Aug 14, 2021 06:30 PM UTC in reply to H. G. Muller from 02:44 PM:

When I tried it by itself, it did loop through the board. Perhaps something in the outer context is affecting your code.


H. G. Muller wrote on Sat, Aug 14, 2021 02:44 PM UTC:

@Fergus: I don't understand what is wrong with the following GAME code:

  for (sqr, piece) $space:
print . iter . #piece #sqr;
    if match #piece #toshuffle:
      if < * 2 file #sqr lastfile:  // left half
        push left #sqr;
      endif;
      if & 1 + file #sqr rank #sqr: // distinguish by shade
        push dark #sqr;
      else:
        push light #sqr;
      endif;
    endif;
  next;
print "got it";


I would have expected it to loop over the board. But instead it prints "iter0" and then exits. If I do a "printr $space" just before it, it does print the board as expected.


Aurelian Florea wrote on Fri, Aug 13, 2021 11:03 AM UTC in reply to H. G. Muller from Tue Aug 10 09:22 AM:

HG, Have you took any time to take a look on the initial position randomization issue?


H. G. Muller wrote on Tue, Aug 10, 2021 09:22 AM UTC in reply to Aurelian Florea from 09:06 AM:

1) It seems the checkbox "Do not include moves in code" is not ticked.

2) Something is wrong with the shuffling; I still have to figure out what. When I delete the last line of the Pre-Game code ("gosub ShuffleSetup;") the preset seems to work (but without shuffling, of course).


Aurelian Florea wrote on Tue, Aug 10, 2021 09:06 AM UTC in reply to H. G. Muller from Mon Aug 9 08:06 PM:

The result of one of my 3 games is here :

https://www.chessvariants.com/play/pbm/play.php?game=Grand+Apothecary+Chess+1&settings=Applet

although it seems I have done something wrong as I don't get normal results. It just says to report any bugs to you HG!


H. G. Muller wrote on Mon, Aug 9, 2021 08:06 PM UTC:

You already made an Interactive Diagram that does the Pawn move and the castling in the way you want, right? All you have to do is paste the description of that diagram (without any HTML tags) into the Play-Test Applet, (where it says "paste an existing diagram"), and click the 'Game code' button.


Aurelian Florea wrote on Mon, Aug 9, 2021 07:59 AM UTC in reply to H. G. Muller from Thu Jul 15 07:03 PM:

@HG Muller

@Aurelian: Just out of curiosity: what happens when you use the Play-Test Applet to convert the Interactive Diagram you made to GAME code? Does the castling work as intended then?

I'm not sure I know how to do this. I have read this:

https://www.chessvariants.com/invention/game-code-generation

but I did not understood how to do the weird castling, or something that needs doing in game code like initial pawn pushes. (the * in Xbetza).


Aurelian Florea wrote on Fri, Jul 23, 2021 07:22 AM UTC in reply to Fergus Duniho from Wed Jul 21 05:19 PM:

With your piece of code I have tested my idea and made it work as intended. Thanks once again, Fergus!


Aurelian Florea wrote on Thu, Jul 22, 2021 04:49 AM UTC:

Thank you, Fergus!


🕸Fergus Duniho wrote on Wed, Jul 21, 2021 05:19 PM UTC in reply to Aurelian Florea from Tue Jul 20 01:38 PM:

I still need to understand how to delete a value from an array in order to remove the necessary value from wcastle or bcastle.

You can unset an array element if you know its key. For example:

set ra array a b c d e f g h i j k l m n o p q r;
unset ra.4; // removes e from array

But what if you just know the element you want to delete and not its key? I have now added a diff operator to return an array difference. When an argument isn't already an array, it gets turned into a single element array. So, this code removes j1 from wcastle.

set wcastle d1 c1 j1 k1;
set wcastle diff #wcastle j1;

Aurelian Florea wrote on Tue, Jul 20, 2021 01:38 PM UTC in reply to Fergus Duniho from Thu Jul 15 05:36 PM:

@Fergus,

I still need to understand how to delete a value from an array in order to remove the necessary value from wcastle or bcastle.


Aurelian Florea wrote on Fri, Jul 16, 2021 03:00 PM UTC in reply to H. G. Muller from Thu Jul 15 07:03 PM:

No ideea I'll Try it!


H. G. Muller wrote on Thu, Jul 15, 2021 07:03 PM UTC:

@Aurelian: Just out of curiosity: what happens when you use the Play-Test Applet to convert the Interactive Diagram you made to GAME code? Does the castling work as intended then?


🕸Fergus Duniho wrote on Thu, Jul 15, 2021 05:36 PM UTC in reply to Aurelian Florea from 07:57 AM:

I do not understand why after I move the rook I can castle with the cannon on the field that was supposed to be used only for the rook.

So far, you have not made it clear that the King moves to a different space when castling with each piece. The rules you have underneath the game do not even mention castling. The castle subroutine was not written with such a rule in mind. You might be able to make it work by adjusting the values of bcastle and wcastle after a Rook moves.

I think I haven't explained that properly but only one castle is aloud.

Castling is allowed only once, which I understand, but what you say next doesn't fit with you trying to say that. Are you trying to say that the King has only once space it can go to when castling with a certain piece?

Regarding your preset, I don't understand why you are using four colors for checkering the board. Also, the dark blue squares do not contrast well with the color used for highlighting legal moves, which makes it hard to see legal moves highlighted on those squares. Additionally, your rules could use images of the pieces, so that someone looking at a piece on the board can more easily tell how it moves. Remember to use the shortcodes for displaying pieces, so that the piece images below match those on the board no matter what piece set is used.


Aurelian Florea wrote on Thu, Jul 15, 2021 07:57 AM UTC in reply to Fergus Duniho from Tue Jul 13 03:38 PM:

@Fergus Then I do not understand why after I move the rook I can castle with the cannon on the field that was supposed to be used only for the rook. I think I haven't explained that properly but only one castle is aloud. This is not free castling. So this is why I asked about wcastle and bcastle.


🕸Fergus Duniho wrote on Tue, Jul 13, 2021 03:38 PM UTC in reply to Aurelian Florea from 11:51 AM:

What I still need to do is delete a variable from wcastle or bcastle as the rook gets moved.

That shouldn't be necessary, as other factors will determine that future castling moves are illegal without doing this.

How do I delete a value from an array?

Once the King has castled, it might be a bit of an optimization if you set wcastle or bcastle to an empty array, but it shouldn't be necessary.


25 comments displayed

Later Reverse Order EarlierEarliest

Permalink to the exact comments currently displayed.