Problem Statement
You are playing a board game called Jolly Jumpers. The game begins with some number of pawns on a 4x4 board. On each turn, you must either:
- Have one pawn jump over another pawn vertically. To do this, the jumping pawn must be vertically adjacent to the pawn it is to jump, with an empty space on the far side. The jumping pawn moves to the empty space, while the jumped pawn is removed from the game. Jumping a pawn scores two points.
- Move a pawn one space horizontally. The space it moves to must be empty. Moving a pawn means you lose one point.
You start the game with a score of zero points, and the goal of the game is to score as high as possible. You may stop moving at any time, including before your first move. The layout of the board will be given to you in the
For the layout given, return the maximum score you can achieve using any number of moves.
Definition
- Class:
- JollyJumpers
- Method:
- maxScore
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int maxScore(String[] layout)
- (be sure your method is public)
Constraints
- layout will contain 4 elements.
- Each element of layout will contain exactly 4 characters.
- Elements of layout will contain only '.' and '#' characters.
Examples
{ "....", ".#..", "..#.", "...."}
Returns: 1
Move either piece horizontally (-1 point), then jump vertically (+2 points).
{ "....", "....", "....", "...."}
Returns: 0
Not the most exciting layout...
{ ".#..", ".#..", "..#.", "...#"}
Returns: 4
{ "####", "####", "####", "####"}
Returns: 0
You can't move outside the board, so there's no moves available.
{ "#...", ".##.", "...#", "...."}
Returns: 3
{ "#...", ".##.", "...#", ".##."}
Returns: 7
{ ".###", "####", "####", "####"}
Returns: 22
{ "##..", "##..", "###.", "###."}
Returns: 14
{ "####", "####", "####", "#.##"}
Returns: 22
{ "####", "##.#", "####", "#.##"}
Returns: 21
{ ".###", "##.#", "##.#", "#.##"}
Returns: 17
{ "####", "#...", "#...", "#..."}
Returns: 5
{ "####", "#...", "#...", "#..#"}
Returns: 7
{ ".###", "#...", "#...", "#.#."}
Returns: 6
{ "##.#", "....", "....", "####"}
Returns: 0
{ "###.", "....", "....", "####"}
Returns: 0
{ "#..#", "....", "....", "####"}
Returns: 0
{ "##.#", "..#.", ".#..", "#..#"}
Returns: 7
{ ".##.", "#..#", "#..#", "####"}
Returns: 13
{ ".##.", "#..#", "#..#", ".##."}
Returns: 9
{ "##.#", ".#.#", "..##", "####"}
Returns: 15
{ "##.#", "##..", "####", "####"}
Returns: 19
{ "####", "####", "#..#", "####"}
Returns: 20
{ "####", "####", "##.#", "####"}
Returns: 22
{ "####", "####", "###.", "####"}
Returns: 22
{ "#.#.", "#...", "....", ".#.#"}
Returns: 5
2-1+2-1+2-1+2=5
{ "#...", "...#", "....", "...."}
Returns: 0
Moving is not worthwhile.
{ "#.#.", "....", ".#.#", "...."}
Returns: 0
{ "#...", "...#", "#...", "...#"}
Returns: 1
{ "#.##", ".#.#", ".#..", "#..#" }
Returns: 11
{ "#.##", "##.#", ".#.#", "#..." }
Returns: 12
{ "#...", "#.##", "####", "####" }
Returns: 18
{ "##.#", "#.##", "..##", "..#." }
Returns: 12
{ "#..#", ".#.#", "#.#.", ".#.." }
Returns: 8
{ "...#", "#.##", ".###", ".###" }
Returns: 14
{".###", "#.#.", "####", "#..." }
Returns: 12
{"#.#.", ".#.#", "#.#.", ".#.#" }
Returns: 8
{"#..#", ".#.#", "#.#.", ".#.#" }
Returns: 9
{"#.##", "##.#", "####", "####" }
Returns: 21
{"####", "####", "####", "###." }
Returns: 22
{"#..#", ".##.", ".#.#", "##.." }
Returns: 9
{"###.", "####", "##.#", "####" }
Returns: 21
{"#...", "##..", "#...", "...." }
Returns: 5
{"...#", "....", "..##", "#..." }
Returns: 1
{"##.#", "####", "#.##", "####" }
Returns: 21
{"##..", "....", "....", "...." }
Returns: 0
{"##..", "##..", "##..", "##.." }
Returns: 9
{"#.#.", ".#.#", "#..#", "##.." }
Returns: 10