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 Earliest Comments Only For Pages | Games | Rated Pages | Rated Games | Subjects of Discussion ]

Single Comment

The Fairychess Include File Tutorial. How to use the fairychess include file to program games for Game Courier.[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote on Mon, Mar 23, 2020 04:05 PM UTC:

You should look at what's being done in the new fairychess preset for Chess. This is the one that is currently being used on the Game Courier page for Chess. Here is what the equivalent section looks like in that preset:

if sub const $moved $origin $dest and issub const $moved:
elseif fn const $moved $origin $dest and isfunc const $moved:
else:
  set name const $moved;
  set errmsg list "You may not move a" #name "from" $origin "to" join $dest ".<BR>";
  set desc join #name "-Desc";
  set errmsg str_replace "_" " " join #errmsg str_replace "%s" #name var #desc;
  die #errmsg;
endif;

Note that this is not using aliases. If you're using aliases, place alias before $moved. This code checks whether the piece has a subroutine defined for it. If it does, it calls the subroutine to check whether the move was legal. If it was legal, it does nothing. If one or both of these tests failed, it checks whether there is a function, and if there is one, it uses the function to check the legality of the move. If the move was legal, it does nothing. Finally, if the move failed both tests, it is illegal, and it reports an error message that uses the name of the piece and displays the description of how the piece moves.

It has occurred to me that if the subrountine is defined, and it fails the subroutine, it will then call the function. To prevent this, I have just added  and not issub const $moved to the end of the second line before the colon.