-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.java
285 lines (215 loc) · 6.08 KB
/
Block.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import java.util.ArrayList;
public class Block {
private ArrayList<Integer> xcoords = new ArrayList<Integer>();
private ArrayList<Integer> ycoords = new ArrayList<Integer>();
private int tag;
public int getTag() {
return tag;
}
public void setTag(int tag) {
this.tag = tag;
}
private int count;
private Cell[][] cage;
private ArrayList<Block> rotations = new ArrayList<Block>();
private int maxLine;
private int maxChar;
private int minLine = 1000000;
private int minChar = 1000000;
private int blockNumber = 0;
public int getBlockNumber() {
return blockNumber;
}
public void setBlockNumber(int blockNumber) {
this.blockNumber = blockNumber;
}
private boolean placed = false;
private int pilot;
public boolean isPlaced() {
return placed;
}
public void setPlaced(boolean placed) {
this.placed = placed;
}
public int getPilot() {
return pilot;
}
public void setPilot(int pilot) {
this.pilot = pilot;
}
public Block(Block b){
this.cage = new Cell[b.getCage().length][b.getCage()[0].length];
for(int i = 0; i < this.cage.length; i++){
for(int j = 0; j < this.cage[0].length; j++){
this.cage[i][j] = new Cell(b.getCage()[i][j]);
}
}
for(int k = 0; k < b.getRotations().size(); k++){
Cell [][] temp = new Cell[b.getRotations().get(k).getCage().length][b.getRotations().get(k).getCage()[0].length];
this.rotations.add(new Block(temp));
for(int i = 0; i < b.getRotations().get(k).getCage().length; i++){
for(int j = 0; j < b.getRotations().get(k).getCage()[0].length; j++){
this.rotations.get(k).getCage()[i][j] = new Cell(b.rotations.get(k).getCage()[i][j]);
}
}
}
this.count = b.getCount();
this.maxChar = b.getMaxChar();
this.maxLine = b.getMaxLine();
this.minChar = b.getMinChar();
this.minLine = b.getMinLine();
this.pilot = b.getPilot();
}
public Block(Block b, int x){
this.cage = new Cell[b.getCage().length][b.getCage()[0].length];
for(int i = 0; i < this.cage.length; i++){
for(int j = 0; j < this.cage[0].length; j++){
this.cage[i][j] = new Cell('-');
}
}
this.count = b.getCount();
this.maxChar = b.getMaxChar();
this.maxLine = b.getMaxLine();
this.minChar = b.getMinChar();
this.minLine = b.getMinLine();
//this.pilot = b.findPilot();
}
public Block(){
count = 1;
}
public Block(Cell[][] n){
this.cage = new Cell[n.length][n[0].length];
for(int i = 0; i < this.cage.length; i++){
for(int j = 0; j < this.cage[0].length; j++){
this.cage[i][j] = new Cell('-');
}
}
}
public int findPilot(){
for(int i = 0; i < this.getCage()[0].length; ++i){
if((this.getCage()[0][i].getValue() != ' ') &&(this.getCage()[0][i].getValue() != '-')){
//System.out.println("in pilot");
this.setPilot(i);
return i;
}
}
//did not find value on top line - broken
System.out.println("No value on top line!");
return -1;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public Cell[][] getCage() {
return cage;
}
public ArrayList<Block> getRotations() {
return rotations;
}
public void setRotations(ArrayList<Block> rotations) {
this.rotations = rotations;
}
public void setCage(Cell[][] block) {
this.cage = block;
}
public int getMaxLine() {
return maxLine;
}
public void setMaxLine(int maxLine) {
this.maxLine = maxLine;
}
public int getMaxChar() {
return maxChar;
}
public void setMaxChar(int maxChar) {
this.maxChar = maxChar;
}
public int getMinLine() {
return minLine;
}
public void setMinLine(int minLine) {
this.minLine = minLine;
}
public int getMinChar() {
return minChar;
}
public void setMinChar(int minChar) {
this.minChar = minChar;
}
public ArrayList<Integer> getXcoords() {
return xcoords;
}
public void setXcoords(ArrayList<Integer> xcoords) {
this.xcoords = xcoords;
}
public ArrayList<Integer> getYcoords() {
return ycoords;
}
public void setYcoords(ArrayList<Integer> ycoords) {
this.ycoords = ycoords;
}
public void makeBlockCage(Grid g){
int x = maxLine - minLine + 1;
int y = maxChar - minChar + 1;
cage = new Cell[x][y];
for(int i = 0; i < this.getXcoords().size(); ++i){
int tempx = this.getXcoords().get(i);
int tempy = this.getYcoords().get(i);
cage[tempx - minLine][tempy - minChar] = new Cell(g.getPlot()[tempx][tempy]);
}
for(int i = 0; i < x; i++){
for(int j = 0; j < y; j++){
if(cage[i][j] == null) {
cage[i][j] = new Cell(' ');
}
}
}
}
public void storeRotations(){
this.rotations.add(this);
for(int i = 0; i < 3; i++){
this.rotations.add(this.makeRotations(rotations.get(i).getCage()));
}
}
public Block makeRotations(Cell[][] c){
Cell[][] rot = new Cell[c[0].length][c.length];
Block newCage = new Block(rot);
for(int i = 0; i < c.length; i++){
for(int j = 0; j < c[0].length; j++){
newCage.getCage()[c[0].length - j - 1][i] = new Cell(c[i][j]);
}
}
//newCage.printCage(newCage.getCage());
newCage.findPilot();
return newCage;
}
public void printCage(){
for(int i = 0; i < this.getCage().length; i++){
for(int j = 0; j < this.getCage()[0].length; j++){
//System.out.print(Character.toString((char) (this.getCage()[i][j].getBlockNumber() + 65)));
System.out.print(this.getCage()[i][j].getValue());
}
System.out.println();
}
System.out.println();
}
public boolean equals(Block b){
if(b == null)
return false;
if(this.getCage().length != b.getCage().length)
return false;
if(this.getCage()[0].length != b.getCage()[0].length)
return false;
for( int i = 0; i < this.getCage().length; i++){
for(int j = 0; j < this.getCage()[0].length; j++){
if(this.getCage()[i][j].getValue() != b.getCage()[i][j].getValue()){
return false;
}
}
}
return true;
}
}