hgm wrote:It is not that I am particularly fond of Omega Chess, but I don't quite see the need fo having only a single piece that can castle. What would go wrong if a game definition would contain both the lines:
Castle: e1-g1 with h1
Castle: d1-f1 with h1
The move generator uses three bitmasks for the generation of castling moves: one that indicates which pieces are required to be virgin, one that indicates which squares should be empty for castling to be possible and one that indicates which squares should be safe (not attacked) in order for castling to be legal. There are two sets of masks for white and two for black (so four sets in total). These masks are (re)calculated based on the FEN to accommodate Chess960-style castling and they keep the move generator fairly agnostic about what is actually going on: it just knows to move some pieces from where they are to a new location, and it pulls all relevant data from tables.
The reason this doesn't work with more than one piece is that the castle masks are defined for each game, rather than for each piece. That wouldn't be hard to change though. The origin for this is just that I used that design in Jazz and reused it for Sjaak. It never really occurred to me to make it a per-piece option (which I did actually do for promotion zones).
Why would a castle flag need to be explicitly specified with the piece anyway?
The reason the flag
exists is so the move generator can test whether to even try to generate castling moves for a particular piece before it starts testing bitmasks. You're right that it's implied by the definition of the castling move, so setting it explicitly should be redundant.
(I must admit that none of the examples in the variants.txt file conatins a Castle: line, though. Is a default assumed in that case? How does the default depend on the board width?)
There currently is no default, which means that the missing Castle: line is really a bug. I have to check if this is something that was already present in the older version of Sjaak, or whether this is something I introduced recently. For the default I would specify that for short castling the king moves next to the corner, long castling moves the same number of squares in the opposite direction and castling is done with the corner piece.
But as I said, it doesn't actually do this now.
BTW, if a non-royal piece is given castling rights, would it be allowed to castle over attacked squares?
No, but that could easily be changed by setting the "must be safe" masks to 0 if the castling piece is non-royal.
So really the reasons this doesn't work properly right now are
- Castle masks are defined per-game rather than per-piece (changing this is straightforward)
- Castling with non-royal pieces would be disallowed if it passes over "unsafe" squares (very easy to fix)
- By default, all castling moves would be output as O-O or O-O-O, independent of whether the moving piece is a king or (say) a queen.
The last point is probably the most annoying one in practice. The reason SjaakII prefers O-O and O-O-O for castling moves was originally that this allows it to treat Chess960 and ortho-chess as the same game: XBoard protocol defines O-O and O-O-O as castling notation for Chess960 and understands it for orthochess. In practice this isn't so straightforward because UCI interfaces
doesn't understand O-O/O-O-O and (worse) don't understand KxR if the variant is not set to Chess960 (I ran into this awhile back).
Even if I get rid of O-O/O-O-O though it'll be annoying to work out what exactly to send to the GUI for a (non-standard) castling move since the easy alternative (always sending "KxR", ugly as it is) doesn't always work...