Beta

Validate FEN notation

Description
Loading description...
Strings
Regular Expressions
Algorithms
View
AllIssues3QuestionsSuggestions1Show Resolved
  • Please sign in or sign up to leave a comment.
  • mauro-1 Avatar

    (half)moves boundary cases are not tested.

    For example:

    halfmoves = moves*2 (False)
    halfmoves = moves*2-1, active='w' (False)
    
  • Loukis Avatar

    I did not understand how en passants are checked on the tests, i tried various forms of verification but every time it failed on a diferent spot

    all those FENs returns true
    pN4k1/2KnN2N/4RrK1/1qR1kKk1/2Br2Q1/b5bK/pn4k1/1RB3R1 w QqK a6 15 28
    2Q1bP2/1K2PN1B/6Bb/3rr3/4kB2/5np1/3K3n/2r1B3 b k a3 31 41
    K2PnPn1/1npK4/1k6/Bb2BbnP/3B1bb1/8/Nbb1k3/r3N3 w qkQ f3 34 116
    3nQk2/1B1B3b/4n3/RN2BN2/1b2qk2/1B1KbbQ1/1Nk5/qRb1B3 w QK d6 20 22

    but how, there isnt even a pawn near the row indicated

  • Blind4Basics Avatar

    Hi,

    I especially didn't like the checks you ask about the en passant moves. To have a valid configuration, those conditions should be met:

    • row number
    • the targeted place is empty
    • there is a pawn of the correct color "ahead"
    • the original position of the pawn is empty

    All those checks are doable right now.

    In a related fashion... why don't you validate that the number of pieces is at least possible?

    EDIT: btw, you could add the input in the assertion message for the fixed tests (they are given with the it blocks in the random tests: that's more comfortable for the user)

    • mingmingrr Avatar

      There could also be checks that:

      • there are no pawns on the 1st or 8th rank
      • there is exactly 1 king for either side
    • David Gildour Avatar

      Hi, thanks for the feedback. I'm aware of the simplicity of the en passant target validation that this kata requires. I've considered all the conditions you mentioned, and at first I wanted to include them in validation, but abandoned this idea, noticing how this would require much more complex random test generation. I thought that this kata is already quite fun as it is now. Or maybe I'm just too lazy :v On the side note, I don't feel that checking if the opposite color's pawn is able to capture the mentioned pawn is neccessary, for I see this notation only as an indication, that the pawn just moved two squares and is susceptible to the en passant capture, regardless of whether this capture is actually possible for the opposing color. But, aside from the en passant capturing, I think that adding at least the minimum board validation you mentioned would be a good idea, honestly I don't know why I didn't do that already. Will do.

    • Voile Avatar

      The checks besides en passant rules are problematic because they are possible in chess variants, which use the same FEN notations to store games. Lichess has lots of popular variants.

      there are no pawns on the 1st or 8th rank

      Violated by horde chess, which has pawns on one's own back rank. Besides, the chess rules used to not forbid promoting to a pawn (or even opponent pieces), which would cause pawns to exist on the opponent's back rank.

      there is exactly 1 king for either side

      Violated by anti-chess (there can be 0 kings for each side).

      the number of pieces is at least possible

      It depends on the variant.

  • ZED.CWT Avatar

    Are these valid or not?

    'rnbqkbnr/pppppppp/8/8/44/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
    'rnbqkbnr/pppppppp/8/8/2222/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
    
    
    'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR W KQkq - 0 1'
    'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR B KQkq - 0 1'
    
    • David Gildour Avatar

      Good questions. Splitting empty squares into separate groups, while not practical, is still a valid notation. This standard, AFAIK, nowhere states that it is not valid, and this still can be clearly interpreted as a valid row on a board. So the answer is yes, this is valid, although the tests don't check this. But as this is an interesting observation, I will include this in fixed tests. For the second part - as per description, the second field in the notation represents: Active color, either `w` or `b` for white and black accordingly. So this field shall take only one of these characters, uppercase letters are not valid. Same thing applies to the en passant target, as traditionally, the algebraic notation identifies square's file as a lowercase letter from a to h.

    • David Gildour Avatar

      Added a mention of the possibility of representing empty squares the way you pointed out, as well as a test that checks against it.

      Issue marked resolved by David Gildour 5 years ago
  • Voile Avatar

    Duplicate castling symbols test is missing from the fixed tests.