Check out Glinski's Hexagonal Chess, our featured variant for May, 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 by Fergus Duniho

Later Reverse Order EarlierEarliest
Game Courier Logs. View the logs of games played on Game Courier.[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote at 06:51 PM UTC in reply to H. G. Muller from 07:19 AM:

Marking of attacked squares to weed out illegal King moves is just one of the two things the accelerated check test does. The other thing is that it tabulates for each board square which (attempted) sliding moves visit it.

It's not the same thing that you're doing, but I have now made a quicker version of stalemated called stalemated-quick, which does some preprocessing to reduce the work involved in checking for check. It starts by creating an array of the King's location and each space it may move to, and for each location in this array, it makes an array of every location with an enemy piece that has it in its range. The code looks like this:

// Build threat lists
set krange merge fn join const alias space #kingpos "-Range" #kingpos #kingpos;
set threats ();
for to #krange:
  set threats.{#to} ();
next;
for (from piece) fn #enemies:
  set in intersection var krange fn join const alias var piece "-Range" var from;
  for to #in:
    push threats.{#to} #from;
  next;
next;

So it creates multiple elements of an array called threats, each of which is an array of the enemy pieces that include that space in its full range of movement. At the start of Chess, threats.d2 and threats.d1 both have one element set to d8, and the others (elements e1, e2, f1, and f2 of threats) are empty.

To check for check, it first assumes a value of false, and it tries out the move only if there are pieces potentially threatening the space the King is on. That move looks like this:

set checkpos cond == #from #kingpos #to #kingpos;
set checked false;
if count elem var checkpos threats:
  move #from #to;
  set checked fn threatened #checkpos;
  restore;
endif;

Instead of using the checked function, it used the threatened function, which looks like this:

def threatened anytrue lambda (fn const alias space #0 #0 var king) 
elem var king threats 
=movetype CHECK 
=king;

This function expects threats to be populated with appropriate values. So it can't be used everywhere checked can.

In tests with Chess, everything seems to be working. After making sure it worked, I did some speed tests comparing 100 calls to stalemated with 100 calls to stalemated-quick. In each pair, stalemated is first, and stalemated-quick is second. The results show that stalemated-quick is normally quicker.

Elapsed time: 4.7686970233917 seconds

Elapsed time: 2.8460500240326 seconds

Elapsed time: 4.8747198581696 seconds

Elapsed time: 3.0506091117859 seconds

Elapsed time: 4.4713160991669 seconds

Elapsed time: 2.9584100246429 seconds

🕸📝Fergus Duniho wrote at 02:09 AM UTC in reply to H. G. Muller from Mon May 13 08:30 PM:

That would indeed be an alternative: do a full king-capture test after every King move. But it would be more expensive, as a King usually has several moves.

It's more than that. I do a full king-capture test for every pseudo-legal move by every piece that can move. My code works like this.

  1. It goes through every piece from the side that can move.
  2. For each piece on the side that can move, it calculates the spaces within its range of movement. This is an optimization to keep it from checking for legal moves to every position on the board.
  3. For each space within a piece's range of movement, it checks whether the piece has a pseudo-legal move there.
  4. For each pseudo-legal move, it tries the position and checks whether it places the King in check.
  5. It checks whether the King is in check by checking whether any enemy piece can move to the King's space. As an optimization, it returns true as soon as it finds one check.
  6. It checks whether a piece may move to the King's space by calling its function for the move from its location to the King's space.
  7. Divergent pieces are handled by writing them to behave differently when the movetype variable is set to CHECK. In the following example, the function for the White_Pawn first checks some conditions any Pawn move must meet, then handles capturing, then continues to handle non-capturing and en passant moves only if movetype is not CHECK.
def White_Pawn
remove var ep
and < rankname #1 var bpr
and < rankname var ep rankname #1
and == filename var ep filename #1
and checkleap #0 #1 1 1
and var ep
or and checkride #0 #1 0 1 == rankname #0 var wpr
or checkleap #0 #1 0 1
and empty #1
and != var movetype CHECK
or and islower space #1 checkleap #0 #1 1 1
and any onboard where #1 0 1 == var movetype CHECK count var wprom
and <= distance #0 #1 var fps
and > rank #1 rank #0;
  1. Pieces with non-displacement captures are handled by writing two different functions for them and using the value of movetype to call the correct function.

So you would have to do enemy move generation several times.

Since my code uses piece functions, this is not a big problem. In tests I ran yesterday, my checked function ran 1000 times in under half a second, and the checked subroutine got called 1000 times in close to a second, and this was on a position in which the King was not in check, which meant it never broke out early. Since your code does not use piece functions, it may handle the evaluation of moves more slowly, which will also cause it to evaluate check more slowly.

Testing whether a destination contains the King is not any more expensive than marking the destination. And to do it, you only need to geenrate all enemy moves once.

This optimization might be helpful when not using piece functions, but one thing about it concerns me. While it might be helpful in determining whether a move by the King would be into check, I'm not sure it will work for revealed checks. It is because of the possibility of revealed checks that my code checks for check for the position resulting from every single pseudo-legal move it finds.

I suppose one optimization that could be made if it were needed would be to identify the pieces that might possibly check the King at its current location, then limit the test for whether a move by another piece places the King in check to those pieces. This could be done by making a short list of every enemy piece whose range of movement contains the King's location and having the checked function use it instead of onlyupper or onlylower. If this list were empty, it could even skip the step of trying out a pseudo-legal move and testing whether it places the King in check.

However, this might not work for non-displacement captures in which the capture occurs outside the piece's range of movement, such as the Coordinator capture in Ultima. So, I have to balance efficiency with the work a programmer has to make to use a piece in a game. The brute force method I use helps reduce the work the programmer has to do to make different kinds of pieces work with it.


🕸📝Fergus Duniho wrote on Mon, May 13 07:35 PM UTC in reply to H. G. Muller from 05:54 PM:

The issue was that the test for being already in check was done with the King taken off the board

Why would you take the King off the board for this? Couldn't this cause false positives and false negatives from divergent pieces like Pawns or Cannons?

This was a bug that did not yet express itself. A Checker diagonally adjacent to the enemy King would not deliver check if a friendly piece was immediately behind that King, blocking the landing square. But that blocking piece would then essentially be pinned, and its moves should not be highlighted.

The code I use avoids this by trying each pseudo-legal move and checking whether any piece in the new position is checking the King.


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, May 13 02:20 AM UTC in reply to Fergus Duniho from Sun May 12 10:29 PM:

I was thinking of splitting the checked function into separate checked-real and checked-potential functions, but as I was looking into which would be which, it looked like there was never any time when it was passed an empty space after the King just moved. In the Pre-Move sections, kpos or Kpos would be updated before calling the function, and in stalemated, it would check whether the King was the moving piece and pass the King's new position if it was. This meant I could reduce the function to this:

def checked anytrue lambda (fn const alias #0 var key var king) 
cond isupper space var king (onlylower) (onlyupper) 
=movetype CHECK 
=king;

Just in case, I ran this code in Ultima as a test:

sub checked king:
  my from piece;
  local movetype;

  set movetype CHECK;
  if empty var king:
    die "The King space at {#king} is empty.";
  endif;
  if isupper cond empty var king $moved space var king:
    def enemies onlylower;
  else:
    def enemies onlyupper;
  endif;
  for (from piece) fn enemies:
    if fn const alias #piece #from var king:
      return #from;
    endif;
  next;
  return false;
endsub;
def checked sub checked #0;

This code would exit right away with an error message if the subroutine, which was called by the function here, got passed an empty space. I then looked at completed games using the same include file, and they did not exit with the error message. So, I got rid of this code and modified the function, tested Ultima again, and it still worked for both actual checks and for moves that would move the King into check.

With that change made, I ran the speed tests again and got these results:

Elapsed time: 1.0438919067383 seconds

Elapsed time: 0.46452307701111 seconds

Elapsed time: 1.013090133667 seconds

Elapsed time: 0.48957395553589 seconds

Elapsed time: 1.1313791275024 seconds

Elapsed time: 0.49660110473633 seconds

In each pair the subroutine is first, and the function is second, and in each case the function takes less than half the time. In both this case and the previous one, these tests were done on the opening position in Chess, in which the King is not in check, meaning that it checks for check from every enemy piece without exiting early.


Rococo. A clear, aggressive Ultima variant on a 10x10 ring board. (10x10, Cells: 100) (Recognized!)[All Comments] [Add Comment or Rating]
🕸Fergus Duniho wrote on Sun, May 12 10:39 PM UTC in reply to NeodymiumPhyte from 08:35 PM:

I asked David Howe about the situation where a Chameleon can capture a Cannon Pawn by hopping over an enemy Long Leaper, and he says "The Long Leaper is not captured. The Long Leaper capturing move requires moving to a vacant square."


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 Sun, May 12 10:29 PM UTC:

The changes to Game Courier I described here were for the purpose of writing a checked function that would do the same job as the checked subroutine but even faster. This is for the sake of illustrating the gains in speed of using functions rather than subroutines when a function will do the job. Here's the code for the subroutine and the function:

sub checked king:
    my from piece;
    local movetype;

    set movetype CHECK;
    if isupper cond empty var king $moved space var king:
        def enemies onlylower;
    else:
        def enemies onlyupper;
    endif;
    for (from piece) fn enemies:
        if fn const alias #piece #from var king:
            return #from;
        endif;
    next;
    return false;
endsub;

def checked anytrue lambda (fn const alias #0 var key var king) 
cond isupper cond empty var king $moved space var king (onlylower) (onlyupper) 
=movetype CHECK 
=king;

I have tested the function out in Ultima, because its stalemated subroutine is not widely used in other presets, and its piece functions make use of the movetype value to determine whether it is a regular move or a checking move. Things appear to be working in Ultima. In speed tests comparing 1000 repetitions of each, the function is around twice as fast. In these results, the first, third, and fifth are the subroutine, and the second, fourth, and sixth are the function.

Elapsed time: 0.92847084999084 seconds

Elapsed time: 0.45569705963135 seconds

Elapsed time: 0.87418103218079 seconds

Elapsed time: 0.46827101707458 seconds

Elapsed time: 1.1367251873016 seconds

Elapsed time: 0.65254402160645 seconds

Game Courier History. History of the Chess Variants Game Courier PBM system.[All Comments] [Add Comment or Rating]
🕸💡📝Fergus Duniho wrote on Sun, May 12 08:53 PM UTC:

I made a change to the following functions that can run lambda functions on array values: aggregate, allfalse, nonetrue, alltrue, anyfalse, anytrue, any. These will now have access to the variable key, which will contain the key of the array value currently passed to the lambda function. This should be accessed with the var keyword to make sure that a previously defined variable is not being used.

To prevent expressions using these from changing the value of a previous variable called key, I had to raise the scope of every expression. But to get this to work, I had to rewrite each built-in function that exited the PHP function for evaluating expressions with a return. Instead of using return, I had each one set $output to a single element array with the return value, and I set $input to an empty array so that the condition on the while loop would be false. Doing this makes sure that it decrements the scope before exiting the function.

Raising the scope of an expression also makes sure that the mechanism for adding named variables to a function cannot be used in an expression to set a variable that lasts beyond the expression. The following code prints 6468, then it prints 63. This is because it raises the scope for the assignments in the expression, and when it completes the expression, it closes that scope.

set o 9;
set y 7;
set pp * var o var y =o 98 =y 66;
echo #pp;
print * #o #y;

Home page of The Chess Variant Pages. Homepage of The Chess Variant Pages.[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote on Sat, May 11 06:14 PM UTC:

I noticed today in the comments section that Smess was being given the description for Take the Brain. So, I made some corrections to make sure that the correct description was given for the name it was paired up with in IndexEntry. In the comments section, the primary name and description should now be used. In queries of the database on the names of games, each description will now show up for the name it goes with. On the What's New page, the name should be the primary name, and the description should be the Whatsnew text if it is available. Otherwise, it will fall back to using the primary description. All of this now works correctly for Smess, All the King's Men, and Take the Brain, though I have not tested other games with multiple names.


Smess. (Updated!) Produced and sold in the early 70's by Parker Brothers. Arrows on squares determine direction pieces can move. (7x8, Cells: 56) (Recognized!)[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote on Sat, May 11 05:03 PM UTC in reply to Fergus Duniho from 12:38 AM:

Because the Ivorytower pieces looked a little small on the board, I reduced the size of the board from 83x83 squares to 73x73 squares. The original board had 83x73 squares to give it a more square shape with a 7x8 layout, but the 73 pixel width works better for the Ivorytower pieces, because they can now fully cover up the oval on some spaces that names the piece starting from that position. I also tried 60x60 spaces, as that is the size used in Storm the Ivory Tower, but the Blue Brain was covering up too much of the forward arrow on its space. So I reverted to 73x73.

While the Ivorytower pieces do look better, they are still rough around the edges. and I think they would look better as SVG pieces.


🕸📝Fergus Duniho wrote on Sat, May 11 12:38 AM UTC in reply to HaruN Y from Fri May 10 01:43 AM:

I got your diagram to display correctly and added it to the page with some modifications. To make the board display correctly without tiling, I removed the firstRank assignment and set borders to 0. I replaced the graphics with ones I created for Smess. The board is a stretched version of one I made for Game Courier, and the pieces are the ones I made for Storm the Ivory Tower, which have smoother edges. I set useMarkers to 1 to stop it from changing the background color of a space when highlighting it, but this doesn't work for moves made by the opponent. Since it is important to not hide the arrows on the board, it would be helpful if useMarkers would also change how the opponent's moves are highlighted.


🕸📝Fergus Duniho wrote on Fri, May 10 09:30 PM UTC in reply to Fergus Duniho from 09:10 PM:

I created and used a new board with 83x83 spaces, and I set squareSize to 83, but now the board is starting halfway into the first rank and tiling on the right side. What can I do to fix that?


🕸📝Fergus Duniho wrote on Fri, May 10 09:22 PM UTC in reply to Fergus Duniho from 09:10 PM:

I changed the board image to the one that goes with the pieces, and it looks a lot better, but there are still some alignment issues. The spaces on the board are rectangular with a width of 83 and a height of 73, but the squareSize parameter seems to expect one value that gets used for both height and width. Is there any way to specify height and width separately? In the meantime, I'll make a resized copy of the board with square spaces.


🕸📝Fergus Duniho wrote on Fri, May 10 09:10 PM UTC in reply to Fergus Duniho from 09:06 PM:

Also, I added the same code to the Smess diagram, and it is now tiling with the pieces on it. Since I made those pieces for a larger board, I think the board image and the pieces are not at the same scale.


🕸📝Fergus Duniho wrote on Fri, May 10 09:06 PM UTC in reply to H. G. Muller from 08:02 PM:

For some reason this does not work anymore. The I.D. on the Eurasian Chess page also lost its background, and I am sure this worked before. Is there some global style definition now that gives elements a background color?

Looking at it with Web Developer Tools in Firefox, I see that TABLE TR has the background-color value of var(--nav-bgcolor), and when I turn it off, the background image shows up. With that in mind, I added this to the Eurasian Chess page, and that fixed it:

<STYLE>
TABLE#board0 TR {background-color: inherit;}
</STYLE>

Would it be a good idea to add this to global.css?


Game Courier Logs. View the logs of games played on Game Courier.[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote on Fri, May 10 04:09 PM UTC in reply to H. G. Muller from 02:54 PM:

The reliable method would try out all pseudo-legal moves, and then generate opponent moves in each of the resulting positions, to see if any of those captures the King. All opponent moves will have to be tried to conclude the move is legal (which usually is the case), and on a large variant this can take very long (to the point where GC aborts the GAME-code execution).

Thanks to GAME Code being an interpreted language written in another interpreted language, it is not as quick at things compiled languages would do more quickly, and it will sometimes exceed the time limit that PHP imposes on script execution. This makes optimizations and short cuts more important, and in hand-written code, I have done this. See my previous comment about how I handled the spotting of check in Ultima as an example.

In automatically-generated code, it might be harder to get in the optimizations needed for particular games. So I would suggest a compromise between your quick method and your reliable method. Flag pieces that can capture a piece without moving to its space, and use your reliable method on these while just checking if other pieces can move to the King's space.


Smess. (Updated!) Produced and sold in the early 70's by Parker Brothers. Arrows on squares determine direction pieces can move. (7x8, Cells: 56) (Recognized!)[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote on Fri, May 10 03:56 PM UTC in reply to HaruN Y from 01:43 AM:

This isn't showing up well on any browser or OS I've seen it on. On my iPad, I see the arrowed board both above and below the blank 7x8 board with the pieces, and the one above is tiled. On Android and Windows, the tiled board is not appearing at the top, but the pieces are still not appearing on the same board as the arrows.


Game Courier Logs. View the logs of games played on Game Courier.[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote on Fri, May 10 01:16 PM UTC in reply to H. G. Muller from 05:58 AM:

You did not get the point. Does the preset say 'check' when you check with any other piece than an Advancer? I think it doesn't. So then this has nothing to do with the piece being an Advancer.

I dug back into this thread to find the preset he was talking about. He linked to a particular game in which neither Advancer checked the opponent's King. Continuing this game by choosing Annotate and then Move, I played some moves to get a White Flying Dragon to check the Black King, and when I did, it said "check!". After moving the King out of check, I tried to move White's Advancer, but no legal moves are being highlighted on the board for it. However, its legal moves do show up in the Moves field, and when I tried one, it worked. At the top of the Moves field, I see the legal move "A e1-#to; A #to-b1". I think this is not a properly formatted move, and it may be interfering with the ability to recognize the Advancer's legal moves. Also, when I entered it, it did not recognize it as legal, and it gave the error message "#to is not a valid square".

Here are the moves to the position in question so that you can see what's going on.

1. P f2-f5 
1... p f9-f6 
2. P e2-e4 
2... p e9-e7 
3. F i1-h3 
3... f i10-h8 
4. P i2-i3 
4... p d9-d8 
5. B h1-i2 
5... c g10-f7 
6. C d1-f3 
6... f b10-c8 
7. C g1-e3 
7... c d10-f8 
8. K f1-i1 
8... p g9-g7 
9. P b2-b3 
9... c f8-e5 
10. P d2-d4 
10... c e5-f8 
11. B c1-b2 
11... a e10-h7 
12. F b1-e2 
12... p i9-i8 
13. P g2-g5 
13... c f7-e8 
14. P g5-g6 
14... a h7-f9 
15. P c2-c4 
15... p b9-b6 
16. F h3-g2 
16... c e8-d7 
17. P d4-d5 
17... f c8-d6 
18. F e2-h3 
18... p c9-c7 
19. C f3-e6 
19... c d7-e6 
20. P d5-e6 
20... p j9-j8 
21. B b2-a3 
21... b c10-a8 
22. B a3-d6 
22... p e7-d6 
23. R h1-f1 
23... p j8-j7 
24. F g2-d3 
24... b h10-j8 
25. C e3-g1 
25... f h8-i6 
26. P j2-j3 
26... p d8-d7 
27. P a2-a5 
27... p b6-a5 
28. R a1-a5 
28... b a8-b9 
29. P e6-d7 
29... f9-e8;@-d7 
30. C g1-a7 
30... f i6-h4 
31. C a7-d8 // - check! -
31... k f10-f9

Just click on Annotate for Butterfly Chess and paste these in to see the same position.


🕸📝Fergus Duniho wrote on Thu, May 9 10:18 PM UTC in reply to Kevin Pacey from 08:57 PM:

Yes, I originally would have thought when an Advancer made a move that threatened a King, an enforcing preset would automatically announce check.

However, maybe the Advancer, being an Ultima-like piece, does not actually make a check in an Ultima-like game (which Butterfly Chess is not)?

So I now ask, is that the usual assumption that Applet generated preset code makes for every CV put through the generating process?

I don't know how a generated preset works, but the checked subroutine I use in the fairychess include file normally checks for captures by displacement by checking if each enemy piece on the board can move to the King's position. This would not normally work with Ultima pieces, which do not normally capture by displacement, but I have managed to use this subroutine with Ultima without modifying it. First, let's look at the subroutine:

sub checked king:
    my from piece;
    local movetype;

    set movetype CHECK;
    if isupper cond empty var king $moved space var king:
        def enemies onlylower;
    else:
        def enemies onlyupper;
    endif;
    for (from piece) fn enemies:
        if fn const alias #piece #from var king:
            return #from;
        endif;
    next;
    return false;
endsub;

The key to working with Ultima is that it sets movetype to CHECK. With this in mind, I have written functions for Ultima pieces like this:

def Black_Withdrawer fn join "Black_Withdrawer_" var movetype #0 #1;

Depending upon the value of movetype, it will call either Black_Withdrawer_MOVE or Black_Withdrawer_CHECK, which I have defined separately and differently. Thanks to setting movetype to CHECK, the checked subroutine will use the *_CHECK functions for Ultima pieces. Instead of going through a normal move, one of these functions will check whether the piece at the first coordinate can capture the piece at the second. For example:

def Black_Withdrawer_CHECK 
empty where #frm - file #frm file #to - rank #frm rank #to
and == distance #frm #to 1
and not near #frm I 1
=frm =to;

This first makes sure that the piece is not next to a White Immobilizer (designated as I). It then verifies that the two spaces are adjacent. Calculating the direction away from the piece at #to, it checks whether there is an adjacent empty space in that direction. If there is, it returns true.


Crossroads. Members-Only Crossing the diagonals generate figures. (9x9, Cells: 81) [All Comments] [Add Comment or Rating]

Since this comment is for a page that has not been published yet, you must be signed in to read it.

Since this comment is for a page that has not been published yet, you must be signed in to read it.

Since this comment is for a page that has not been published yet, you must be signed in to read it.

Since this comment is for a page that has not been published yet, you must be signed in to read it.

Since this comment is for a page that has not been published yet, you must be signed in to read it.

Since this comment is for a page that has not been published yet, you must be signed in to read it.

Game Courier. PHP script for playing Chess variants online.[All Comments] [Add Comment or Rating]
🕸💡📝Fergus Duniho wrote on Thu, May 9 04:12 PM UTC in reply to Aurelian Florea from 06:59 AM:

You need code in your Post-Move sections to control what is allowed on the first turn. Setting legal moves in the Post-Game section is not enough, because these will only be used for which legal moves are highlighted for the player. They will not control which legal moves are allowed.


25 comments displayed

Later Reverse Order EarlierEarliest

Permalink to the exact comments currently displayed.