Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

As part of this Lab Test, you will create a Console Application using the C# programming language that simulates the classic Knights Tour problem. Your

As part of this Lab Test, you will create a Console Application using the C# programming language that simulates the classic Knights Tour problem. Your application must move a Knight around an 88 Chess board until no valid moves for it remain. Furthermore, your application must be able to repeat the Knights Tour 200,000 times (Hint: use a for-loop!). The Chess board is represented by an 88 rectangular array board. Each square is initialized to zero. From a square in the center, the Knight can only make L-shaped moves, as shown in the figure below.Each of the eight possible moves are described in terms of their horizontal and vertical components. For example, a move of type 2 involves moving one square horizontally to the left and two squares vertically upward. These eight move types can be described using two one-dimensional arrays horizontal and vertical, as shown below. static int[] horizontal = { 2, 1, -1, -2, -2, -1, 1,2 }; static int[] vertical = { -1, -2, -2, -1, 1, 2, 2, 1 }; If variables currentRow and currentColumn indicate the row and column of the knights current position, respectively, one can make a move of type moveNumber, where moveNumber is between 0 and 7, using the following statements: currentRow = currentRow + vertical[moveType]; currentColumn = currentColumn + horizontal[moveType];Your application must record the Knights move number in the board array. The value of each element of the board array must represent the move number made by the Knight when that square was visited. The Knight must be moved at each iteration by choosing the move type at random using the built-in Random class. If the randomly chosen move is not legal, your application must increment the move type using moveType = (moveType + 1) % 8;The Knights Tour may have between 1 and 64 moves. Your application must repeat the Tur 200,000 times and record the number of moves made in each Tour. You may do this by defining an integer array of length 65 named moveTotals. Each element of the moveTotals array can store the number of simulations that ended with the same elements index. For example, moveTotals[32] stores the number of Tours that ended with exactly 32 moves.

Once the 200,000 simulations are complete, your application must write a histogram (i.e., frequency distribution diagram) of the results to a text file, exactly the same as the following (Hint: see Slide 12 of Lecture Notes 3 for an example!). Here, the number of stars on each row is proportional to the number of times the Tour ended with the same number of moves. The percentage values represent the frequency divided by 200,000.

In addition to the instructions described above, your app must meet the following requirements for full credit:

  1. Your submission must be a zipped folder and must contain the entire project directory from your Microsoft Visual Studio project. Otherwise, you may not receive any credit for the test.

  1. Your C# console application must compile and execute correctly without error in Microsoft Visual Studio.

  1. Your C# console application must use a class named KnightTour to house all the required methods and instance variables.

  1. The KnightTour class must define the following instance variables, nothing more, nothing less:

static Random randomNumbers = new Random(); static int[,] board; static int[] horizontal = {2, 1, -1, -2, -2, -1, 1, 2}; static int[] vertical = {-1, -2, -2, -1, 1, 2, 2, 1}; // to store the number of tours for each move number: static int[] moveTotals = new int[65];

  1. The KnightTour class must also define the following methods in addition to the main() method:

// checks for legality of move

public static bool CheckMove(int row, int column);// write the simulation statistics to a text file whose name is stored in "str" public static void WriteResults(string str);

Method CheckMove() must be implemented as an expression-bodied method

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

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

7. Senior management supports the career system.

Answered: 1 week ago