|
|
Here is a well organized list that should validate 99.99%+ of common positions:
Board:
- There are exactly 8 cols
- The row sum of the empty squares and pieces add to 8
Kings:
- See if there is exactly one w_king and one b_king
- Make sure kings are separated 1 square apart
Checks:
- Non-active color is not in check
- Active color is checked less than 3 times; in case of 2 that it is never pawn+(pawn, bishop, knight), bishop+bishop, knight+knight
Pawns:
- There are no more than 8 pawns from each color
- There aren't any pawns in first or last rows
- In case of en passant square; see if it was legally created (e.g it must be on the
x3 or x6 row, there must be a pawn (from the correct color) in front of it, and the en passant square and the one behind it are empty)
- Prevent having more promoted pieces than missing pawns (e.g
extra_pieces = Math.max(0, num_queens-1) + Math.max(0, num_rooks-2)... and then extra_pieces <= (8-num_pawns)), also you should do special calculations for bishops, If you have two (or more) bishops from the same square color, these can only be created through pawn promotion and you should include this information to the formula above somehow
- The pawn formation is possible to reach (e.g in case of multiple pawns in a single col, there must be enough enemy pieces missing to make that formation), here are some useful rules:
- it is impossible to have more than 6 pawns in a single column (because point NÂș2)
- it is impossible to have more than 5 pawns in
a or h columns
- the minimum number of enemy missing pieces to reach a multiple pawn in a single col
B to G 2=1, 3=2, 4=4, 5=6, 6=9 ___ A and H 2=1, 3=3, 4=6, 5=10, 6=impossible, for example, if you see 5 pawns in A or H, the other player must be missing at least 10 pieces from his 15 captureable pieces
- if there are white pawns in a2 and a3, there can't legally be one in b2, and this idea can be further expanded to cover more possibilities
Castling:
- If the king or rooks are not in their starting position; the castling ability for that side is lost (in the case of king, both are lost)
Bishops:
- Look for bishops trapped with pawns in the first and last row, these positions are tricky, they must be surrendered by 3 pawns, not because you see a trapped bishop by 2 pawns means it is illegal (a pawn under-promoting to a bishop could have done this), in the case of an under-promotion, remember to check for missing pawns
Other:
- Make sure the FEN contains all the parts that are needed (e.g active color, castling ability, en passant square, etc)
- If there are non-jumpers enemy pieces in between the king and rook and there are still some pawns without moving; check if these enemy pieces could have legally gotten in there. Also, ask yourself: was the king or rook needed to move to generate that position? (if yes, we need to make sure we have the castling abilities correctly)
Note: there is no need to make the 'players should not have more than 16 pieces' check because the points 'no more than 8 pawns' + 'prevent extra promoted pieces' + the 'exactly one king' should already cover this point
|