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

Code knight's tour using backtracking is not showing any output

This code is not giving any output. It should output a matrix of 8X8 size. #include #define N 8 using namespace std; This function prints the matrix: void print(int arr[][N]){ int i, j; for (i = 0; i < N; i++){ for (j =…
1
vote
0 answers

Knight's Tour Printing Out List of Moves (Recursion)

#include "knight.h" #include bool voyagingKnight(Grid& visited, int x, int y, int m); using namespace std; int main() { Grid visited; int m =0; int x = 5; int y = 5; voyagingKnight(visited, x, y, m); return…
Jacob Culp
  • 27
  • 3
1
vote
2 answers

Knight's tour in java (recursive)

I am writing the code for a classic Knight's tour, my code seems to be mostly doing the right thing but it still gives me "not possible" for possible boards and i can't figure out why. (ex: it fails for for a table with 3 rows, 4 columns, starting…
Chalupa
  • 367
  • 1
  • 5
  • 20
1
vote
1 answer

knights tour using a stack

I'm tasked with solving the Knights tour iteratively using a stack to store the previous moves so I can pop if the knight is stuck. My program seems to be making multiple POPS but doesn't seem to be ever solving the puzzle. It uses Warnsdorffs rule…
Cody Krauskopf
  • 330
  • 1
  • 4
  • 13
1
vote
2 answers

Knights Tour Java

I am receiving a StackOverflow error when ever I run the program instead of finding the Knights Tour. Any idea what is causing this and how I can change my code around to actually find the Knights Tour and get rid of this error. Project is for my…
1
vote
1 answer

Knight's Tour Depth First Search Backtracking

I'm working on a knight's tour implementation using DFS. My problem is, when I run it, it works fine up to step 20, but after that the algorithm freaks out and outputs this on a 5x5 board (there is a solution for a 5x5 board starting at (0,0)): (1 …
user1846359
  • 233
  • 3
  • 12
1
vote
0 answers

Knights Tour Implementation & End Conditions

I'm trying to implement Knight's Tour using DFS in Racket. My current implementation involves generating a list of legal moves (not off board and not in list of previous steps) possible from the current position and throwing it into a stack. Then…
1
vote
2 answers

Knight's tour backtrack implementation choosing the step array

So I came up with this implementation for solving knights tour for a 8*8 chess board. But seems like it is taking a long time running (so long that I have to stop it). But if I replace the dx, dy arrays with the one written in comments and the…
Jignesh
  • 555
  • 1
  • 8
  • 18
1
vote
2 answers

Knights tour backtracking Java

I am trying to solve the Knights tour problem on a 4x4 board with backtracking and recursion in java, and on the output I get this step sequence: 1  13   16  15 10  7   4   14 5    2   11   8 12  9   6   3 in the right upper corner, the…
user2208931
1
vote
4 answers

How do I move a game piece(control) during runtime?

I am doing a simple C# program of the game Knights Tour in C# the hard way to learn all I can of C#. I have a board and a knight piece and the knight is a custom panel with the picture of the knight. What I am attempting to do is allow the user to…
texasman1979
  • 473
  • 1
  • 6
  • 17
1
vote
1 answer

Knight's tour with Warnsdorff's Rule: Determine all solutions

I implemented a recursive solution for the Knight's tour using Haskell. My algorithm is basically based on Warnsdorff's Rule. Example: Size of chessboard: 5x5 Starting position: (3,3) The basic idea based on this example: (1) Calculate allowed…
Patrick
  • 3,091
  • 4
  • 26
  • 29
1
vote
1 answer

Knights tour recursive

I'm trying to write knights tour recursive algorithm: int mov[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}}; typedef struct element { int x; int y; struct element *prev, *next; } node; //adding pool to list void…
whd
  • 1,819
  • 1
  • 21
  • 52
1
vote
2 answers

knight's tour : not able to resolve

I wrote this code to print one of the possible knight's tour such that every place is visited exactly once. public class Main{ static int move[][]=new int[8][8]; static int X[]={1 , 2 , 2 , 1 ,-1 ,-2 ,-2,-1}; static int…
Saurav Kumar Singh
  • 1,352
  • 7
  • 18
0
votes
3 answers

Knight Tour C++

I am trying to solve Knight Tour Problem using recursive Backtracking. Can someone help me optimize my code. My code works till 6X6 board. . After N=7 it takes almost infinite time to solve . Here is my code : #include #include…
Ganesh
  • 57
  • 8
0
votes
0 answers

Improvement in time complexity required

https://www.hackerrank.com/challenges/knightl-on-chessboard/problem This is the problem that I have been trying to solve using simple loops and recursive approach and trying to keep my code simple void of any boolean or queues etc. My code is…