Problem Statement
In this problem we are going to make an 11x11 chess board out of the Cartesian plane. The positions on our board will be the coordinates (x,y) where
You will be given a String[] pieces describing the locations of the rooks and bishops on the board. Each element will have the format (quotes for clarity) "x y P", where x and y are coordinates and P is Rook or Bishop. For example, "9 10 Rook" means there is a Rook at the position (9,10). Return the number of distinct positions that are collectively 'under control' by the given pieces. Note that the locations of the actual pieces should not be considered in the count. Hence, for the input above, you would return 27.
- 0 <= x <= 10,
- 0 <= y <= 10, and
- x,y are integers.
. . X . . . . X . . . . . X . . . X . . . . X X R X X X X X X X X X . X . X . . . . . . . X X X . . . . . . . . . B . . . . . . . . . X . X . . . . . . . X . . . X . . . . . . . . . . . X . . . . . . . . . . . X . . . . . . . . . . . X . . .
You will be given a String[] pieces describing the locations of the rooks and bishops on the board. Each element will have the format (quotes for clarity) "x y P", where x and y are coordinates and P is Rook or Bishop. For example, "9 10 Rook" means there is a Rook at the position (9,10). Return the number of distinct positions that are collectively 'under control' by the given pieces. Note that the locations of the actual pieces should not be considered in the count. Hence, for the input above, you would return 27.
Definition
- Class:
- UnderControl
- Method:
- howMany
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int howMany(String[] pieces)
- (be sure your method is public)
Constraints
- pieces will contain between 1 and 50 elements inclusive.
- Each element of pieces will have the form (quotes for clarity) "x y P" where:x is an integer with no extra leading zeros between 0 and 10 inclusive,y is an integer with no extra leading zeros between 0 and 10 inclusive, andP is either Rook or Bishop.
- No two pieces will be at the same location.
Examples
{"0 0 Rook"}Returns: 20
A rook in the lower left corner controls 20 squares. Each controlled square has the form (0,y) or (x,0) - with the exception of (0,0), which is the position of the rook.{"0 0 Bishop"}Returns: 10
A bishop in the lower left corner only controls 10 squares.{"5 5 Bishop"}Returns: 20
Near the center, the bishop controls more squares.{"0 5 Rook","2 5 Rook","5 5 Rook","9 5 Rook"}Returns: 47
Many rooks sharing the same y-coordinate.{"0 0 Bishop","1 1 Rook"}Returns: 20
The rook blocks the path of the Bishop.{"2 5 Bishop","2 8 Rook"}Returns: 27
The example in the problem statement.