A knight's tour is a sequence of moves of a knight on a chessboard.
Questions tagged [knights-tour]
223 questions
1
vote
1 answer
Knight's tour Problem - storing the valid moves then iterating
I tried to code the knight's tour problem(8X8 board), but somehow I am not able to get it to work.
Instead of exploring all possible knight moves, I am storing it and iterating it one by one but
the program gets terminated before printing the…

Amit Kumar
- 93
- 1
- 2
- 6
1
vote
0 answers
finding path to all 3 corners on a chess board starting from 0,0 isn't working
#include
#define SIDE 8
#define VISITED 1
#define NOT_VISITED 0
#define FALSE 0
#define TRUE !FALSE
void printBoard(int board[][SIDE]);
int goHorsie(int board[][SIDE], int x, int y, int step);
int main(void)
{
int…

Hillskiller
- 33
- 6
1
vote
0 answers
Knight's Move Hidden test Case 4 Failing (Google Foobar test)
Hidden Test case 4
I am at task 2 of Google foobar test. The task is to find the smallest number of moves to reach at the destination node from the start node using Knight's move. Code is running fine and giving intended output. but there is a…

ALI AHMAD
- 33
- 3
1
vote
1 answer
Knight's tour using backtracking
I have been given some initialisation code and told to write a function knight(n,y,x) to print a solution to the problem.
This initialisation code is
size = 8
board = []
for y in range(size) :
board = board +…

pythonc0der
- 33
- 4
1
vote
1 answer
Knights tour in haskell getting a loop
I'm in the process of coding the knight's tour function, and I'm as far as this where I'm getting an infinte loop in my ghci:
type Field = (Int, Int)
nextPositions:: Int -> Field -> [Field]
nextPositions n (x,y) = filter onBoard
…

green tea
- 87
- 7
1
vote
1 answer
Why is this R version of Knight's Tour not working?
I'm new to R and I'm trying to find the least number of moves it takes for the knight to move around a chess board when it starts from the corner.
I used the Python algorithm from this…

Kyle Angelo Gonzales
- 812
- 1
- 4
- 18
1
vote
1 answer
Error: subscript out of bounds (knight's tour)
im new to R and im trying to solve for the minimum number of moves for a knight visit all the moves in a chess board.
I got the python code from:
https://www.geeksforgeeks.org/the-knights-tour-problem-backtracking-1/
and i tried to translate it to…

Kyle Angelo Gonzales
- 812
- 1
- 4
- 18
1
vote
1 answer
Python "The Knight's Tour" backtracking code not working
Having watched the Computerphile video on backtracking, I've decided to attempt to implement this algorithm for a different problem. My code seems to work up until depth ~48 when it starts to endlessly iterate through depth 46-53. It is not a…

Hubert Janczak
- 25
- 3
1
vote
1 answer
Hamiltonian path function returns empty path unexpectedly
The assignment I'm struggling with is based around a problem called the knight's tour and this Numberphile video: https://www.youtube.com/watch?v=G1m7goLCJDY
Basically, what I'm trying to do here is to write a helper function that recursively…

sweatspaghettios
- 23
- 4
1
vote
1 answer
Loop running infinitely C++ for Knight Tour Problem
I'm coding the Knight Tour problem in C++. But the is running indefinitely. I checked my logic and is similar to the logic mentioned here
#include
using namespace std;
bool isvalid(vector>board,int i,int j)
{
return i…

IshduttT
- 179
- 1
- 14
1
vote
0 answers
Implementing warndorffs rule for the first 32 moves of my knights tour, then using a stack and brute force backtracking
Ive changed the code, and even got a knights tour to work at starting at 0,0, but ever since the first time I've complied I havent gotten it to work, and im a little confused on how it possibly worked correctly the first time.
sample output:
0 61…

Jacob Fernandez
- 11
- 2
1
vote
1 answer
Pygame Becomes Unresponsive after running for a few seconds
I'm trying to write a GUI to display the Knights Tour backtracking algorithm. I have the algorithm working but when running the GUI, it becomes unresponsive after a few seconds.
import pygame
import time
# Init Gui
pygame.init()
# Window…

wvano97
- 82
- 6
1
vote
1 answer
How BFS gives Minimum steps to reach target by a Knight in Infinite chess board
There is a problem in which we should find out the minimum number of moves required by a Knight to reach its destination in an Infinite Chessboard. BFS solves this in finding that by making one move to one of its all 8 adjacent reachable vertices. I…

Mahideep
- 41
- 7
1
vote
2 answers
Knight's tour in Prolog: Stack limit exceeded
After I tried to optimize the program using Warnsdorff's rule, the compiler started issuing Stack limit exceeded. All parts separately seem to work, but I have no idea how this could be optimized. I am writing a program on an old laptop with 32-bit…

rancid_rot
- 45
- 5
1
vote
1 answer
Knight tour problem - order of moves affect performance
I was trying to implement a solution for knight tour problem. I faced an interesting issue. I would like to know the reason for the behavior.
This is the code - it works fine.
public class OpenKnightTour {
private int[][] chessTable;
…

KitKarson
- 5,211
- 10
- 51
- 73