-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonochromeInfoTile.java
More file actions
50 lines (41 loc) · 1.53 KB
/
MonochromeInfoTile.java
File metadata and controls
50 lines (41 loc) · 1.53 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
48
49
50
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
public class MonochromeInfoTile extends InfoTile {
public MonochromeInfoTile(int x, int y) {
super(x, y);
}
// Calculates what text should be written in the InfoTile to make it into a puzzle. This basically means running a Run Length Encoding algorithm
// on the slice(could be horizontal or vertical) for the 0 or 1 values, ignoring the 0's so it's not a trivial puzzle where you are given what each tile should be.
@Override
public void calculateConstraints() {
constraintSlice = ParsedImage.getBooleanSlice(getXCoord(), getYCoord());
if (constraintSlice.length == 0) {
return;
}
ArrayList<Integer> result = runLengthEncoding();
for(int i = 0; i < result.size(); i++) {
this.add(new JLabel(String.valueOf(result.get(i))));
}
}
// Returns an array of the length of the different groups of enabled tiles in the slice.
@Override
public ArrayList<Integer> runLengthEncoding() {
ArrayList<Integer> result = new ArrayList<Integer>();
int counter = 0;
for (int value : constraintSlice) {
if (value == 1) {
if (counter > 0) {
result.add(counter);
counter = 0;
}
} else if (value == 0) {
counter++;
}
}
if(counter > 0) {
result.add(counter);
}
return result;
}
}