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
COSCOW: Data Structures II
Assignment
Duedate: Friday, January @:pm
Cutoff 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 Xs and Os to the corresponding positions after the jump happens
moveBackward: moves the Xs and Os 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
Submission Instructions:
Please note that the submitted work will be considered as your own work and you
confirm that you have not received any unauthorized assistance in preparing for or
doing this labassignmentexamination You confirm knowing that a mark of may
be assigned for entire work.
Submit your complete Java source files java Comment your program carefully so that it can
be read and understood. If your program is not properly commented you may lose marks. See
marking scheme for details.
Marking Scheme:
You will receive full credits for the working code, otherwise zero. No partial credits!
Comments in the program:
Complete program, no compilelogical error, and correct output:
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