[ List Earliest Comments Only For Pages | Games | Rated Pages | Rated Games | Subjects of Discussion ]
Check out Janggi (Korean Chess), our featured variant for December, 2024.
Check out Janggi (Korean Chess), our featured variant for December, 2024.
Now that the infrastructure for legality testing has been defined, we can pay attention to the heart of the move generator, the subroutine NextLeg. The first parameter of this indicate how many legs we will have yet to go. It is decremented every time the function recursively calls itself, and when it hits 0 we have completed the move, and can pass it to GotMove. Otherwise we have to retrieve the leg description from legdefs, and see if it is possible to move that way in the given position. The basic step of the leg is given, and the range specifies how many of those step we can maximally take. If this is 1, we are dealing with a leap. If it is larger, but the specified mode compells us to finish on a square with a particular occopant (friend or foe), there is still at most one way to do that. Only when the mode allows going to empty squares can we have more than one possibility to realize the leg, and even then the iso parameter can force the destination. But if we do have a 'free ride' we have to loop over all possible leg destinations, and if more legs follow, continue with the next leg from each of those. This happens for hook movers.
For phase 2 we only want to do castlings. These are encoded as two-leg moves, the first leg specifying a slide of the King that must end on the Rook. This is similar to a 'riendly capture' sliding leg, but still a special case in many ways: it must end in a specific location, the piece there must not have moved. So we have dedicated code for that, triggered by a special mode, only used for castling. Instead of following it by a new general leg through a recursive call, this dedicated code interprets the leg that follows by itself; the only info used from it is how many steps the King must move. Where the Rook will then reappear is implied by that.
This code tests for virginity in two places. First, in the general code, it tests the moving piece when the mode indicates we are dealing with an initial move (which for conventional castling will be the case). Then in the dedicated it tests whether the castling partner is virgin. For these tests it uses flags with the name of the board squares. This assumes that in the HandleMove routine, ater each move, there will be a setflag #desti; to indicate the destination square no longer contains its original occupant. If this flag is not set, together with the fact that the square is occupied, it is a guarantee that the original piece is still on the square without having moved.