Difference between revisions of "Computer Science/61b/Homework/hw6/SimpleBoard.java"

From lensowiki
< Computer Science‎ | 61b‎ | Homework‎ | hw6
Jump to: navigation, search
 
Line 1: Line 1:
{{code}}
+
[url=http://941mp3.com/quran-mp3.html]quran mp3[/url]
/* SimpleBoard.java */
+
[url=http://941mp3.com/mp3-arabe.html]mp3 arabe[/url]
+
[url=http://941mp3.com/mp3-download.html]mp3 download[/url]
/**
+
[url=http://941mp3.com/creative-mp3-player.html]creative mp3 player[/url]
*  Simple class that implements an 8x8 game board with three possible values
+
 
  *  for each cell:  0, 1 or 2.
+
[url=http://941mp3.com/heafphones.html]heafphones[/url]
  *
+
[url=http://941mp3.com/mp3.html]mp3[/url]
  *  DO NOT CHANGE ANY PROTOTYPES IN THIS FILE.
+
[url=http://941mp3.com/mp3-music.html]mp3 music[/url]
  **/
+
 
+
[url=http://941mp3.com/download-free-minnale-mp3-song-tamil.html]download free minnale mp3 song tamil[/url]
public class SimpleBoard {
 
private final static int DIMENSION = 8;
 
private int[][] grid;
 
 
/**
 
*  Invariants: 
 
*  (1) grid.length == DIMENSION.
 
*  (2) for all 0 <= i < DIMENSION, grid[i].length == DIMENSION.
 
*  (3) for all 0 <= i, j < DIMENSION, grid[i][j] >= 0 and grid[i][j] <= 2.
 
**/
 
 
/**
 
*  Construct a new board in which all cells are zero.
 
*/
 
 
public SimpleBoard() {
 
grid = new int[DIMENSION][DIMENSION];
 
}
 
 
/**
 
*  Set the cell (x, y) in the board to the given value mod 3.
 
*  @param value to which the element should be set (normally 0, 1, or 2).
 
*  @param x is the x-index.
 
*  @param y is the y-index.
 
*  @exception ArrayIndexOutOfBoundsException is thrown if an invalid index
 
*  is given.
 
**/
 
 
public void setElementAt(int x, int y, int value) {
 
grid[x][y] = value % 3;
 
if (grid[x][y] < 0) {
 
grid[x][y] = grid[x][y] + 3;
 
}
 
}
 
 
/**
 
*  Get the valued stored in cell (x, y).
 
*  @param x is the x-index.
 
*  @param y is the y-index.
 
*  @return the stored value (between 0 and 2).
 
*  @exception ArrayIndexOutOfBoundsException is thrown if an invalid index
 
*  is given.
 
*/
 
 
public int elementAt(int x, int y) {
 
return grid[x][y];
 
}
 
 
/**
 
*  Returns true if "this" SimpleBoard and "board" have identical values in
 
*    every cell.
 
*  @param board is the second SimpleBoard.
 
*  @return true if the boards are equal, false otherwise.
 
*/
 
 
public boolean equals(Object board) {
 
if (board.getClass() == this.getClass()) {
 
return (this.hashCode() == board.hashCode());
 
} else {
 
return false;
 
}
 
}
 
 
/**
 
*  Returns a hash code for this SimpleBoard.
 
*  @return a number between Integer.MIN_VALUE and Integer.MAX_VALUE.
 
*/
 
 
public int hashCode() {
 
int hash = 0;
 
for (int io=0; io<DIMENSION; io++) {
 
for (int ii=0; ii<DIMENSION; ii++) {
 
hash = hash * 3 + grid[io][ii];
 
}
 
}
 
return hash;
 
}
 
}
 

Revision as of 12:04, 25 April 2007

[url=http://941mp3.com/quran-mp3.html]quran mp3[/url] [url=http://941mp3.com/mp3-arabe.html]mp3 arabe[/url] [url=http://941mp3.com/mp3-download.html]mp3 download[/url] [url=http://941mp3.com/creative-mp3-player.html]creative mp3 player[/url]

[url=http://941mp3.com/heafphones.html]heafphones[/url] [url=http://941mp3.com/mp3.html]mp3[/url] [url=http://941mp3.com/mp3-music.html]mp3 music[/url]

[url=http://941mp3.com/download-free-minnale-mp3-song-tamil.html]download free minnale mp3 song tamil[/url]