A knight's tour is a sequence of moves of a knight on a chessboard.
Questions tagged [knights-tour]
223 questions
3
votes
1 answer
Finding one solution to Knight's Tour in Haskell
I'm trying to solve Knight's Open Tour in Haskell,and come up with a solution to generate all possible solutions:
knightsTour :: Int -> [[(Int, Int)]]
knightsTour size = go 1 [(1, 1)]
where
maxSteps = size^2
isValid (x, y) = x >= 1 && x <=…

Allen Wang
- 107
- 1
- 9
3
votes
3 answers
optimise knight-tour LISP
I am new to LISP and I encounter this problem with the below code.
(defun knights-tour-brute (x y m n)
(setq height m)
(setq width n)
(setq totalmoves (* height width))
(setq steps 1)
(setq visited-list (list (list x…

Hero1134
- 189
- 9
3
votes
1 answer
Implementing the Knight's Tour on a 8x8 chess board using backtracking
Here is my code in python, the call to knightsTour(0,0,1,sol,xMove,yMove) should return True but I am getting False. I was not able to hunt the bug down.
def safe(x,y,sol):
return x >= 0 and x < 8 and y >= 0 and y < 8 and sol[x][y] == -1
def…

Anuj Mittal
- 83
- 1
- 9
3
votes
2 answers
How can I correctly return produced sequences in an F# recursive algorithm
As a tutoring exercise I implemented the Knights Tour algorithm in CS and worked fine, after trying to port it to F# I cannot go past the part where I aggregate the resulting sequences of the Knight's path to return to the caller.
The code is…

Jonathan Nazario
- 133
- 3
- 13
3
votes
1 answer
Knights Tour Algorithm
I'm trying to write a Knights Tour Algorithm which has two arrays, ACCESS and board. ACCESS is the array I use to figure out what the next move is and board is the array that the user will see as the end result. My algorithm checks to find the…

Sygnerical
- 231
- 1
- 3
- 12
3
votes
2 answers
Can someone help me with this knight's tour code?
The code seems fine to me, but the output is too short and the answer is no when it should be yes (starting at a,0, the knight should be able to tour the entire board)
By the way, the reason my positionsVisted array is [9][9] is because I wanted the…

ido flax
- 528
- 1
- 10
- 19
3
votes
2 answers
Solving knight tour with c++
I wanted to solve knights tour puzzle. When I searched it I come to know that there are many ways of solving it. In fact very efficient and fast algorithms for solving it including Warnsdoff's rule. But actually I never wanted to copy any of them.…

Ali Raza
- 191
- 2
- 12
2
votes
1 answer
Knight's tour depth-first search infinite loop
I'm trying to solve the knight's tour problem using a depth-first search algorithm. The algorithm seems te be looping whenever it has two choices that both result in a dead end. I understand that this is caused because the algorithm resets the…

Bart
- 769
- 2
- 13
- 29
2
votes
1 answer
knights tour code with recursion and backtracking
I was recently assigned the knight's tour problem.
Here is my try at it:
#include
#include
#include
int count = 1;
int movej[8] = {1, -1,-2, 2, -2, -1, 1, 2};
int movei[8] = {2, 2, 1, 1, -1, -2, -2, -1};
void…

Chemical Brewster
- 43
- 5
2
votes
3 answers
Find path to all 3 corners on a chessboard as a knight
#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 cor1, int cor2, int cor3);
int…

Hillskiller
- 33
- 6
2
votes
2 answers
Knights Tour with Backtracking
I'm trying to write a Python program which will solve the Knight's Tour problem using backtracking. For those unfamiliar: "The knight is placed on the first square of an empty chess board and, moving according to the rules of chess, must visit each…

Lou
- 103
- 10
2
votes
1 answer
open knight's tour (backtracking) algorithm in smlnj
I have to write SML code to solve knight's tour problem in backtracking. The chess knight must run all over the chessboard (size: NxN) and must visit each square exactly once (no need to come back in first square at the end).
I already write all the…

Arie
- 23
- 5
2
votes
2 answers
Knight tour on Infinite Grid with blocking cell
Recently in an interview, I was asked this question:
You are given two cells on a chess board, one is starting cell and another
one is destination cell. You will get a list of cells also, which
represents blocked cells, that means you can't…

Ahmad Faiyaz
- 316
- 4
- 16
2
votes
2 answers
Call a rule in Prolog
I'm trying to solve Knight Tour problem.
I want to call a rule to evaluate possible movements, but I can't do that my rule returns the next position in the variable that I send.
move(X,Y):-
X is X+1,
Y is Y-2.
move(X,Y):-
X…

Joseph
- 97
- 3
- 9
2
votes
1 answer
Gprolog Knight's Tour using Warnsdorff's Rule
I'm trying to implement Warnsdorff's Rule in Gprolog to generate tours on an arbitrary chessboard. I found an SO post providing a good solution in B-prolog, and I simply needed to translate the Warnsdorff step (knight's tour efficient…

pepperguy3
- 51
- 2
- 8