Answered step by step
Verified Expert Solution
Question
1 Approved Answer
COSC 2 0 0 7 O 2 4 W: Data Structures II Assignment - 1 Due - date: Friday, January 1 9 , 2 0
COSC
O
W: Data Structures II
Assignment
Due
date: Friday, January
@
:
pm
Cut
off date: Sunday, January
@
:
pm
Objective:
The objective of this assignment is to implement and solve peg solitaire by using recursion and
backtracking algorithms.
Problem Specification:
The following game is actually a puzzle where the board has the form of a cross. It consists of
fields.
of these fields contain a peg. The single field in the middle of the board is empty. We
mark a peg with
X
and an empty field with
O
in the following examples.
X X X
X X X
X X X X X X X
X X X O X X X
X X X X X X X
X X X
X X X
The rules of this game are simple:
you can take a peg and jump over another neighboring peg
the peg you jumped over is removed from the board
you solved the puzzle if at the end only on peg exists and is located in the middle of the board
At the start there are only a few possible moves, but the choices are increasing during the game.
Implement a recursive backtracking algorithm in Java, that finds a solution to this puzzle. Please
download the PegSolitaireSample before start. Your program must include a class called
PegSolitaireBoard which includes the following methods:
findSolution: Recursive and backtracking algorithm to compute all the possible moves move
current number of move, first move must be
moveForward: Moves the
X
s and
O
s to the corresponding positions after the jump happens
moveBackward: moves the
X
s and
O
s back to their initial position before the jump occurred
COSC
: Assignment
checkMove: checks that the
X
performing the jump has one more
X
in between itself and
the
O
print: print the current state of the board
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started