Back
Close
  • 415

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

Statement

 Goal

In chess, the board is split in 8 rows and 8 columns. Considering the view of the game to be from the white side, the utmost top left cell is called a8 and the utmost top rightcell is called h8. Decreasing from top to bottom of the chessboard, the utmost down left cell is then called a1 and the utmost down right cell is called h1.

A rook is a piece than can move as many cells as it want to vertically or horizontally. A rook can't go past an ally unit but can replace an opponent one.

Each position must be a valid chessboard-position notation (Algebraic notation) such that it is identified by a column identifier from a to h and a row identifier from 1 to 8.

Given a white rook and a set of chess pieces that can be yours (white) or not (black), print all available movements for the rook in the current configuration.
Input
First line : the position of the white rook
Second line : the amount P of pieces to be placed on the board
Next P lines : P space-separated lines containing attributes for each piece : color position

color is either 0 (WHITE) or 1 (BLACK)
position is the chessboard-notation of the position of the given piece
Output
A list of space-separated combination where combination has the following shape :

Rfrom_positionactionto_position with from_position being the actual position of the white rook and to_position being a possible destination for the white rook, both in the chessboard-position format. action should be x if the movement involves taking an opponent pieces, - otherwise.

For instance, if the white rook is in d5 and can move to d6, then the output must be Rd5-d6.
If the white rook is in e4 and can capture an opponent piece in e3, then the output must be Re4xe3

Moves must be sorted in ascending lexicographical ASCII order
Constraints
The grid is always an 8*8 matrix
Example
Input
d5
2
0 c1
1 e8
Output
Rd5-a5
Rd5-b5
Rd5-c5
Rd5-d1
Rd5-d2
Rd5-d3
Rd5-d4
Rd5-d6
Rd5-d7
Rd5-d8
Rd5-e5
Rd5-f5
Rd5-g5
Rd5-h5

A higher resolution is required to access the IDE