-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSegment.java
51 lines (40 loc) · 1.6 KB
/
Segment.java
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
import java.util.*;
public class Segment implements Chunk {
private int row, col, layer;
private int[][] pl; //simply stores reference
public Segment(int r, int c, int[][] plane, int i) {
row = r;
col = c;
pl = plane; //stores reference to plane array, NOT clone
layer = i; //stores what plane level it is
}
public int[][] getSegArr() {
int[][] temp = new int[8][8];
for(int r = row; r < row + 8; r++) for(int c = col; c < col + 8; c++) temp[r - row][c - col] = pl[r][c];
return temp;
}
public String toString() {
int[][] temp = getSegArr();
String result = "Position: (" + row + ", " + col + ")\r\nPlane " + layer + "\r\n";
for(int k = 0; k < 8; k++) {
for(int j = 0; j < 8; j++) result += temp[k][j] + " ";
result += "\r\n";
}
return result;
}
public int getBorder() {
int changes = 0;
//number of row changes
for(int r = row; r < row + 8; r++) for(int c = col + 1; c < col + 8; c++) if(pl[r][c] != pl[r][c - 1]) changes++;
//number of column changes
for(int c = col; c < col + 8; c++) for(int r = row + 1; r < row + 8; r++) if(pl[r][c] != pl[r - 1][c]) changes++;
return changes;
}
public boolean isComplex() {
return (getBorder() / 64.0) > 0.3;
}
public void replaceWith(Block data) {
int[][] temp = data.getBlock();
for(int r = row; r < row + 8; r++) for(int c = col; c < col + 8; c++) pl[r][c] = temp[r - row][c - col]; //replace segment section with provided block
}
}