Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

here's the code for part 1 import java.util.Scanner; public class Main { static int[] horizontalMovement = {2, 1, -1, -2, -2, -1, 1, 2}; static

image text in transcribedimage text in transcribed

here's the code for part 1

import java.util.Scanner;

public class Main { static int[] horizontalMovement = {2, 1, -1, -2, -2, -1, 1, 2}; static int[] verticalMovement = {-1, -2, -2, -1, 1, 2, 2, 1}; static int[][] chessBoard = new int[8][8]; static int knightMove; static int currentX; static int currentY; public static void main(String[] args) { //Scanner inputScanner = new Scanner(System.in); /* System.out.print("Enter starting row (0-7): "); currentX = inputScanner.nextInt(); System.out.print("Enter starting column (0-7): "); //allows user to select starting location currentY = inputScanner.nextInt(); inputScanner.close();*/ knightMove = 1; chessBoard[currentX][currentY] = knightMove; for (int i = 0; i = 0 && nextX = 0 && nextY Part 3 (6 points) In this part you will write a Java program that uses heuristics (or strategy) to try to get further in the Knight's Tour. Heuristics do not guarantee success, but a carefully developed heuristic greatly improves the chance of success. After completing Parts 1 and 2, you may have noticed that the outer squares are harder to land on than squares nearer the center. The four corners are the most inaccessible. So, let's try to move to the most inaccessible squares first, and leave easiest squares for when the board gets congested, near the end of the tour. We can develop an accessibility heuristic by classifying each square according to how accessible it is. Then at each move, we can move to an open square that is least accessible. We can represent the accessibility of each square using a 2-Dimensional array of integers called accessibility. Each square in this accessibility matrix corresponds to a square on the board. The number stored in accessibility [row] [column] is the number of open squares on the board from which board [ row] [column] can be reached. On a blank chessboard, each center square is rated as 8 , each corner square is rated as 2 , and the other squares have accessibility numbers of 3,4 , or 6 . The figure at the top of the next page summarized the initial values for the accessibility array. Figure 2 From ho oard is emply. Write a version of the Knight's Tour using the accessibility heuristic. The knight should always move to the square with the lowest accessibility number. In case of a tie, the knight may move to any of the tied squares. Therefore, the tour should begin in any of the four corners. As the knight moves around the chessboard, your program needs to reduce the accessibility numbers as more squares become occupied. In this way, at any given time during the tour, each available square's accessibility number will remain equal to precisely the number of squares from which that square may be reached. Sample Run for Part 3 In this sample run, the knight started at position (0,0) and the program was able to visit all 64 squares. The final square reached was (5,6). Part 4 (6 points) Modify your program from Part 3 so that it performs 64 different tours, one starting from each square of the chessboard. To display how many squares each tour was able to reach, we will use yet another 88 array of integers called results. The number stored at results [row] [column] is the number of squares that were visited when performing a tour starting at board [row] [column]. Sample Run for Part 4 All tours except one completed a full Knight's Tour. The tour starting at (3,2) was only able to visit 60 squares

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Be able to explain the concept of constructive discharge

Answered: 1 week ago