PROBLEM STATEMENT
Given a board configuration, you are to calculate the possible number of moves
for the red player in a game. The game is as follows:
10 black and 10 red marbles are placed on an 8x8 board with grooves as shown:
oooooooo
oooooooo
BBooooRR
BBBooRRR
BBBooRRR
BBooooRR
oooooooo
oooooooo
(Note: the starting configuration is for your information only. You are only
concerned with the given configuration in the input.)
Each turn, a player pushes 1 of his marbles, or a chain of 2 of his own marbles
in a line up, down, left, or right.
R-->
RR-->
Two of a player's marbles may push one of an opponent's marbles:
RRB->
A player's goal is to push the opponent's marbles off the board, so doing such
is a legal move. However, pushing a player's own marbles off the board is
illegal. The following are examples of illegal moves:
RRR-> (you cannot push 3 of your marbles in a row)
RB-> (you need 2 of your marbles to push 1 opponent marble)
RRBB-> (you cannot push 2 opponent marbles)
RBB-> (you cannot push 2 opponent marbles)
Also, a chain may NOT move laterally, as shown here:
ooo ooo
oRo -> ooR
oRo -> ooR
However, if you have a chain of 3 or more marbles, you can break it up as so:
RRRooooo
->
RoRRoooo
Given the current board configuration, calculate the number of legal moves for
the red player and return it as an int.
DEFINITION
Class name: Marbles
Method name: redMoves
Parameters: String[]
Returns: int
The method signature is:
int redMoves(String[] board)
Be sure your method is public.
board will be a String[] containing 8 elements of 8 characters each. These
Strings will contain either B (black), R (red), and o (empty groove). Valid
boards will contain between 5 and 10 of each color marble.
TopCoder will ensure the following:
*board contain exactly 8 elements.
*each element of board is exactly 8 characters in length.
*each character of each element of board will be either o (the lower case
letter), R, or B.
*There will be between 5 and 10 marbles of each color on the board, inclusive.
EXAMPLES
(quotes added for clarity)
board=
{"oooooooo",
"oooooooo",
"BBooooRR",
"BBBooRRR",
"BBBooRRR",
"BBooooRR",
"oooooooo",
"oooooooo"}
There are 20 possible moves for red (10 involve 1 marble and 10 involve 2
marbles), so the return is 20.
board=
{"BoBooRoR",
"oooooooo",
"BoBooRoR",
"oooooooo",
"BoBooRoR",
"oooooooo",
"BoBooRoR",
"oooooooo"}
There is 1 marble that has only 2 moves, 4 that have 3 moves, and 3 that have 4
moves. The return is 26.
board=
{"oooooRRB",
"oooooRBB",
"oooooRBB",
"oooooRRB",
"oooooooo",
"oooooooo",
"oooooooo",
"oooooooo"}
The return is 11 (2 of which involve pushing a black marble off of the board).