Programming Geek
Rated 4.7/5 based on 1446 reviews

CodeVita 2016 Round 2 Question: Mate In Two

Problem : Mate In Two


A Chess board position is accurately captured by Forsyth-Edwards notation and is abbreviated as FEN. A FEN "record" defines a particular game position, all in one line of text and using only the ASCII character set. A FEN record consists of six fields. A complete description of the FEN format to represent Chess positions can be found here


                    Figure 1.




                    Figure 2.



Similarly, 3 more half-moves are depicted in following diagrams

Figure 3.Figure 4.Figure 5.


           3. rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR

Wikipedia describes first field of FEN format as follows



Given a board position in FEN format, your task is to find out all move(s) that lead to a forced mate. White to play and win in 2 moves.

Input Format:

Output Format:
  1. The output must be printed as follows
    1. A string in format by "< move format >-< move format >-< move format >", where first move is white move, second is black move and third is again a white move
    2. Where < move format > is move represented in format "fromSquaretoSquare"
  2. See Example section for better understanding of output format

  1. The board position will always be White to move and mate in 2
  2. Since we focus on only first part of the FEN, we are essentially ignoring possibility of Castling being a mating move. Hence our test cases don't contain FENs which give rise to such positions.
  3. There is no need to handle En Passant positions. There are no test cases involving En Passant moves.
  4. No need to implement pawn promotion rules. Our test cases do not contain positions which will lead to a pawn getting promoted and inflicting a mate.
  5. There is exactly one forced mating sequence in our test cases. So once a forced mating sequence is found, there is no need to process further.

Sample Input and Output





Board position for sample input 1: 

                    Figure 6.

Mate enforcing moves for input 1: 

                    Figure 7.

Board position for sample input 2:                           

                    Figure 8.
Mate enforcing moves for input 2: 

                    Figure 9.

No comments :

Post a Comment