The X game is a two person game. The board is just a sequence of
boxes, some of which are randomly marked with an X before the game begins.
The two players
alternate turns. On each turn the player whose turn it is marks 1 or more
previously unmarked boxes. All her marks on the turn must be adjacent (with no wrap-around
at the ends) to each
other. The game continues until all the boxes are marked.
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.
A players wins the game if the sum of the points scored on all her turns is strictly greater than
her opponent's sum.
Create a class TheXGame that contains a method firstMove that is given a String
board indicating how many boxes there are, and which ones are marked with X before the
game begins.
The method returns the smallest number of Xs that the first player can mark on
her first turn (somewhere on the board) that will allow her to win the game if she
plays optimally thereafter. If no first
move puts the first player into a winning position, the method returns -1.
|