In the sample code for queen moves, after the quasi-legal attack board is generated, there is code to detect if the piece is within the range of the king as a 'superpiece' (except knight moves).
B = SetBit(fr) & MaskRook[ksqr] & PosInfo[ply].KingVulnAtk[wtm];
if (B) { // Possible rook pin
B = Atk & MaskRook[fr] & MaskRook[ksqr];
if (B & (Pieces[!wtm][Rook] | Pieces[!wtm][Queen])) {
Atk = B;
goto RollQueen;
}
}
If in range, (B not empty), then I look at the possibly pinned queen as a rook, to detect if any opponent rooks or queens is within the range of the queen and the king, using MaskRook. If so, the piece is pinned and the attack board Atk holds the legal moves within the pin. Of course, if the piece was a knight, the code would just say 'continue' because of no legal moves.
Lasse Hansen wrote:One nice thing is that when not in check, all queen, rook, bishop and knight moves are legal by default, pinned or not.
Could you explain this, please? To my understanding, moving a pinned knight is always illegal, as well as for instance moving a rook pinned by a bishop or a bishop pinned by a rook, etc. So maybe I did not get your point in that sentence above.
Sven
You can also have a bishop pinned by a bishop, so it can only move on one diagonal, ditto for a rook or queen...
A FEN record always has EXACTLY SIX fields. No program is obligated to interpret an invalid FEN record, and no program should generate an invalid FEN record.
Also, the ordering of the castling availability is KQkq.
r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1
Another reminder.
One can be draconian, or flexible. For example, how do you enter castle short?
o-o, O-O, or 0-0? Last one is zero-zero.
I learned YEARS ago to accept all of those, otherwise parsing book moves from PGN collections was basically impossible. My take has always been to take whatever is recognizable...
sje wrote:A FEN record always has EXACTLY SIX fields. No program is obligated to interpret an invalid FEN record, and no program should generate an invalid FEN record.
One can be draconian, or flexible. For example, how do you enter castle short?
o-o, O-O, or 0-0? Last one is zero-zero.
Flexible on input, draconian on output.
Anyway, for years nearly all chess data is generated via a program, either an engine or a GUI. So guessing at non-standard move input isn't all that important nowadays.
sje wrote:A FEN record always has EXACTLY SIX fields. No program is obligated to interpret an invalid FEN record, and no program should generate an invalid FEN record.
One can be draconian, or flexible. For example, how do you enter castle short?
o-o, O-O, or 0-0? Last one is zero-zero.
Flexible on input, draconian on output.
Anyway, for years nearly all chess data is generated via a program, either an engine or a GUI. So guessing at non-standard move input isn't all that important nowadays.
Problem is, there are MILLIONS of games that were not produced by a computer. Can't do much about the ones with illegal moves, of course, but incorrect syntax can be handled. Things like 1.e4 rather than 1. e4, for example, seems to be pretty common.
Lasse Hansen wrote:One nice thing is that when not in check, all queen, rook, bishop and knight moves are legal by default, pinned or not.
Could you explain this, please? To my understanding, moving a pinned knight is always illegal, as well as for instance moving a rook pinned by a bishop or a bishop pinned by a rook, etc. So maybe I did not get your point in that sentence above.
Sven
You can also have a bishop pinned by a bishop, so it can only move on one diagonal, ditto for a rook or queen...
I know, Bob. My point was, the OP wrote "are legal by default" and I was not sure whether he meant "in general" or "with my move generator". The term "by default" was not clear. Now it is.
Anyway, for years nearly all chess data is generated via a program, either an engine or a GUI. So guessing at non-standard move input isn't all that important nowadays.
Problem is, there are MILLIONS of games that were not produced by a computer. Can't do much about the ones with illegal moves, of course, but incorrect syntax can be handled. Things like 1.e4 rather than 1. e4, for example, seems to be pretty common.
That may be true, but very little new ASCII chess data is created by hand. Eventually, bad PGN data will be hard to find, just like English Description Notation games are hard to find today.
The "1.e4" vs "1. e4" is a minor issue compared to getting the SAN incorrect. Unfortunately, there may still be some programs that crank out bad SAN on occasion; Stockfish was one of these until a week ago.
Stockfish has been fixed, but there way be other programs with the same bug. For anyone with an interest, I've got a PGN file with a million random games for use in testing. And now that I've got a Windows 7 machine, I can test a lot of commercial software. Well, if vendors will send me evaluation copies.
Lasse Hansen wrote:One nice thing is that when not in check, all queen, rook, bishop and knight moves are legal by default, pinned or not.
Could you explain this, please? To my understanding, moving a pinned knight is always illegal, as well as for instance moving a rook pinned by a bishop or a bishop pinned by a rook, etc. So maybe I did not get your point in that sentence above.
Sven
You can also have a bishop pinned by a bishop, so it can only move on one diagonal, ditto for a rook or queen...
I know, Bob. My point was, the OP wrote "are legal by default" and I was not sure whether he meant "in general" or "with my move generator". The term "by default" was not clear. Now it is.
Sven
That was the reason I responded as well. I generally think "pseudo-legal" for efficiency reasons.