import Piece; /** * A class Board to store, delete and move pieces on it. * * @February 2000 * @author Ming Gu, Yasir Mehboob, Mustally Hussain, Shiva Kabra, * Ammar Bandukwala. */ public class Board { // +--------+----------------------------------------------- // | Fields | // +--------+ /** * protected [a vector or array of pieces] pieces; * In this field each piece is put into its own position * according to its row number and column number. For * example: a Piece(a, b) on a n*n board should be the * (a*n+b-1)th piece in the vector or array. */ // +--------------+----------------------------------------- // | Constructors | // +--------------+ public Board(int rownumber, int columnnumber){ /** * Build a board, with given row number and column * number.The two parameters decide how big the field * array or vector should be. Be sure that rownumber * and columnnumber are positive integers, or an * exception may be thrown. The method will use the two * parameters' product as the size of the Board's * field. After calling this method, the received * Board's vector or array should be empty at first. * A constructor for null piece might be needed in Piece * class. */ } // +------------+------------------------------------------- // | Extractors | // +------------+ public Piece lookupPiece(int rownumber, int columnnumber){ /** * Look up the board and get the piece according to the * parameters' row and column number. The two numbers * of the parameters should exist on the board. If * there is not a piece at this position, a null piece * will be received or an error will be thrown out. * After this method is called, there shouldn't be any * changes made to the board. Only a copy of the * corresponding piece is received. */ }// lookupPiece(int, int) // +-----------+-------------------------------------------- // | Modifiers | // +-----------+ public void putPiece(Piece piece){ /** * Put a piece onto this board's corredponding position. * The method takes a Piece object, which contains its * position. * Be sure that the position of the piece exists on the * board and the corresponding index of the board's * field array or vector is empty or a null piece, an * exception is needed here. After calling this method * a new piece will be put into a specific position on * the board. */ }// putPiece(Piece) public void takeoffPiece(int rownumber, int columnnumber){ /** * Delete a piece at a certain position decided by the * row number and column number parameters. The * position should exist on the board, an exception is * needed here. If there is a piece, delete this piece * from the board. If not, the position remains vacant. * In the field, the position's index place should * be changed to vacant or contain a null piece. * Use this method when you know the position of a piece. */ }// takeoffPiece(int, int) public void takeoffPiece(Piece piece) { /** * Delete a certain piece. Its position on board and * index in the array of vector field is determined by * the piece's field. Be sure that the parameter piece * is on the board, or an exception should be thrown. * After this method is called, the board's field should * be updated. * Use this method when you know a specific piece but * don't care where on board it is. */ }// takeoffPiece(Piece) public void movePiece(int oldrownumber, int oldcolumnnumber, int newrownumber, int newcolumnnumber){ /** * Move a piece decided by the old row and column * number to a new position decided by the new row and * column number. Some precondition is needed: 1)The * old and new positions exist on the board. 2)There * is a piece at the old position. 3)The new position * should be empty or a null piece. An exception is * needed here. After this method is called, the old * position should be empty and its piece is moved into * the new position. Some corresponding changes will * happen to this object's field's index. */ }// movePiece(int, int, int, int) public void updatePiece(Piece oldpiece, Piece newpiece){ /** * Update a certain piece. That is to change the * oldpiece's data to the newpiece's data. * Be sure that the oldpiece exist on the board and the * newpiece's position is vacant. An exception is needed. */ }// updatePiece(Piece, Piece) }// class Board