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 recursion

Is anyone able to find a mistake in my knight's tour code? I can't seem to find it, and I'm getting an infinite loop, not a stack overflow private bool heuristic(int[,] board, int x, int y, ref int jmp) { if (x < 0 || x > 7 || y < 0 || y > 7 ||…
Stefan
  • 700
  • 10
  • 22
0
votes
1 answer

Sort lists from shortest to longest

I've recently picked up prolog and am trying to make a program to find a solution for the famous puzzle Knight's Tour [found here] Using the Warnsdorff algorithm i'm trying to find all the possible moves that can be made from a specific spot on the…
vega2015
  • 119
  • 3
  • 11
0
votes
0 answers

KnightsTour solution, java.lang.StackOverflowError: null (in java.util.ArrayLists)

This is an assignment for one of my classes, I'm trying to create a program that will find a solution to the game "Knights Tour". Play it here: https://www.brainbashers.com/knight.asp I have my program run recursively until it finds a solution.…
Greg M
  • 398
  • 1
  • 9
0
votes
2 answers

Knight's Tour recursive algorithm

Okay everybody, I know the knight's tour problem is popular for all cs students and I am having trouble getting mine to work. I use this recursive algorithm to progress through the moves, however, once I get to around move 50 I have to backtrack…
mike
  • 3,339
  • 6
  • 30
  • 34
0
votes
1 answer

Knight's tour using Graph(DFS) Java

I'm trying to implement knight's tour using DFS. My board is 5x5 for simplicity. below is my code class StackK { private final int SIZE = 25; private int[] st; private int top; //…
Hello
  • 286
  • 3
  • 18
0
votes
2 answers

Knight's tour recursive approach Java

I'm trying to implement the knight's tour recursively.. below is my code. I chose the board to be 5x5 for simplicity. My goal is to print out the correct knight placements and possibly show backtracking at the same time with print statements. class…
Hello
  • 286
  • 3
  • 18
0
votes
1 answer

Knights tour backtracking Lisp

I am having some problems generating the correct output for this program. My output is almost correct, but missing of some steps. My code is as follows: (defun kt (x y m n) ;set the board (setq totalmoves (* m n)) ;find…
jtan
  • 13
  • 5
0
votes
1 answer

Weird result different from prediction (Knight's tour)

I'm coding the Knight's tour problem to find a tour for the knight in a n*n chessboard. I have made 2 answers, which I think are identical. However, when compiled, two codes produce 2 different results. I want to know the difference between two of…
0
votes
1 answer

Knight's Tour in Java (recursive), using Graph and DFS

I'm trying to calculate all possible knight moves on a 5x5 field: To do this, I'm trying to use a DFS (Depth First Search) class and a Graph class. I thought it might be too much code (and maybe not relevant enough) to paste these entire classes…
MJM
  • 141
  • 1
  • 2
  • 11
0
votes
2 answers

Calculate possible knight moves on a 5x5 field in Java, using DFS

I'm trying to calculate all possible knight moves on a 5x5 field. To do this, I'm trying to use DFS (Depth First Search) and a Graph class. The field would look something like this (using an id for each field): 0 1 2 3 4 5 6 7 8 9 10 11 12…
MJM
  • 141
  • 1
  • 2
  • 11
0
votes
1 answer

Finding move that is furthest from center of board - python 2

I have been working on the knight's tour simulation, and I have been stumped as to how to apply the Arnd Roth alteration to my python program. The snippet of the program here is the bulk of the calculations, and goes through the board, traveling to…
user3923303
0
votes
1 answer

Parallel Knight's Tour algorithm

Currently I have a knight's tour algorithm that is working. I uses a combination of: Backtracking Warnsdorf's Rule The algorithm does the following: Checks to see if the board is solved (all squares visited) If true: return true else…
Josafoot
  • 119
  • 1
  • 5
0
votes
1 answer

Knight tour all answers in c++

For knight tour problem, I came up with this answer; however, it just prints one answer. I don't know how to print all answers. I know I should change the output of find tour into void to avoid finishing but I don't know how. Can anyone modify…
mohammad amin
  • 47
  • 2
  • 8
0
votes
2 answers

Need of backtracking in Knight’s tour

Why we need backtracking for The Knight’s tour problem? Can we do it by using only recursion? i have tried to do it but it give wrong answer and i am not able to figure out where code or logic goes wrong. import java.util.*; public class Solution…
nikhil jain
  • 105
  • 9
0
votes
2 answers

Random function keeps on getting same result

I am writing a program to simulate Knight's tour randomly. (See wikipedia for what it means: http://en.wikipedia.org/wiki/Knight%27s_tour) First, I create a chess object, which is basically just a 8*8 array with numbers to indicate the position of…
Wt Tai
  • 3
  • 2