| Author |
Message |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/28/2006 22:10:34
|
lilgreenowl
Newbie
![[Avatar]](/images/avatar/eae27d77ca20db309e056e3d2dcd7d69.jpg)
Joined: 03/28/2006 21:50:14
Messages: 4
Offline
|
im in intro to java programming and we have this problem called the knight's tour, and i need help doing it. i have no idea where to start. Please i know there are some java wizzes out there, i need help writing this program. ill write out the problem below.
(knight's tour) One of the more interesting puzzlers for chess buffs is the knight's tour problem, originally proposed by the mathematician Euler. Can the chess piece called the knight move around an empty chessboard and touch each of the 64 squares once and only once?
The knight makes only L-shaped moves.
Now let us develop an application that will move the knight around a chessboard. The board is represented by an eight by eight two dimensional array board. Each square is initialized to zero. We describe each of the eight possible moves in terms of their horizontal and vertical components. For example, a move of type 0, consists of moving two squares horizontally to the right and one square vertically upward. A move of type 2 consists of moving one square horizontally to the left and two squares vertically upward. Horizontal moves to the left and vertical moves upward are indicated with negative numbers. The eight moves may be described by two one dimensional arrays, horizontal and vertical as follows:
horizontal[0]=2 vertical[0]=-1
horizontal[1]=1 vertical[1]=-2
horizontal[2]=-1 vertical[2]=-2
horizontal[3]=-2 vertical[3]=-1
horizontal[4]=-2 vertical[4]=1
horizontal[5]=-1 vertical[5]=2
horizontal[6]=1 vertical[6]=2
horizontal[7]=2 vertical[7]=1
Let the variables currentRow and currentColumn indicate the row and column respectively, of the knight's current position. To make a move of type moveNumber, where moveNumber is between 0 and 7, your application should use the statements
currentRow+=vertical[moveNumber];
currentColumn+=horizontal[moveNumber];
write an application to move the knight around the chessboard. keep a counter that varies from 1-64. Record the latest count in each sqare the knight moves to. Test each potential move to see if the knight has already visited that square. Test every potential move to ensure that the knight does not land off the chessboard. Run the application. How many moves did the knight make?
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/28/2006 22:33:52
|
tfecw
Newbie
Joined: 09/19/2005 15:02:20
Messages: 144
Location: No. VA.
Offline
|
ahh yes, the knights tour program been a while for that one. I liked the 8 queens problem better.
What have you tried so far? If you really need a starting point start by grabbing yourself a piece of paper and spend some time thinking about the problem. How would you solve this without using a programing language?
Once you have it on paper, start translating it into java.
Good luck and feel free to ask specific question and post the code you come up with. Don't forget to use the code tags
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/28/2006 23:16:39
|
lilgreenowl
Newbie
![[Avatar]](/images/avatar/eae27d77ca20db309e056e3d2dcd7d69.jpg)
Joined: 03/28/2006 21:50:14
Messages: 4
Offline
|
translating it into java is my problem. im really lowsy at programming with java, or atleast getting started. once im started i can usually finish. i understand the whole moving around the chessboard thing i just don't know how to put it to code. ill see what i come up with and post what i got. if you have anything to help me get started, that'd be great. maybe i can move from there. thanks for replying so quickly.
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/29/2006 07:52:16
|
tfecw
Newbie
Joined: 09/19/2005 15:02:20
Messages: 144
Location: No. VA.
Offline
|
Just take your problem and divide into manageable pieces.
Create your class, then create a method/methods to draw your chess board to a screen. Might even want to put the chess board drawing/managment methods in their own class.
Once you've got that going, then worry about actually making the Knight move around on the board.
Good luck.
|
|
|
 |
|
|