I'm doing the "Knights Tour" exercise. It's where I have one knight piece on a chessboard. I'm supposed to see how far it can get when it's allowed to only touch a square once. I'm using rand() to generate the moves and I run the tour 1000 times. My problem is when I run it through the loop it seems to go through the exact same moves every single tour. What gives?

Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int checkMovability( int[][ 8 ], int, int ); void printBoard( int[][ 8 ] ); int main() { int currentRow = rand() % 8, currentColumn = rand() % 8, moveNumber, counter = 1; int vertical[ 8 ] = { -1, -2, -2, -1, 1, 2, 2, 1 }, horizontal[ 8 ] = { 2, 1, -1, -2, -2, -1, 1, 2 }; int board[ 8 ][ 8 ] = { 0 }; int tourLength[ 65 ] = { 0 }; int tour, i; srand( time(NULL) ); for (tour = 1; tour <= 1000; ++tour) { while ( checkMovability( board, currentRow, currentColumn ) == 1 && counter <= 64 ) { moveNumber = rand() % 8; if ( board[ currentRow + vertical[ moveNumber ] ][ currentColumn + horizontal[ moveNumber ] ] == 0 ) { // printf("inner if 1\n"); if ( ( currentRow + vertical[ moveNumber ] ) <= 7 && ( currentRow + vertical[ moveNumber ] ) >= 0 ) { // printf("inner if 2\n"); if ( (currentColumn + horizontal[ moveNumber ]) <= 7 && ( currentColumn + horizontal[ moveNumber ] ) >= 0 ) { currentRow += vertical[ moveNumber ]; currentColumn += horizontal[ moveNumber ]; board[ currentRow ][ currentColumn ] = counter; ++counter; // printBoard( board ); // printf("Knight at %d %d\n", currentRow, currentColumn); } } } } // printBoard( board ); // printf("No more moves can be made\n"); ++tourLength[ counter - 1]; } for (i = 0; i <= 64; ++i) { printf("%d: %d\n", i, tourLength[ i ] ); } return 0; } int checkMovability( int grid[][ 8 ], int row, int column ) { int h[ 8 ] = { 2, 1, -1, -2, -2, -1, 1, 2 }; int v[ 8 ] = { -1, -2, -2, -1, 1, 2, 2, 1 }; int move; for (move = 0; move <= 7; ++move) { if ( grid[ row + v[ move ] ][ column + h[ move ] ] == 0 ) { if ( ( row + v[ move ] ) <= 7 && ( row + v[ move ] ) >= 0 ) { if ( (column + h[ move ]) <= 7 && ( column + h[ move ] ) >= 0 ) { // printf("checkMovability returned 1\n"); // printf("checkMovability says you can move v: %d h: %d\n", v[ move ], h[ move ] ); // printBoard( grid ); return 1; } } } } return 0; } void printBoard( int grid[][ 8 ] ) { int i, j; printf("\n\n"); for (i = 0; i <= 7; i++) { for (j = 0; j <= 7; j++) { printf("%4d", grid[ i ][ j ] ); if ( (j + 1) % 8 == 0 ) printf("\n\n"); } } return; }