Game-of-Life-WSU-CEG4180  v0.1
RefactoringtheGameofLife
Cell.java
Go to the documentation of this file.
1 /* This page is part of the Game of Life source code */
2 
3 package org.bitstorm.gameoflife;
4 
5 /**
6  * Every cell in the grid is a Cell-object.
7  * So it must be as small as possible.
8  * Because every cell is pre-generated, no cells have to be generated when the Game Of Life playw.
9  * Whether a cell is alive or not, is not part of the Cell-object.
10  * @author Edwin Martin
11  *
12  */
13 public class Cell {
14  public final short col;
15  public final short row;
16  /**
17  * Number of neighbours of this cell.
18  *
19  * Determines the next state.
20  */
21  public byte neighbour; // Neighbour is International English
22 
23  /**
24  * HASHFACTOR must be larger than the maximum number of columns (that is: the max width of a monitor in pixels).
25  * It should also be smaller than 65536. (sqrt(MAXINT)).
26  */
27  private final int HASHFACTOR = 5000;
28 
29  /**
30  * Constructor
31  * @param col column of cell
32  * @param row row or cell
33  */
34  public Cell( int col, int row ) {
35  this.col = (short)col;
36  this.row = (short)row;
37  neighbour = 0;
38  }
39 
40  /**
41  * Compare cell-objects for use in hashtables
42  * @see java.lang.Object#equals(java.lang.Object)
43  */
44  public boolean equals(Object o) {
45  if (!(o instanceof Cell) )
46  return false;
47  return col==((Cell)o).col && row==((Cell)o).row;
48  }
49 
50  /**
51  * Calculate hash for use in hashtables
52  *
53  * @see java.lang.Object#hashCode()
54  */
55  public int hashCode() {
56  return HASHFACTOR*row+col;
57  }
58 
59  /**
60  * @see java.lang.Object#toString()
61  */
62  public String toString() {
63  return "Cell at ("+col+", "+row+") with "+neighbour+" neighbour"+(neighbour==1?"":"s");
64  }
65 }
boolean equals(Object o)
Definition: Cell.java:44
Cell(int col, int row)
Definition: Cell.java:34