Re: knight's tour problem
Are you just trying to move through the board once and only once? Then want a list of the moves it performed to get there?
I might suggest a stack for this, but based on the current setup, you'll need an array that can hold your 64 locations and an array keeping track of the last move made from each location.
This is a brute-force method, but would work like this:
Start somewhere, mark it visited. start your list with that place
count = 0
while not done:
If N-N-E available and not visited and not N-N-E from here before (separate array/list)
mark moved[HERE] = N-N-E
move N-N-E
mark new current visited, add to list of moves
count ++
Else If N-N-W available .....
...
Else if S-S-W (OR LAST IN CHOICE OF MOVES) not available
count --
BACK UP
...
if count == 63 done = true!
Re: knight's tour problem
I tried a similar way by performing the eight possible moves and checking whether the location is available or not if available I mark it as not available and try another location
if not i stay at the same place and try different move. but my problem is to make the knight make a decision to move toward the square that has the lowest accessibility(has the least number of squares around it that can be reached only from it). I don't know how to do this for sorry.
Re: knight's tour problem
Quote:
Originally Posted by
Kareem Mesbah
I tried a similar way by performing the eight possible moves and checking whether the location is available or not if available I mark it as not available and try another location
if not i stay at the same place and try different move. but my problem is to make the knight make a decision to move toward the square that has the lowest accessibility(has the least number of squares around it that can be reached only from it). I don't know how to do this for sorry.
That's the 'Warnsdorff's rule' for a night tour; it solves the entire tour in linear time and you never have to back track.
kind regards,
Jos
Re: knight's tour problem
Quote:
Originally Posted by
JosAH
That's the 'Warnsdorff's rule' for a night tour; it solves the entire tour in linear time and you never have to back track.
kind regards,
Jos
thank you very much :)