KNIGHTS TOUR

I have had to summit the question again
because i cannot edit the question i set earlier cookies problem

but here it is again a bit clearer to understand i hope

Knights tour problem
I need the design for a 2d array for where the user inputs the starting position for the knight
The program then displays all the subsequent moves in rows of eight
the user inputs any postion
say 2b the program then has to display
all the 64 positions the knight will travel
from to complete its tour of the board
the result will be displayed in rows and
columns of eight
{user inputs 1a}
 
output

1a 3b 2d 1f 3g 2e ect

the program does not have to be a 2d array
but as i am just starting to learn what
2d arrays do i thought this would be a better way of doing it
instead of using a load of if and else statements

cheers
gandalph
gandalphAsked:
Who is Participating?
 
scrapdogConnect With a Mentor Commented:
I am assuming you want to find the smallest amount of moves the knight can make to visit every square on the board?

If this is the case, you can use a 2-d array to store booleans indicating whether or not the square has been visited.

For each square, there is a number of legal moves a knight can make.  Using recursion, find out which move will result in the least number of moves in the long run.  When a knight moves to a square that hasn't been visited, mark it as true, and decrement a counter (initialized as 64).  When the counter reaches zero, you have found a path.  Try all possible combinations, and the one that takes the least number of moves would be the best solution.
0
 
dbruntonCommented:
You need to have one of your questions deleted.

Contact the help desk and specify the question number that you want deleted.

I hope that you are not asking for the algorithm to solve the problem.  The other question has a comment that gives an idea of the array to hold what you want.  Also especially read scrapdog's comment above.

Have fun.
0
 
gandalphAuthor Commented:
i have tried the 2d array but i am having loads of probs i need to set up the array so that that it shows on the user screen columns a to h & rows 1 to 8 with the rest showing zero like this
  a b c d e f g h
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0

and so on

i do not know how to set the array up so that it will show this table

also when the user inputs from any starting point say b1 the screen will then display 'x' in the table at b1

i can get a table displayed but it only shows 8 rows and 8 columns of zeros

and when user inputs say b1 the table just shows the value 1 at h8

i need some serious help with this one
any offers

gandalph
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
john_pradeepCommented:
Hi! Gandalph,
i am stuck with the same problem...i was wondering if you could help in anyway.
0
 
gandalphAuthor Commented:
yeh hi john
sorry a bit late in answering been away
send me your email address
and i will send you some code
0
 
gandalphAuthor Commented:
yeh hi john
sorry a bit late in answering been away
send me your email address
and i will send you some code
0
 
gandalphAuthor Commented:
yeh hi john
sorry a bit late in answering been away
send me your email address
and i will send you some code
0
 
john_pradeepCommented:
Hi ! Gandalph ,

My email id is kolijoe@hotmail.com.
thanks
0
 
john_pradeepCommented:
Hi!

I was basically looking for a solution in c++.

thanks.
0
All Courses

From novice to tech pro — start learning today.