-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConwayRules.java
More file actions
47 lines (47 loc) · 1.46 KB
/
ConwayRules.java
File metadata and controls
47 lines (47 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.awt.Color;
public class ConwayRules implements Rules
{
public int getDefaultCellState(){
return 0;
}
public int[] getAcceptableCellStates(){
return new int[]{0,1};
}
public Color getCellColor(int cellState){
if(cellState==0) return Color.WHITE;
return Color.BLACK;
}
public int getNeighborValue(int cellState){
return cellState;
}
public int getCellState(int cellState, int neighborCount){
if(cellState==0){
if(neighborCount==3) return 1;
return 0;
}else{
if(neighborCount<2) return 0;
if(neighborCount>3) return 0;
return 1;
}
}
public int getCellState(int cellState){
if(cellState==1||cellState==0) return cellState;
System.out.println(cellState+" not acceptable for ConwayRules");
return 0;
}
public int getCellStateFromFile(char c){
if(c=='.' || c=='0' || (c>='a' && c<='z')) return 0;
if((c>'0' && c<='9') || (c>='A' && c<='Z')) return 1;
throw new IllegalArgumentException(c+" is not a valid input for OurRules");
}
public char getCellStateForFile(int cellState){
if(cellState==this.getDefaultCellState()) return '.';
else return Integer.toString(cellState).charAt(0);
}
public boolean initRule(){
return true;
}
public int getCellStateFromClick(int cellState){
return (cellState+1)%2;
}
}