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");

}

}

}

[5382 byte] By [da3shota] at [2007-11-26 15:47:44]
# 1
Looks to me as if you'd need to construct a KnightTour object, and then call the "move" method on that object.
doremifasollatidoa at 2007-7-8 22:07:10 > top of Java-index,Java Essentials,Java Programming...
# 2

i have another question, how would i display a grid showing all the steps the knight took until the program ended? something like this

12345678

110 2100 14 23 12

2 20069 22 1100

372 19 36 15 46 13 24

4058 47 10 370 45

50 183 16 35 44 25 38

64 31 340 42 39 280

700 17 32 29 26 43 40

80 33 3000 410 27

47 squares were visited

da3shota at 2007-7-8 22:07:10 > top of Java-index,Java Essentials,Java Programming...
# 3
bump
da3shota at 2007-7-8 22:07:10 > top of Java-index,Java Essentials,Java Programming...
# 4
bump
da3shota at 2007-7-8 22:07:10 > top of Java-index,Java Essentials,Java Programming...
# 5
1) Do you realize not even waiting a couple of hours before bumping it will piss people off ?2) never heard of knights tour - perhaps you can give the description of the assignment problem so I have a better idea of it.3) When is it due ?
Aknibbsa at 2007-7-8 22:07:10 > top of Java-index,Java Essentials,Java Programming...
# 6
> 1) Do you realize not even waiting a couple of hours> before bumping it will piss people off ?u do realize i waited half a day, right?> 3) When is it due ?it was due today, so u dont have to reply now. or u could reply just for my knowledge
da3shota at 2007-7-8 22:07:10 > top of Java-index,Java Essentials,Java Programming...
# 7
> bumpNo wonder you have to cheat if you keep bumping your head and lose a few 100 brain cells each time.
floundera at 2007-7-8 22:07:10 > top of Java-index,Java Essentials,Java Programming...