The knight''s tour problem

Assignment Help C/C++ Programming
Reference no: EM13163984

The knight's tour problem is as follows: given an initial position for a single knight on an otherwise empty chessboard, find a sequence of 64 moves that will make the knight visit every square on the board exactly once. This seemly impossible task can be accomplished using Warnsdorff's rule: at any time, with the knight at a given position, there are at most eight positions on the board to which the knight could move. Some are off the board; others have been visited earlier in the tour. Choose the position that has the fewest open positions available to it. If this criterion yields a tie, use the same criterion on each of the positions available from the current one, i.e., use a second-level tie-breaker. If there's a tie at the second level, choose arbitrarily.

Write a program that will read in the starting position of the knight and produce a knight's tour beginning at that position. Is a knight's tour always possible, regardless of the starting position?

Hints:

Backtracking is an algorithmic paradigm that tries different solutions until finds a solution that "works". Problems which are typically solved using backtracking technique have following property in common. These problems can only be solved by trying every possible configuration and each configuration is tried only once. A Naive solution for these problems is to try all configurations and output a configuration that follows given problem constraints. Backtracking works in incremental way and is an optimization over the Naive solution where all possible configurations are generated and tried.

Naive Algorithm for Knight's tour?The Naive Algorithm is to generate all tours one by one and check if the generated tour satisfies the constraints.

while there are untried tours

{

   generate the next tour

   if this tour covers all squares

   {

      print this path;

   }

}

Backtracking works in an incremental way to attack problems. Typically, we start from an empty solution vector and one by one add items (Meaning of item varies from problem to problem. In context of Knight's tour problem, an item is a Knight's move). When we add an item, we check if adding the current item violates the problem constraint, if it does then we remove the item and try other alternatives. If none of the alternatives work out then we go to previous stage and remove the item added in the previous stage. If we reach the initial stage back then we say that no solution exists. If adding an item doesn't violate constraints then we recursively add items one by one. If the solution vector becomes complete then we print the solution.

Backtracking Algorithm for Knight's tour?Following is the Backtracking algorithm for Knight's tour problem.

If all squares are visited

    print the solution

Else

   a) Add one of the next moves to solution vector and recursively check if this move leads to a solution. (A Knight can make maximum eight moves. We choose one of the 8 moves in this step).

   b) If the move chosen in the above step doesn't lead to a solution then remove this move from the solution vector and try other alternative moves.

   c) If none of the alternatives work then return false (Returning false will remove the previously added item in recursion and if false is returned by the initial call of recursion then "no solution exists" )

Reference no: EM13163984

Questions Cloud

Calculate the de broglie wavelength : Calculate the de Broglie wavelength for each of the following.a 57 g ball with a velocity of 35. m/s b an electron with a velocity 12% the speed of light.
Emulates the behavior of a bus : Write a program that emulates the behavior of a bus. The bus must have a schedule ( a finite number of times for it to stop) and a certain capacity (number of passengers). In this program the bus has two states: stopped and going.
What objectives and political philosophies did he advocate : Who was Eugene V. Debs and what objectives and political philosophies did he advocate? What did he accomplish in 1912?
Method that receives an array and returns with no duplicate : Write a program that contrains a method that receives an array and returns a new array with no duplicates.
The knight''s tour problem : The knight's tour problem is as follows: given an initial position for a single knight on an otherwise empty chessboard, find a sequence of 64 moves that will make the knight visit every square on the board exactly once
Three dimensional array representing parking spaces : start with code in the file lab.cpp. This program works with a three dimensional array representing parking spaces in a parking garage on several floors. The code is incomplete. The functions "main", "display" and "showSpace" are complete. Your job i..
What factors contribute with the recent economic recession : Topic what factors contribute with the recent economic recession
Write the formulas for the compounds of these ions : although not a transition element, lead can form two cations: Pb2+ and Pb4+. write the formulas for the compounds of these ions with the chloride ion.
Give a polynomial time reduction : Give a polynomial time reduction from the 3-Color (coloring a graph so that no vertices adjacent to each other have the same color using 3 colors) problem to 3-CNF SAT.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a c program that asks for and reads in two integers

Write a C program that asks for and reads in two integers and then reports if one is a multiple of the other.

  The use of decision logic

The use of decision logic is one of the major concepts of computer programming.

  Write a loop that fills a vector

Write a loop that fills a vector V with ten  different  random numbers between 1 and 100. output must actually display the random numbers to get credit.

  Using opengl to create a cube

Write a program in C/C++ using OpenGL to create (without using built in function) a cube by implementing translation algorithm by translating along 1. X-axis, 2.Y-axis and 3. X and Y plane

  Method celsius return celsius equivalent of fahrenheit

Method Celsius return the Celsius equivalent of a Fahrenheit temperature,using the calculation Celsius = 5.0/9.0*(Fahrenheit -32); method Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature, using the calculation  Fahrenheit = 9.0/5..

  Write c program which has parent process and child process

Write a C program that has a parent process, a child process, and a grandchild process. The parent process should print its id and the square or 5.

  Write program to input series of hourly temperatures

Create and write a c++ program which inputs series of 24 hourly temperatures from file, and outputs bar chart (using stars) of temperatures for the day.

  Create class has three pieces of information as data members

Create a class called Date in C++ that includes three pieces of information as data members: month (type int), day (type int) and yaer (type int).

  Program to compute and show miles per gallon

Create the program in C++ which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and show miles per gallon.

  Find the pairs in any given matrix

write a c program which will find the pairs in any given matrix, whose sum of pairs are 10.

  Write a menu-driven program that maintains an address book

Write a menu-driven program that maintains an address book using a linked list. The address book must supports the following operations

  Insert the missing code in the c program

You are to insert the missing code in the C program given for combinational equivalence checking. This program will interface with the CUDD package and will parse netlist files in ISCAS85 circuit format. Next, BDDs will be created for each circuit an..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd