/* SimpleBoard.java */ import Supporting.*; /** * Simple class that implements an 8x8 game board with three * possible values for each position, 0, 1 or 2. */ public class SimpleBoard implements Hashable { /** * Construct an new board in which all positions * in the board are empty. */ public SimpleBoard() { grid = new int [DIMENSION][DIMENSION]; } /** * Set the position x, y in the board to the given value % 3. * @param value to which the element should be set (normally a * value between 0 and 2 inclusive). * @param x is the index of the x direction to be set. * @param y is the index of the y direction to be set. * @exception ArrayIndexOutOfBoundsException is thrown if an * invalid pair of indices is given. */ public void setElementAt( int x, int y, int value ) { grid[x][y] = value % 3; } /** * Get the valued stored in position x, y. * @param x is the index of the x direction to get. * @param y is the index of the y direction to get. * @return the stored value (which is always between 0 and 2). * @exception ArrayIndexOutOfBoundsException is thrown if an * invalid pair of indices is given. */ public int elementAt(int x, int y) { return grid[x][y]; } /** * Implements the equals method. * @param board is the second SimpleBoard. * @return true if the objects are equal, false otherwise. * @exception ClassCastException if board is not * a SimpleBoard. */ public boolean equals( Object board ) { // FILL IN, REPLACING LINE BELOW return false; } /** * Implements the hash method. * @param tableSize the hash table size. * @return a number between 0 and tableSize-1. */ public int hash( int tableSize ) { // FILL IN, REPLACING LINE BELOW return 99; } /* Invariants: * 1) grid.length == DIMENSION * 2) forall 0 <= i < DIMENSION, grid[i].length == DIMENSION * 3) forall 0 <= i, j < DIMENSION, grid[i][j] > -1 and grid[i][j] < 3 */ private int [][] grid; private final static int DIMENSION = 8; }