-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCell.pde
80 lines (69 loc) · 1.93 KB
/
Cell.pde
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class Cell{
int x,y;
boolean collapsed;
ArrayList<Tile> possible=new ArrayList<Tile>();
Tile finalTile;
Cell(int x_,int y_,ArrayList<Tile> possible_){
x=x_;
y=y_;
possible=possible_;
collapsed=false;
}
void display(){
if(collapsed){
image(finalTile.img,x*rows,y*cols,rows,cols);
}
}
boolean isPossible(Cell c, Tile t){//checks if the tile is present in possible
for(Tile tile : c.possible){
if(tile.isSame(t)) return true;
}
return false;
}
//randomly decides the final tile and follows the core algo
void finalise(){
collapsed=true;
int randChoice=(int)random(possible.size());
finalTile=possible.get(randChoice);
//for up-cell
if(y>0){
ArrayList<Tile> newPossible=new ArrayList<Tile>();
for(Tile t : tiles){
if(t.edges[2]==finalTile.edges[0] && isPossible(grid[x][y-1],t)){
newPossible.add(t);
}
}
grid[x][y-1].possible=newPossible;
}
//for down cell
if(y<dim-1){
ArrayList<Tile> newPossible=new ArrayList<Tile>();
for(Tile t : tiles){
if(t.edges[0]==finalTile.edges[2] && isPossible(grid[x][y+1],t)){
newPossible.add(t);
}
}
grid[x][y+1].possible=newPossible;
}
//for left
if(x>0){
ArrayList<Tile> newPossible=new ArrayList<Tile>();
for(Tile t : tiles){
if(t.edges[1]==finalTile.edges[3] && isPossible(grid[x-1][y],t)){
newPossible.add(t);
}
}
grid[x-1][y].possible=newPossible;
}
//for right
if(x<dim-1){
ArrayList<Tile> newPossible=new ArrayList<Tile>();
for(Tile t : tiles){
if(t.edges[3]==finalTile.edges[1] && isPossible(grid[x+1][y],t)){
newPossible.add(t);
}
}
grid[x+1][y].possible=newPossible;
}
}
}