## Sunday, July 31, 2016

### TCS Code Vita Season-5 Round-1 set-1 Program-8

Problem : Bishop Moves

Background

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 text line and using only the ASCII character set. A FEN record contains six fields. A complete description of the FEN format to represent Chess positions can be found at
here

For the purpose of this problem only consider first of the six fields of FEN. Before we describe the problem, let us look at how FEN maps to a board position. The following 5 images show board positions and its corresponding FEN representation.

Figure 1.

 This board position depicts initial position before any side has made a move. In FEN format this board position is represented as  rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w

Let's say, White plays e4. Then the board position looks like shown below

Figure 2.

 This board position depicts the Chess board after White has played e4. In FEN format this board position is represented as  rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b

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

Figure 3.                                                  Figure 4.                                                      Figure 5.

The FENs corresponding to Figure 3, 4 and 5 are represented as

3. rnbqkbnr/pppp1ppp/8/4P3/4P3/8/PPPP1PPP/RNBQKBNR w
4. rnbqkbnr/pppp1ppp/8/4p3/4PP2/8/PPPP2PP/RNBQKBNR b
5. rnbqkbnr/pppp1ppp/8/8/4Pp2/8/PPPP2PP/RNBQKBNR w

Wikipedia describes first field of FEN format as follows

Each rank is described, starting with rank 8 and ending with rank 1; within each rank, the contents of each square are described from file "a" through file "h". Following the
Standard Algebraic Notation (SAN), each piece is identified by a single letter taken from the standard English names (pawn = "P", knight = "N", bishop = "B", rook = "R", queen = "Q" and king = "K").[1] White pieces are designated using upper-case letters ("PNBRQK") while black pieces use lowercase ("pnbrqk"). Empty squares are noted using digits 1 through 8 (the number of empty squares), and "/" separates ranks.

The second field denotes whose move it is now. "w" depicts that it is White's turn to play and "b" indicates that it is Black's turn to play

CodeVita Problem Statement

Given a board position in FEN format, your task is to find out all the move(s) that Bishop(s) of the playing side can make.

Input Format:
1.    First line contains single FEN record, which corresponds to a particular board position and also indicates whose turn it is.

Output Format:
1.    The output must be printed as follows
1.    All legal moves that Bishop can make must be in the format "[<Move Format>]"
2.    Where <Move Format> is move represented in format "[fromSquare][toSquare]"
2.    See Example section for better understanding of output format
3.    Follow Output printing specification to print the output in required format

Constraints:
1.    Since we focus on only first two parts of the FEN, we are essentially ignoring possibility of Castling. Hence our test cases don't contain FENs which give rise to such positions.

Sample Input and Output
 SNo. Input Board Depiction Output 1 3k4/8/8/2P1P3/3B4/2R1R3/8/4K3 w [] 2 3k4/8/8/4P3/3B4/2R1R3/8/4K3 w [d4a7, d4b6, d4c5] 3 3k4/8/8/8/3B4/8/8/1B2K3 w [d4h8, d4a7, d4g7, d4b6, d4f6, d4c5, d4e5, d4c3, d4e3, d4b2, d4f2, d4a1, d4g1, b1h7, b1g6, b1f5, b1e4, b1d3, b1a2, b1c2]

Print Specification:
2. If more than one move is possible, moves should be separated by a comma followed by whitespace
3. Moves of a single bishop should be printed in Move Format. Scan the board from 8th rank to 1st rank from a-file to h-file. Whichever square gets hit first, that move should be printed first.
4. If more than one bishop exists for side to move, then start scanning for bishop from 8th rank to 1st rank, left to right i.e. from a-file to h-file. Whichever bishop appears first, print all moves for that bishop first.
5. Verify your understanding of how printing should happen against examples shown above
Problem : Bishop Moves

Background

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 text line and using only the ASCII character set. A FEN record contains six fields. A complete description of the FEN format to represent Chess positions can be found at
here

For the purpose of this problem only consider first of the six fields of FEN. Before we describe the problem, let us look at how FEN maps to a board position. The following 5 images show board positions and its corresponding FEN representation.

Figure 1.

 This board position depicts initial position before any side has made a move. In FEN format this board position is represented as  rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w

Let's say, White plays e4. Then the board position looks like shown below

Figure 2.

 This board position depicts the Chess board after White has played e4. In FEN format this board position is represented as  rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b

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

Figure 3.                                                  Figure 4.                                                      Figure 5.

The FENs corresponding to Figure 3, 4 and 5 are represented as

3. rnbqkbnr/pppp1ppp/8/4P3/4P3/8/PPPP1PPP/RNBQKBNR w
4. rnbqkbnr/pppp1ppp/8/4p3/4PP2/8/PPPP2PP/RNBQKBNR b
5. rnbqkbnr/pppp1ppp/8/8/4Pp2/8/PPPP2PP/RNBQKBNR w

Wikipedia describes first field of FEN format as follows

Each rank is described, starting with rank 8 and ending with rank 1; within each rank, the contents of each square are described from file "a" through file "h". Following the
Standard Algebraic Notation (SAN), each piece is identified by a single letter taken from the standard English names (pawn = "P", knight = "N", bishop = "B", rook = "R", queen = "Q" and king = "K").[1] White pieces are designated using upper-case letters ("PNBRQK") while black pieces use lowercase ("pnbrqk"). Empty squares are noted using digits 1 through 8 (the number of empty squares), and "/" separates ranks.

The second field denotes whose move it is now. "w" depicts that it is White's turn to play and "b" indicates that it is Black's turn to play

CodeVita Problem Statement

Given a board position in FEN format, your task is to find out all the move(s) that Bishop(s) of the playing side can make.

Input Format:
1.    First line contains single FEN record, which corresponds to a particular board position and also indicates whose turn it is.

Output Format:
1.    The output must be printed as follows
1.    All legal moves that Bishop can make must be in the format "[<Move Format>]"
2.    Where <Move Format> is move represented in format "[fromSquare][toSquare]"
2.    See Example section for better understanding of output format
3.    Follow Output printing specification to print the output in required format

Constraints:
1.    Since we focus on only first two parts of the FEN, we are essentially ignoring possibility of Castling. Hence our test cases don't contain FENs which give rise to such positions.

Sample Input and Output
 SNo. Input Board Depiction Output 1 3k4/8/8/2P1P3/3B4/2R1R3/8/4K3 w [] 2 3k4/8/8/4P3/3B4/2R1R3/8/4K3 w [d4a7, d4b6, d4c5] 3 3k4/8/8/8/3B4/8/8/1B2K3 w [d4h8, d4a7, d4g7, d4b6, d4f6, d4c5, d4e5, d4c3, d4e3, d4b2, d4f2, d4a1, d4g1, b1h7, b1g6, b1f5, b1e4, b1d3, b1a2, b1c2]

Print Specification: