Question: * * * * * * * * * * * * * * * * * * * * * * * * *
You must use all the given methods without changing their signature.
However you may add new methods using the given ones if necessary.
public class PegSolitaireBoardProfVersion
protected char pegBoard;
private static final int UP ;
private static final int DOWN ;
private static final int LEFT ;
private static final int RIGHT ;
Initializes the board at its starting position
XXX
XXX
XXXXXXX
XXXOXXX
XXXXXXX
XXX
XXX
public PegSolitaireBoardProfVersion
this.pegBoard new char;
for int i ; i ; i
for int j ; j ; j
if i && j
this.pegBoardij;
else if i && j
this.pegBoardij;
else if i && j
this.pegBoardij;
else if i && j
this.pegBoardij;
else if i && j
this.pegBoardijO;
else
this.pegBoardijX;
moves the Xs and Os to the corresponding positions after the jump happens
private boolean moveForwardint x int y int direction
Implement moveForward here
The error will go away once you implement and returns a boolean
value
return false;
moves the Xs and Os back to their initial position before the jump
occurred
private void moveBackwardint x int y int direction
Implement moveBackward here
private void addPegint x int y
pegBoardxyX;
private void removePegint x int y
pegBoardxyO;
check if the jump is valid
checks if the result of the jump will be out of bounds
checks that the X performing the jump has one more X in between itself
and the O
private boolean checkMoveint x int y int newX, int newY
Implement checkMove here
The error will go away once you implement and returns a boolean
value
return false;
getNewX and getNewY get the x and y coordinates of the position where the X
will occupy after the jump
private int getNewXint x int direction
int newX x;
switch direction
case RIGHT:
newX newX ;
break;
case LEFT:
newX newX ;
return newX;
private int getNewYint y int direction
int newY y;
switch direction
case UP:
newY newY ;
break;
case DOWN:
newY newY ;
return newY;
private void print
Implement print here
recursive and backtracking algorithm to compute all the possible moves
loops through the rows and columns of the matrix and tests if a jump in each
of the directions is a valid move
if it is a valid move it will perform the move and update the board and store
it into the array at the corresponding move count
base case occurs if the move count is equal to AND the centre position is
still filled with an X otherwise it calls the recursive method and moves
on to the next move
if the base case is not reached, than the backtracking method is called and
tries a new jump direction
public boolean findSolutionint move
Implement findSolution here
The error will go away once you implement and returns a boolean
value
return false;
considering this code, help me implement the peg solitaire so the solution can look like this:
X
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
