Game-of-Life-WSU-CEG4180
v0.1
RefactoringtheGameofLife
Main Page
Related Pages
Packages
Classes
Files
File List
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
}
org.bitstorm.gameoflife.Cell.neighbour
byte neighbour
Definition:
Cell.java:21
org.bitstorm.gameoflife.Cell.equals
boolean equals(Object o)
Definition:
Cell.java:44
org.bitstorm.gameoflife.Cell.col
final short col
Definition:
Cell.java:14
org.bitstorm.gameoflife.Cell
Definition:
Cell.java:13
org.bitstorm.gameoflife.Cell.toString
String toString()
Definition:
Cell.java:62
org.bitstorm.gameoflife.Cell.row
final short row
Definition:
Cell.java:15
org.bitstorm.gameoflife.Cell.Cell
Cell(int col, int row)
Definition:
Cell.java:34
org.bitstorm.gameoflife.Cell.hashCode
int hashCode()
Definition:
Cell.java:55
org.bitstorm.gameoflife.Cell.HASHFACTOR
final int HASHFACTOR
Definition:
Cell.java:27
Generated on Sat Oct 24 2015 14:13:25 for Game-of-Life-WSU-CEG4180 by
1.8.9.1