![]() |
School of Engineering and
Applied
Science Department of Computer Science CSci 133 -- Algorithms and Data Structures I http://www.seas.gwu.edu/~csci133/spring06 Prof. Michael B. Feldman mfeldman@gwu.edu |
Project #1
Due Date: beginning of class, Thursday, Feb. 2, 2006
This project depends on Lewis/Loftus, especially Section 6.3
The purpose of this project is to refresh your memories of programming since you took CSci 53, and to give students who took different introductory courses a chance to get up to speed with Java. Start working on this now, so you have a chance to ask questions about anything you don't understand!
In this project you'll develop a program to do the data management for a very simple 1-person game derived from chess, called the knight's tour. You do not need to know how to play chess to do this project!
The game as we know it is played on a checkerboard with 8 rows, called ranks, and 8 columns, called files. The ranks are designated 1 through 8; the files are designated a through h. There are 6 types of pieces; each type of piece has its own rules for moving. A normal board, set up at the start of the game, looks like this:

Each kind of piece has its own rules for moving. For this project, we are interested only in the knight, whose moves are the most interesting.

You can see how this works, and play the game, by visiting http://www.borderschess.org/KnightTour.htm.
In this project we will represent the chessboard as a 2-dimensional
array of pieces, displaying it in a simple text format. The pieces are
denoted by e.g., BQ (Black Queen) and WN (White
Knight).
A normal game setup would look like
8 BR BN BB BQ BK BB BN BR
7 BP BP BP BP BP BP BP BP
6 .. .. .. .. .. .. .. ..
5 .. .. .. .. .. .. .. ..
4 .. .. .. .. .. .. .. ..
3 .. .. .. .. .. .. .. ..
2 WP WP WP WP WP WP WP WP
1 WR WN WB WQ WK WB WN WR
a b c d e f g h
A Knight's Tour setup might look like
8 .. .. .. .. .. .. .. ..
7 .. .. .. .. .. .. .. ..
6 .. .. .. .. .. .. .. ..
5 .. .. .. .. .. .. .. ..
4 .. .. .. .. .. .. .. ..
3 .. .. .. .. .. .. .. ..
2 .. .. .. .. .. .. .. ..
1 .. WN .. .. .. .. .. ..
a b c d e f g h
Your program will start the game with the knight at b1, then, repeatedly,
It's easier to follow the game if, instead just displaying a sequence of WN icons, we display the number of the move. Using this approach, suppose the knight moves from b1 to c3 (a valid move); the next board display will look like:
8 .. .. .. .. .. .. .. ..
7 .. .. .. .. .. .. .. ..
6 .. .. .. .. .. .. .. ..
5 .. .. .. .. .. .. .. ..
4 .. .. .. .. .. .. .. ..
3 .. .. 2 .. .. .. .. ..
2 .. .. .. .. .. .. .. ..
1 .. 1 .. .. .. .. .. ..
a b c d e f g h
If the next move is (say) to e2, the next display will be
8 .. .. .. .. .. .. .. ..
7 .. .. .. .. .. .. .. ..
6 .. .. .. .. .. .. .. ..
5 .. .. .. .. .. .. .. ..
4 .. .. .. .. .. .. .. ..
3 .. .. 2 .. .. .. .. ..
2 .. .. .. .. 3 .. .. ..
1 .. 1 .. .. .. .. .. ..
a b c d e f g h
and so on until the game terminates.
The Java application programs133/KnightTour.java is a skeletal one that reads one move and positions the knight, using the Screen class to put the board in the center of the screen. You can copy this file and use it as a starting point for your project. In your program, use the bottom few lines of the screen for data input and program messages.
Note that this skeletal program doesn't validate its inputs. As a reminder of how to read and validate the range of an input, you can study programs133/ShowInputLoop.java.
Grading:
Grading for this first project will be 0-20 points, as in CSci 53: Analysis/Design: 0-6, Test Plan: 0-4, Program Implementation 0-6, Code style and layout, 0-4.