Problem Statement
The number of points scored by a player on his turn is equal to the number of boxes he marked on that turn times a multiplier. The multiplier gets bigger and bigger as the game goes on:
- first turn Player 1 multiplier=0
- second turn Player 2 multiplier=1
- third turn Player 1 multiplier=2
- fourth turn Player 2 multiplier=4
- fifth turn Player 1 multiplier=8
- ... etc.
Definition
- Class:
- TheXGame
- Method:
- firstMove
- Parameters:
- String
- Returns:
- int
- Method signature:
- int firstMove(String board)
- (be sure your method is public)
Constraints
- board will contain between 1 and 50 characters, inclusive.
- Each character in board will be 'X' or '-'.
- board will contain at least one '-'.
Examples
"X---X-X-"
Returns: 1
There are 8 boxes, 3 of them marked with X before the game begins. The first player can win by marking the third box. After that each player will only be able to mark one box one each turn, and the scoring will be: P1: 0*1; P2: 1*1; P1: 2*1; P2: 4*1; P1: 8*1 and player 1 wins with a score of 10 versus player 2's score of 5.
"----"
Returns: 2
The first player can win by marking the middle two spaces. After that, each player will mark one on each turn so player 1 wins by a score of 2 to 1. If the first player just marked one of the middle spaces, then the second player would mark 2 and the first player would mark 1 leaving the game tied (2 to 2).
"--XXX"
Returns: -1
The first player cannot win by marking both of them, since her first turn multiplier is 0!
"--------X-----X----X"
Returns: 3
"X-----X-------X---------X-----------"
Returns: -1
"--------------------------------------------------"
Returns: 2
"----X-----X----"
Returns: 1
"----XXX------XX--XXX"
Returns: -1
"-----XXX------XX--XXX"
Returns: 1
"---X----X-X-X-------X--------X"
Returns: 2
"-----X-X------------------------------X----------X"
Returns: 14
"-----X-X---------------------X----------X"
Returns: 5
"XXXXXXXXXX---XXXXXXXXXXXXXXXXXXXXXX-XXXXXXX"
Returns: 2
"--XXX--XX----X------------------------------"
Returns: 4
"--XXX--XX----X-----------------------------"
Returns: 3
"--XXX---XX----X------------------------------"
Returns: 5
"---------X--------X-----X-X-----------------------"
Returns: 2
"--XX---X---X----X------XX---X---X----X--"
Returns: 2
"--------X-X----------------X-X--X----X-----X-----"
Returns: 2
"--------------------------------------------------"
Returns: 2
"-----X---X----XXX---"
Returns: 1
"--------X-----X----X------------------------------"
Returns: 9
"-X--X----X-------"
Returns: -1
"--X----X---"
Returns: 3
"--XX---X---X----X------XX---X---X----X--"
Returns: 2
"--------X-X----------------X-X--X----X-----X-----"
Returns: 2
"--------------------------------------------------"
Returns: 2
"-----X---X----XXX---"
Returns: 1
"--------X-----X----X------------------------------"
Returns: 9
"-X--X----X-------"
Returns: -1
"--X----X---"
Returns: 3