Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ons to the n-quccnsuale for Anis values of To be specific, test your program for = 4 and n = 8 (Knight's tour) This chapter

ons to the n-quccnsuale for Anis values of To be specific, test your program for = 4 and n = 8 (Knight's tour) This chapter described the backtracking algorithm and how to us cursion to implement it. Another well-known chessboard problem that can be solv using the backtracking algorithm is a knight's tour. Given an initial board position, determine a sequence of moves by a knight that will visit every square of the ches board exactly once. For example, for a 5 x 5 and 6 X 6 square board, the sequence of moves are shown in Figure 5-22 t that will Ple, for a n Figure 16 7 26 11 6 15 8 13 24 17 3309 18 3 12 Figure 5-22 Knight's tour A knight moves by jumping two positions either vertically or horizontally and one position in the perpendicular direction. Write a recursive backtracking program that takes as input an initial board position and determines a sequence of moves by a knight that visits each square of the board exactly once. We have earlier completed the Recursion chapter (chapter 5) of the textbook, including the topics of Recursion vs. Iteration and Recursion with Backtracking. This programming exercise (by popular vote in class) will be your choice of the Knight's Tour problem from chapter 5 (programming exercise 19 on page 363) or the Sudoku Puzzle application. Update: The class chose the Knights Tour, not the Sudoku Puzzle. Be sure your solution is a self contained, single file containing Java source code with it's own main method to run the compiled class. Name your file either Knights Tour.java or SudokuPuzzle.java (depending on the challenge you are attempting) and do not create any packages. Your solution must compile and run with the Java 8 Standard Edition JDK. Again: The class choose Knight's Tour, so name your solution accordingly. Knight's Tour: Don't follow the book's description exactly. I will simplify it somewhat here: Have your main method instantiate a traditional 8x8 chess board (don't request a size, just assume 8x8). Just use the upper-left as the starting position for the knight (don't allow the user to specify a different position). Just find and print the first solution (you don't have to find all solutions). However, if you somehow can't find a solution when starting from the first square, then proceed to try from successive starting positions moving left to right and then top to bottom on the chess board. Make sure you use a recursive solution with backtracking (don't produce an iterative solution or one that doesn't employ backtracking via the call stack). When you find your first solution, print out the board as in the illustration on page 363 (included with the programming exercise) in the textbook. Make sure the numbers are right-aligned in 8 rows and 8 columns so I can read it easily (that is part of the credit, too). I hope we all find the same first solution, so I would like you to check for the next move of the knight clockwise from the top (or starting from the one o'clock position, first). That way it will be quicker to verify the results, and every little bit helps. Sudoku Puzzle: (Don't do this problem as the class voted for the Knight's Tour, above) Look up the Wikipedia article on Sudoku puzzles at: https://en.wikipedia.org/wiki/Sudoku We will use the standard 9 x 9 board with hints read from standard input. Your program should output the first solution discovered using a recursive algorithm that employs backtracking. Note that depending on the number and value of the hints, there may be more than one solution or no solutions possible. Generally, Sudoku puzzles have hints that result in only one solution. For this reason, your program should read 81 values from standard input containing the hints (numbers in the input sequence between 1 and 9, inclusive) and empties (zeros in the input sequence). The input should fill the rows left-to-right then top-to-bottom. The values input should be taken from one of the many, easily available, Sudoku Puzzles (like the Wikipedia article) to be sure you will find a unique solution. Notice that you can place the hints as a sequence in a white space delimited plain text file and read it as standard input to your program by using the following command line when launching your Java program: java Sudoku

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Core Ios Developer S Cookbook Core Recipes For Programmers

Authors: Erica Sadun ,Rich Wardwell

5th Edition

0321948106, 978-0321948106

More Books

Students also viewed these Programming questions

Question

9.1 Define a budget. How is a budget different from a forecast?

Answered: 1 week ago