Questions tagged [knights-tour]

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

223 questions
1
vote
1 answer

Having difficulty in chess knights tour

I've tried writing a code for knight's tour problem using backtracking. My code is working for 4x4 matrix, but for 8x8 matrix it is not displaying anything on the output screen. I don't know what am I doing wrong. This is how my code works: If all…
1
vote
1 answer

StackOverflowError when running my "Knight's Tour" (it's pretty much finished otherwise)

I'm trying to make a program that goes through all squares of a chessboard (size doesn't really matter, but for now it's 6x6) with a knight, called a "Knight's Tour" check it out on wiki. The tour is supposed to be closed, which means the knight on…
XistenZ
  • 309
  • 1
  • 4
  • 14
1
vote
0 answers

Knight's Tour taking infinite time in Backtracking

My knight's tour code taking a long time to generate the output but it seems to be working fine until it reaches 61st step. What problem is making this code slower and inefficient? This code is working fine for 5*5,6*6 but it's getting slower when I…
suvojit_007
  • 1,690
  • 2
  • 17
  • 23
1
vote
1 answer

Function for Backtracking

I'm trying to create backtracking for for a singly linked list knight's tour problem. I have to implement a linked list as a stack and be able to pop the previous move and use that to back track/ try another move. I know the program works until I…
NikNik
  • 33
  • 4
1
vote
2 answers

Knights tour c++ recursive

im trying to do the knights tour in c++ with a recursive function but this program just exits without executing the function more than once. The main concept is just brute forcing the way with one function that finds a way by jumping to any open…
BlazS14
  • 13
  • 4
1
vote
1 answer

Why I run the same Python code on different computers has a huge difference in execution speed? (over 1000 times)

I have written a small game about knight's tour problem in Python. When I finished the algorithm part of the game, I found it run about 0.01 second to find a successful path of a 8*8 chess board. But when I run it on the computer of my office, it…
1
vote
2 answers

Modify Knight's Tour Algorithm to Print All Solutions

I recently pulled a C program (https://repl.it/Klpv) that searches for a knight's tour on an 8 by 8 board. I re-wrote the program in JavaScript (since I understand JS better), then I modified the program so that is can search for a solution on any…
1
vote
1 answer

Knight's tour- given n moves, in how many options can a knight move from (1,1) to (8,8) in n moves?

I've been trying to improve my recursion skills in C and I came across this question. I've tried to solve it, yet the code doesn't seem to work properly. For example, there are 108 options for the knight to move from (1,1) to (8,8) in 6 moves and in…
Cbeginner
  • 59
  • 1
  • 7
1
vote
1 answer

Solving Knights Tour using Warnsdorff's Rule

I'm currently trying to improve upon a brute force implementation of Knight's Tour by using Warnsdorff's Rule, however I feel as though I'm not understanding the algorithm, as the execution of the script is taking very long. I'm mainly looking for…
xxyyxx
  • 2,306
  • 3
  • 24
  • 34
1
vote
2 answers

Having trouble with Knights Tour in Ruby

I'm trying to the knights tour problem as an exercise in recursion since I have not used it in awhile, but my script does not seem to find a solution and only goes as high as 56 moves. Any tips to point me in the right direction would be…
xxyyxx
  • 2,306
  • 3
  • 24
  • 34
1
vote
0 answers

Warnsdorff’s algorithm for Knight’s tour

Please help me with this code. I don't know why is it not printing the output. The code is based on Warnsdorff’s algorithm for Knight’s tour problem. It says "[Error]:Id returned 1 exit status. When I executed it online it sait runtime error. Please…
goku
  • 156
  • 2
  • 8
1
vote
1 answer

Translating a tabled predicate from b-prolog to gprolog

For fun I've been attempting to write a Knight's Tour (https://en.wikipedia.org/wiki/Knight%27s_tour) solver in gprolog using Warnsdorf's rule. I found another SO post asking about efficiency that provided a solution in B-prolog: knight's tour…
Knight Artorias
  • 105
  • 1
  • 6
1
vote
1 answer

Knight's tour using recursion

Right now I'm at the point in the knight's tour where I just want the knight to be able to move until he can't move anymore and then just stop. The code works fine for the most part, but once and a while the code will print out two of the same…
Nick
  • 23
  • 4
1
vote
1 answer

Haskell: Knight tour never finish if I try more than 55 steps?

This is my code: maxX=8; maxY=8; maxSteps=60 -- If I change maxSteps=55 I get an answer move :: [(Int, Int)] -> [( Int, Int)] move list | lastX>maxX || lastY>maxY || lastX<=0 || lastY<=0 = [] | lastMove `elem` (init list) = [] | length…
Aminadav Glickshtein
  • 23,232
  • 12
  • 77
  • 117
1
vote
1 answer

Knight's tour using DFS Java

I'm trying to implement Knight's tour. I've been working on(more like planning) it for almost good 2~3hours now. and I still haven't made any progress. I seem to be unable to find the starting point.. below is the basic dfs method which I have to…
Hello
  • 286
  • 3
  • 18