Questions tagged [knights-tour]

A knight's tour is a sequence of moves of a knight on a chessboard.

223 questions
0
votes
1 answer

Knight's Tour code runs into infinite loop, does not reach a solution

My Recursive Backtracking approach to Knight's Tour runs into an infinite loop. At first, I thought the problem might be taking this much time in general but some solutions do it in an instant. Please tell what is wrong with my code. package…
0
votes
1 answer

Why does changing the order of array results in Time Limit Exceeded?

This is the classic "Knight Tour" Problem. I have used x_mov[] and y_mov[] to define the next co-ordinates the knight will take. The problem is, when I rearrange the arrays x_mov[] and y_mov[] (simultaneously), the program doesn't give an output and…
0
votes
1 answer

Knight's Tour - BackTracking in Java, Out of Bound

I am trying to solve the problem where the problem states that, given a N * M chessboard, a Knight’s Tour is defined as the sequence of moves of a Knight, such that the Knight visits every square only once. Below is my code, however I am getting…
0
votes
0 answers

Knight's tour recursion only fills up 60 squares

I have been working on this knight's tour recursion problem for days and still can't find a solution. Can someone help me identify the error? I've been searching for it for a long time and the maximum tiles it can fill up to is only 60. I have no…
BAW
  • 1
  • 1
0
votes
1 answer

Knight's Travail: Recursive Solution

The problem is to create a data structure, similar to a binary search tree that can list all possible moves a knight (in chess) can make on a 8x8 board. I came up with a single node class with the current location, a parent and 8 possible children…
0
votes
1 answer

Python Recursive Knight Tour

I'm trying to solve the knight tour algorithms with recursive backtracking method in python. The solution should be a matrix with 24 documented steps, but it only count up-to 5 steps. It doesn't enter the recursive if statement. JUMP_POS = [ (2,1), …
NetBlocker
  • 11
  • 5
0
votes
0 answers

Implementation of knight tour in c for knight at any random position on board

I am very new to the algorithm. I just came to know about backtracking algorithm and saw a video for knight tour problem on youtube. The video solve the problem with knight starting from initial position as (0,0). I tried to implement it for any…
Mukul
  • 310
  • 1
  • 6
  • 13
0
votes
1 answer

Knight's Tour C++ using stack

I am currently working on Knight tour Chessboard game in c++ using Stack to store my move. I encounter a weird loop that does not end the program. Can anybody help me with the code? #include #include #include #include…
0
votes
1 answer

Knight's Tour Brute Force

I'm lost with how the knight backtracks using recursion. I've tried multiple ways as you can see it's commented out some of the attempts, but how does it know how far to backtrack back to start moving forward again? My understanding of recursion is…
0
votes
1 answer

Knight's tour- backtracking (unable to solve for odd board sizes)

Below is the code I am using to test backtracking algo to solve knight's tour, and it's not able to solve for odd board sizes. I would really appreciate if someone could point out the error in the code. The code works fine for boards of even size,…
0
votes
1 answer

Prolog chess knight algorithm

I'm trying to resolve chess knight problem for custom matrix but I don't know where is problem. A chess knight must visit each place once, and when he manages to visit all fields then finish the program. Currently, he is looking for the correct…
Sekru
  • 515
  • 2
  • 11
0
votes
1 answer

Recursion in scala wont stop

I have a method which helps me to solve a knight's tour. I want my recursion to stop as soon as I have found a solution however It keeps going on and on. At the end it returns nearly 20 different solutions. I have added my code below, Can Someone…
Siyavash
  • 970
  • 9
  • 23
0
votes
0 answers

Knight's Tour with accessibility heuristic

Currently I'm just going through Deitels "Java, how to program early objects. 10th Edition". Exercise 7.22c) asks me to start using heuristic accessibility. d) Asks me to develop the app a tad further, and add a prediction to the next move in case…
0
votes
0 answers

Keeping track of the path, Knights travel

So far my shortest path method will stop when it reaches the goal position, printing out everything it did along the way. I would like to know how I could go about implementing parent positions so I can print the path along with the goal. This is an…
Jacob Moore
  • 277
  • 2
  • 12
0
votes
0 answers

How to pass STL parameter from the struct for the next step in BFS?

Hello this is the code "Chess knight problem" where knight has the start and end points - x,y on the chessboard. The first problem was to find the shortest path from the source to the destination point. I used bfs algorithm to solve it and it…