import Piece; /** * A stub class for Board to store, delete and move pieces on it. * * @March 2000 * @author Ming Gu, Yasir Mehboob. * Ammar Bandukwala. Mustally Hussain, Shiva Kabra. */ public class StubBoard implements Cloneable{ // +--------+----------------------------------------------- // | Fields | // +--------+ /** * Create field: protected Piece[][] 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 * pieces[a-1][b-1] in the array. * REMEMBER!!! The row and column numbers start from (1, 1). */ protected Piece[][] pieces; protected int row; protected int column; // +--------------+----------------------------------------- // | Constructors | // +--------------+ /** * Create a Board with parameters: int rownumber, int columnnumber. * The fields should be: int[rownumber+1][columnnumber+1]. */ public StubBoard(int rownumber, int columnnumber) { row = rownumber; column = columnnumber; this.pieces = new Piece[rownumber][columnnumber]; } /** * Return an identical board as this one. You have to cast this object to * Board first before using it. */ public Object clone() { Board newboard = new Board(row, column); newboard.pieces = this.pieces; return newboard; } // +------------+------------------------------------------- // | Extractors | // +------------+ public int getNumberofRows() { return 8; } public int getNumberofColumns() { return 8; } public Piece[][] getAllpieces() { return pieces; } /** * 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. * After this method is called, there shouldn't be any * changes made to the board. */ public Piece lookupPiece(int rownumber, int columnnumber){ return this.pieces[rownumber-1][columnnumber-1]; } /** * Look up a position and see if it is occupied. This method * should take the column number and row number as its * parameters. Return f if the position is null. */ public boolean isOccupied(int rownumber, int columnnumber) throws Exception{ return false; } // +-----------+-------------------------------------------- // | Modifiers | // +-----------+ /** * Put a piece onto this board's corredponding position. * The method takes a Piece as its parameter, which contains * its position and color. * 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. */ public void putPiece(Piece p) throws Exception { } /** * 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. */ public void takeoffPiece(Piece p) throws Exception { } /** * 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. */ public void movePiece(Piece p, int newrow, int newcolumn) throws Exception{ } /** * Update a certain piece. That is to change the * oldpiece's data to the newpiece's data. Two parameters * are: Piece oldpiece, Piece newpiece. * Be sure that the oldpiece exist on the board and the * newpiece's position is vacant. An exception is needed. */ public void updatePiece(Piece oldpiece, Piece newpiece) throws Exception { } }// class StubBoard