knights tour
ok, i think people are familiar with the knights tour game. anyways, i have this code(got it from someone else) but it doesnt have a main method. all i need is a main method and this baby is gonna work. i was wondering if you could help me in making this. which method do i call?
import java.util.Random;
publicclass KnightTour
{
/** Creates a new instance of chessBoard */
//This creates an
privateint board[][];
staticprivateint vertical[] ={-1, -2, -2, -1, 1, 2, 2, 1};
staticprivateint horizontal[] ={2, 1, -1, -2, -2, -1, 1, 2};
privateint currentRow;
privateint currentColumn;
private Random randomNumbers;
privateint moveNumber = 0;
privateint count = 1;
//The constructor will initialize the board to all 0's
//and set the initial position of the knight.
public KnightTour()
{
board =newint[8][8];
randomNumbers =new Random();
for (int row = 0; row < board.length; row++)
{
for(int column = 0; column < board[row].length; column++)
board[row][column] = 0;
}
currentRow = randomNumbers.nextInt(7);
currentColumn = randomNumbers.nextInt(7);
board[currentRow][currentColumn] = count;
}
publicvoid move()
{
count++;
int tempRow;
int tempColumn;
tempRow = currentRow;
tempColumn = currentColumn;
boolean tourNotDone =true;
moveNumber = randomNumbers.nextInt(7);
tempRow += vertical[moveNumber];
tempColumn += horizontal[moveNumber];
//before it actually sets count to the value
//we need to check for valid move...
//if either currentRow or currentColumn have
//a value less than 0 this means that we are
//out of bounds on the array...another move must
//then be made
while ((tempRow < 0)||(tempColumn <0)||
(board[tempRow][tempColumn] != 0))
{
int loopcounter = 0;
if(loopcounter == 20 )
{
System.out.println("The kights tour ended on move:" + count);
tourNotDone =false;
break;
}
moveNumber = randomNumbers.nextInt(7);
tempRow += vertical[moveNumber];
tempColumn += horizontal[moveNumber];
loopcounter++;
}
//check to see if a move to that spot has
//already been made
//one problem here This may result in an infinite loop
//because there will be a time when the tour ends
//when it will be impossible to find a spot that
//has a 0 value.
//The move is actually made
//what if the tour ended
if (tourNotDone)
{
currentRow = tempRow;
currentColumn = tempColumn;
board[currentRow][currentColumn] = count;
}
else
{
System.out.println("I hope you had a good time");
}
}
}

