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

LatestLater Reverse Order EarlierEarliest
Game Courier Developer's Guide. Learn how to design and program Chess variants for Game Courier.[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote on Wed, Feb 17, 2021 09:20 PM UTC:

How to replace piece labels without using aliases

The Alfaerie:Many set uses many cryptic labels that include punctuation, and it would be best to avoid using these to represent your pieces in games. In the past, you could set aliases to avoid using these labels, but you would also have to meticulously make sure you used the aliases rather than the labels. Instead of doing this, you may now completely replace the original labels with new ones. Here is how to do it. This code has all been tested and saved to an example preset.

  1. Use the labels defined in Alfaerie:Many in your FEN code while designing the board. In my example, I used {.df}n{b$}qk{b$}n{.df}pppppppp32PPPPPPPP{.DF}N{B$}QK{B$}N{.DF}.

  2. Create two arrays, one for regular pieces, and one for flipped pieces. Depending on the set file, you may not need one for flipped pieces, but Alfaerie:Many does include some flipped pieces. So, you have to include it for this set.

set mypieces ();
set myflipped ();
  1. For the pieces that will remain unchanged, simply add them to these arrays like so:
foreach label (k K q Q n N p P):
  setelem mypieces #label pieceimg #label;
  setelem myflipped #label flipimg #label;
next;
  1. For pieces that will be relabled, assign the appropriate images to your new labels. These use the pieceimg and flipimg operators to return the images for regular and flipped pieces. It then replaces the old pieces on the board with the new ones that have more appropriate labels. It uses an array of all spaces for this task.
set sp spaces;
foreach pair ((.df r) (.DF R) (b$ b) (B$ B)):
  setelem mypieces #pair.1 pieceimg #pair.0;
  setelem myflipped #pair.1 flipimg #pair.0;
  replace #pair.0 #pair.1 all #sp;
next;
  1. Reassign values to both $pieces and $flipped:
setsystem pieces #mypieces;
setsystem flipped #myflipped;
  1. Update the value of $originalpieces:
setsystem originalpieces currentpieces;

🕸📝Fergus Duniho wrote on Tue, Feb 16, 2021 10:02 PM UTC:

I have added the pieces system variable. This is the array stored in a set file. Its keys are piece labels, and its values are the filenames of image files. It basically tells which graphics to use for the pieces. I also fixed things so that you can set or get specific values of this array. This is done by following the variable name with a period and the element name. Because this will not work for labels that include periods, I have also added the pieceimg operator. This returns a specific element of the $pieces array.

The point of this is to make it even easier to support multiple sets when matching sets have not been provided. It can also be used to eliminate the need to use aliases. Here is how it may be used:

  1. Set groupsets to an array of the allowed sets. Each should be the basename of a set file:
setsystem groupsets array abstract5 alfaerie-many;
  1. Create an empty array:
set mypieces ();
  1. For any pieces whose images already have the same label in different sets, set the corresponding elements of your array to those pieces:
set mypieces.k $pieces.k;
set mypieces.K $pieces.K;
set mypieces.q $pieces.q;
set mypieces.Q $pieces.Q;
set mypieces.r $pieces.r;
set mypieces.R $pieces.R;
set mypieces.b $pieces.b;
set mypieces.B $pieces.B;
set mypieces.n $pieces.n;
set mypieces.N $pieces.N;
set mypieces.p $pieces.p;
set mypieces.P $pieces.P;

Or just:

foreach label (k K q Q r R b B n N p P):
  setelem mypieces #label pieceimg #label;
next;
  1. For each allowed set, use an if-elseif-else block or a switch-case block to set an individualized value for any pieces that are different between sets:
if == pieceset abstract5:
  set mypieces.s $pieces.s;
  set mypieces.S $pieces.S;
elseif == pieceset alfaerie-many:
  set mypieces.s pieceimg .de;
  set mypieces.S pieceimg .DE;
endif;
  1. Change the value of $pieces to that of the array you created:
setsystem pieces #mypieces;

Although you could have edited $pieces directly, this has the advantage of stripping $pieces of all the pieces you will not be using in your game.


🕸📝Fergus Duniho wrote on Tue, Feb 16, 2021 07:17 PM UTC:

I have added the system variable groupsets and the nullary operator pieceset. My intention behind adding these is to allow a developer to support multiple piece sets even when he cannot find piece sets that use the same keys for the same pieces.

Here is how to do this:

  1. Check the box for "Bypass Error Check on Piece Label".
  2. In the Pre-Game code, use setsystem to set groupsets to an array of the basenames of the sets you will allow a player to select from.
  3. Still within the Pre-Game code, use an if-elseif-else block or a switch-case block to check the value of pieceset against the basename of each allowed set, use the add command to change the pieces on the board to match the images you want to use from that set, and use the alias command to set appropriate aliases.
  4. Within your other code, consistently do operations on the piece aliases rather than the piece labels. Note that the fairychess include file is already designed to do this, and it is the recommended include file for new games.

🕸📝Fergus Duniho wrote on Tue, Jan 12, 2021 07:15 PM UTC:

I have started work on updating the documentation to include previously undocumented operators. I'll update this comment as I make more progress. So far, I have gone through the nullary operators, which do not take any arguments.

I have added documentation for the previously undocumented operators: args.

I removed the following undocumented operators: debug, dump.

I removed documentation for the following non-existent operators: player.

I modified the dump command to use var_dump() instead of print_r, and I modified it to report on a single value when it is passed as an argument. The use of var_dump() adds information on the type of each value.


🕸📝Fergus Duniho wrote on Mon, Jan 11, 2021 10:28 PM UTC:

I added documentation for the new operators int and type.


Samuel Hoskins wrote on Sun, Jan 10, 2021 08:53 AM UTC in reply to Samuel Hoskins from Wed Jan 6 04:37 AM:

Where can I find an editor so I can have a piece set uploaded?

Bump. I'm making a preset for Dai Shogi and help would be appreciated.


🕸📝Fergus Duniho wrote on Sat, Jan 9, 2021 06:52 PM UTC in reply to H. G. Muller from Thu Jan 7 10:32 AM:

I[s] there a notation for octal, hexadecimal or binary constants in GAME code?

I have just added a new int operator that recognizes whether a number is a hexadecimal, octal, decimal, or binary literal and converts it to an integer. Hexadecimal literals begin with 0x, octal with just 0, decimal with nothing special, and binary with 0b. It checks the first characters to determine the base, then uses PHP's intval() function.


🕸📝Fergus Duniho wrote on Sat, Jan 9, 2021 06:25 PM UTC in reply to H. G. Muller from Thu Jan 7 10:32 AM:

I[s] there a notation for octal, hexadecimal or binary constants in GAME code?

No. My tests show that PHP has this feature, but for some reason, it hasn't carried over to GAME Code. It looks like it has to do with handling numbers as strings. In a further test I ran, PHP would convert base 10 strings into numbers, but it would not convert other bases into numbers when they were enclosed by quotation marks. Additionally, PHP's is_numeric() function does not recognize strings in other bases as numeric.

My current automation code tabulates the capability of a move as bit flags packed into a single word. And often has to test one of these flags. Currently I use the expression & << 1 N #mode for this, where N is a constant indicating the number of the bit I want to test. This slows down the program by requiring extra shift operations at run time.

While I could build in conversion to handle this, it might be more costly than using a bit shift.

I could of course calsulate how much << 1 N is as a decimal number in every case, and write that into the code instead, but this makes the code very hard to understand, susceptible to typos (N can get quite large, like 28) and therefore hard to debug and maintain.

What I do is use constants with meaningful names. Doing this makes the code much more readable, and it reduces the chance for error by limiting the actual numeric values to some constant assignments.

An alternative would be to have a bit operator such that bit N #mode would calculate & << 1 N #mode (i.e. mask out the Nth bit).

What is #mode supposed to be?


H. G. Muller wrote on Thu, Jan 7, 2021 10:32 AM UTC:

I there a notation for octal, hexadecimal or binary constants in GAME code? My current automation code tabulates the capability of a move as bit flags packed into a single word. And often has to test one of these flags. Currently I use the expression & << 1 N #mode for this, where N is a constant indicating the number of the bit I want to test. This slows down the program by requiring extra shift operations at run time. I could of course calsulate how much << 1 N is as a decimal number in every case, and write that into the code instead, but this makes the code very hard to understand, susceptible to typos (N can get quite large, like 28) and therefore hard to debug and maintain. Written as a hexadecimal it would be much more obvious and less error prone, as even for N=28 it would just read 10000000. An alternative would be to have a bit operator such that bit N #mode would calculate & << 1 N #mode (i.e. mask out the Nth bit).


Samuel Hoskins wrote on Wed, Jan 6, 2021 04:37 AM UTC:Good ★★★★

Where can I find an editor so I can have a piece set uploaded?


Jose Carrillo wrote on Thu, Oct 15, 2020 05:24 PM UTC in reply to Fergus Duniho from 04:57 PM:

Thanks again Fergus.


🕸📝Fergus Duniho wrote on Thu, Oct 15, 2020 04:57 PM UTC in reply to Jose Carrillo from 04:06 PM:

Can you delete 18. resign move from the database?

I think this is causing a problem after a won command.

Instead of doing that, which would have fixed only one game, I did a more global fix. In the won, resign, and lost commands, I replaced $movenum, which is recorded in the log, with $mline[$mln]->movenum, which is generated by the program and indicates the number of the current move.


Jose Carrillo wrote on Thu, Oct 15, 2020 04:06 PM UTC in reply to Fergus Duniho from Mon Oct 12 06:26 PM:

Fergus,

The problems with the "won" command are back.

This game is again showing the wrong winner:

https://www.chessvariants.com/play/pbm/play.php?game=Latrunculi+XXI&log=j_carrillo_vii-cvgameroom-2020-281-060

Can you delete 18. resign move from the database?

I think this is causing a problem after a won command.

= = =

Source code:


Jose Carrillo wrote on Mon, Oct 12, 2020 07:54 PM UTC in reply to Fergus Duniho from 06:26 PM:

Thanks Fergus!


🕸📝Fergus Duniho wrote on Mon, Oct 12, 2020 06:26 PM UTC in reply to Jose Carrillo from 06:11 PM:

There seems to be something weird with the "won" command.

I have now fixed this. See the comment below.


🕸📝Fergus Duniho wrote on Mon, Oct 12, 2020 06:24 PM UTC in reply to Jose Carrillo from 05:15 PM:

The correct game was this one:

https://www.chessvariants.com/play/pbm/play.php?game=Petteia+-+Dmytro+Variation&log=j_carrillo_vii-halfer-2020-283-953

Seems to be fine now. Thanks.

It was showing that your opponent had won, yet you had entered the won command. So, I fixed that. It now makes use of the $players variable if available. This gets set when an invitation is accepted, and it keeps a permanent record of who moved first, which makes it easier to tell which player entered the command.


Jose Carrillo wrote on Mon, Oct 12, 2020 06:11 PM UTC in reply to Fergus Duniho from 04:48 PM:

Fergus,

I must be going crazy... :-(

Now this game:

https://www.chessvariants.com/play/pbm/play.php?game=Petteia+-+Dmytro+Variation&log=j_carrillo_vii-halfer-2020-283-953

(the game whose moves I couldn't see before) is showing that my opponent won the game. This game is another one where I ended the game with the "won" command.

I issued the "won" command as white, but the log shows that my opponent (black) won.

There seems to be something weird with the "won" command.

Below the page source section with the problem:


Jose Carrillo wrote on Mon, Oct 12, 2020 05:15 PM UTC in reply to Fergus Duniho from 04:49 PM:

Apologies Fergus, gave you the wrong link.

The correct game was this one:

https://www.chessvariants.com/play/pbm/play.php?game=Petteia+-+Dmytro+Variation&log=j_carrillo_vii-halfer-2020-283-953

But I just checked again and now the log is there. It was weird. last time I checked there were only two lines in the log, White to play and Jose Carrillo won the game.

And I saw it as well in the page source.

Seems to be fine now. Thanks.

And thanks for correcting the winner in the other comment I submited.

Cheers!


🕸📝Fergus Duniho wrote on Mon, Oct 12, 2020 04:59 PM UTC in reply to H. G. Muller from Sun Oct 11 07:21 PM:

So I could write something like

def BadZone == 9 rank #destination =origin =destination =locustsqr =dropsqr =droppedpiece;

to get a function called with 5 parameters, and only testing if the second is on rank 9?

First, a matter of vocabulary. Function definitions have parameters, but function calls have arguments. An argument is a value passed to one of the parameters of a function. This will test whether the fourth argument from the right is a coordinate on rank 9, which would be the tenth rank. As long as you include five arguments in your function call, it will be the second argument from the left. If you had only four arguments, it would test the first one from the left. If you had three or less, that parameter would not be assigned a value. I know it's a bit counter-intuitive, but it's what comes from evaluating functions in reverse order, as Game Courier does.


🕸📝Fergus Duniho wrote on Mon, Oct 12, 2020 04:49 PM UTC in reply to Jose Carrillo from 01:07 PM:

Also, something went wrong with this game, which also just ended with the "won" command:

https://www.chessvariants.com/play/pbm/play.php?game=Petteia+-+Dmytro+Variation&log=j_carrillo_vii-halfer-2020-285-568

Are you sure you gave me the link to the correct game? This one doesn't include the won command in it.


🕸📝Fergus Duniho wrote on Mon, Oct 12, 2020 04:48 PM UTC in reply to Jose Carrillo from 12:44 PM:

Now it shows that my opponent (who resigned) won the game.

That's now been corrected.


Jose Carrillo wrote on Mon, Oct 12, 2020 01:07 PM UTC in reply to Fergus Duniho from 02:34 AM:

Fergus,

Also, something went wrong with this game, which also just ended with the "won" command:

https://www.chessvariants.com/play/pbm/play.php?game=Petteia+-+Dmytro+Variation&log=j_carrillo_vii-halfer-2020-285-568

I'm trying to view the moves to replay the game, and now I can't see any of the moves.

It just show the starting board without any of the moves played.

Thanks in advance.


Jose Carrillo wrote on Mon, Oct 12, 2020 12:44 PM UTC in reply to Fergus Duniho from 02:34 AM:

Thanks Fergus.

Now that the "won" command is working (and because by opponent had resigned to the game, while the won command didn't work) there was a strange behavior that affected the result for this game:

https://www.chessvariants.com/play/pbm/play.php?game=Latrunculi+XXI&log=j_carrillo_vii-cvgameroom-2020-281-060

Now it shows that my opponent (who resigned) won the game.

Can you please correct the result for this game? Thanks again.


🕸📝Fergus Duniho wrote on Mon, Oct 12, 2020 02:34 AM UTC in reply to Jose Carrillo from Sun Oct 11 10:03 PM:

To summarize, I fixed it.


Jose Carrillo wrote on Sun, Oct 11, 2020 10:03 PM UTC in reply to Fergus Duniho from 09:47 PM:

Fergus,

I'm not sure I understood your response.

Does the won command don't work anymore when entered as a move?

How are we supposed to claim a win when we checkmate in a preset that does not enforce the rules?

It would make more sense for the "won" command to work as a move than the "lost" command. For losing a game we have the alternative to "resign" command, but what is the alternative when we win by checkmate and we should claim a win immediately, rather than ask the opponent to resign a checkmated position?


25 comments displayed

LatestLater Reverse Order EarlierEarliest

Permalink to the exact comments currently displayed.