Knight's Tour Problem 2

This is a discussion on Knight's Tour Problem 2 within the C Programming forums, part of the General Programming Boards category; Hi,
THis time i only have one question to get clear of so far. Now my book tells me to ...

Knight's Tour Problem 2

Hi,

THis time i only have one question to get clear of so far. Now my book tells me to develop a strategy to move the knight. Each square on the board is labelled with accessibility numbers which tells how hard are they accessed. They are as follows on a 8x8 chess board:

Here is the bit i don't understand:
---------------------------------------------------------------------------------
'Now write a version of the Knight's Tour program using the accessibility heuristic. At any time, the knight should move to the square with the lowest accessibiloity number. In case of a tie, the knight may move to any of the tied squares. Therefore, the tour may begin in any of the four corners. (Note: As the knight moves around the chess board, your program should reduce the acessibility numbers as more and more squares become occupied. In this way, at any give time during the tour, each available square's accessbility number will remain equal to precisely the number of squares from which that square may be reached.) '
----------------------------------------------------------------------------------

WHat IS a tie?

How do i reduce the accessibility numbers ? Each time the knight moves reduce one from all squares? This can't make sense.

Let's say your knight starts in the top left corner, which I refer to as (0,0).

From that place, we have two places to which we can move, either (1, 2), or (2, 1). The accessability of each of these cells is 6, so we have a tie. According to the rules of the problem, we may choose either of the squares. Let's say that we choose (1, 2)

Also, since we've visited cell (0,0), it is no longer accessable, therefore that's one less cell that (1, 2) has access to, and one less cell that (2, 1) has access to. Therefore, when we mark cell (0, 0) as unaccesable, we also have to reduce the accessability of (1, 2) and (2, 1) to 5. It doesn't matter if we do this before or after choosing which cell to jump to.

Now we have another tie. So, according to the rules, we may choose either (0, 4), or (2, 0). Also, since cell (1, 2) has been visited, all the cells which have access to (1, 2) will have their accesability reduced by one (clearly, these are the same points as those which we could access from (1, 2)).

And I take it that we just repeat this untill we've nowhere else to move.

To determine which cell has the lowest accessibility, do i have to use some sort of sorting algorithm such as bubble sort ?

and for each move i have to calculate how many squares are accessible from that square, do that for every move, will it slow down the program a little bit ? Like because i have to use a for loop of a while loop ?

That's what i have so far. It doesn't work, it only display 2 moves, but it does choose the lowest accessibility number to go to for that two moves. I would like to know why it won't go further as it should. What's wrong with the code and where ?

I'm sorry, but the problem with that code is not a couple bugs, the code itself is incorrect enough that I'm not sure it can be 'fixed'.

You need to work with 3 seperate steps...

Step one: choose the X and Y such that they have the lowest accessability from the current square.
Step two: mark the current square as visited.
Step three: decrease the accessability of all the squares which can access the current square by one.

For step one, you don't need to sort. You should be using a for loop that has the following code...

This little snippet of code will compare the accessability of square tempX, tempY with that of move2MeX, move2MeY, and if the accessability of temp is less than that of move2Me, then it will replace move2Me with temp. By doing this for every square you want to compare, in the end, move2Me be the square with the lowest accessability.

For step two, I suggest that you only use one array to represent the board, use your access array. If a square has been visited, then mark the square as having an access of 0 or -1.

Here is the code that I wrote which
shows the problem with the code that you
wrote. Your method won't work as the knight
will get stuck after a certain number of moves.
This one will run until it gets stuck after 59
moves.