Add the following methods for a game of Marble Solitaire to the code below:

1.The move method should make the move and change the game state . A move is valid if all these conditions are true:

(a) the “from” and “to” positions are valid

(b) there is a marble at the specified “from” position

(c) the “to” position is empty (d) the “two” and “from” positions are exactly two positions away (horizontally or vertically)

(e) there is a marble in the slot between the “to” and “from” positions. Any invalid move should result in an IllegalArgumentExceptionexception with an appropriate message on a single line. The text of the message is up to you.

A position is specified using a pair (row,column), assuming that the board is laid on a rectangular grid. The row and column numbers start at 0 (increasing top to bottom and left to right respectively). For example in the above picture, the positions of the three marbles in the top row are (0,2), (0,3) and (0,4) respectively. The empty slot is at (3,3). From this starting configuration, the only valid moves are from (5,3), (1,3), (3,1) or (3,5) to (3,3).

2. String getGameState() returns the current state of the game as a String object. The exact format of this string is dependent on the implementation (see below).

3. isGameOver returns true if the game is over, and false otherwise.

4. int getScore() returns the current score in the game.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *