use of searcher.pack.separable_mino.mask.MinoMask in project solution-finder by knewjade.
the class FullOperationSeparableMino method create.
public static SeparableMino create(FullOperationWithKey operationWithKey, int upperY, int fieldHeight) {
assert upperY <= 10 : upperY;
Mino mino = operationWithKey.getMino();
long deleteKey = operationWithKey.getNeedDeletedKey();
int y = operationWithKey.getY();
MinoMask minoMask = MinoMaskFactory.create(fieldHeight, mino, y, deleteKey);
int x = operationWithKey.getX();
Field mask = minoMask.getMinoMask(x);
int lowerY = operationWithKey.getY() + operationWithKey.getMino().getMinY();
ColumnSmallField columnField = ColumnFieldFactory.createField();
for (int ny = lowerY; ny <= upperY; ny++) {
for (int nx = x + mino.getMinX(); nx <= x + mino.getMaxX(); nx++) {
if (!mask.isEmpty(nx, ny))
columnField.setBlock(nx, ny, fieldHeight);
}
}
Field field = FieldFactory.createField(fieldHeight);
field.put(operationWithKey.getMino(), operationWithKey.getX(), operationWithKey.getY());
field.insertWhiteLineWithKey(operationWithKey.getNeedDeletedKey());
return new FullOperationSeparableMino(operationWithKey, columnField, field);
}
use of searcher.pack.separable_mino.mask.MinoMask in project solution-finder by knewjade.
the class DeleteKey method create.
public static DeleteKey create(Mino mino, long deleteKey, long usingKey, int lowerY, int upperY) {
int y = lowerY - mino.getMinY();
int maxHeight = upperY + 1;
MinoMask minoMask = MinoMaskFactory.create(maxHeight, mino, y, deleteKey);
int minoHeight = mino.getMaxY() - mino.getMinY() + 1;
int[][] blockCountEachLines = new int[minoHeight][2];
int index = 0;
for (int newY = lowerY; newY <= upperY; newY++) {
Field mask = minoMask.getMinoMask(-mino.getMinX());
int block = mask.getBlockCountOnY(newY);
if (block != 0) {
blockCountEachLines[index][0] = newY;
blockCountEachLines[index][1] = block;
index++;
}
}
assert index == minoHeight;
return new DeleteKey(minoMask, blockCountEachLines, lowerY, deleteKey, usingKey);
}
use of searcher.pack.separable_mino.mask.MinoMask in project solution-finder by knewjade.
the class CrossBuilder method recordResult.
private void recordResult() {
boolean isReuse = true;
for (int index = 0; index < prev.length; index++) {
if (!isReuse || fullLimitedMinos[index] != prev[index]) {
isReuse = false;
List<XField> xFields = cache.get(index);
List<XField> nextXFields = new ArrayList<>();
for (XField xField : xFields) {
Field field = xField.getField();
XHistory xHistory = xField.getxHistory();
FullLimitedMino current = fullLimitedMinos[index];
MinoMask minoMask = current.getMinoMask();
int[] xs = current.getXs();
for (int x : xs) {
Field mask = minoMask.getMinoMask(x);
if (field.canMerge(mask)) {
Field newField = field.freeze(maxClearLine);
newField.merge(mask);
if (perfectValidator.validate(newField, maxClearLine)) {
XHistory newHistory = xHistory.recordAndReturnNew(x);
nextXFields.add(new XField(newField, newHistory));
}
}
}
}
if (index < prev.length - 1) {
cache.set(index + 1, nextXFields);
} else {
for (XField nextXField : nextXFields) {
int[] history = nextXField.getxHistory().getHistory();
assert fullLimitedMinos.length == history.length;
List<MinoOperationWithKey> result = new ArrayList<>();
for (int i = 0, length = history.length; i < length; i++) {
FullLimitedMino limitedMino = fullLimitedMinos[i];
int x = history[i];
Mino mino = limitedMino.getMino();
long deleteKey = limitedMino.getDeleteKey();
long usingKey = limitedMino.getUsingKey();
int lowerY = limitedMino.getLowerY();
MinoOperationWithKey withKey = new FullOperationWithKey(mino, x, deleteKey, usingKey, lowerY);
result.add(withKey);
}
results.add(result);
}
}
prev[index] = fullLimitedMinos[index];
}
}
}
use of searcher.pack.separable_mino.mask.MinoMask in project solution-finder by knewjade.
the class Search method search.
private void search(Field field, int depth) {
if (depth == sets.getDepth()) {
List<OperationWithKey> result = new ArrayList<>();
for (int index = 0, length = fullLimitedMinos.length; index < length; index++) {
FullLimitedMino limitedMino = fullLimitedMinos[index];
int x = xs[index];
Mino mino = limitedMino.getMino();
long deleteKey = limitedMino.getDeleteKey();
long usingKey = limitedMino.getUsingKey();
int lowerY = limitedMino.getLowerY();
OperationWithKey withKey = new FullOperationWithKey(mino, x, deleteKey, usingKey, lowerY);
result.add(withKey);
}
results.add(result);
} else {
FullLimitedMino limitedMino = sets.get(depth);
fullLimitedMinos[depth] = limitedMino;
MinoMask minoMask = limitedMino.getMinoMask();
for (int x : limitedMino.getXs()) {
xs[depth] = x;
Field mask = minoMask.getMinoMask(x);
if (field.canMerge(mask)) {
field.merge(mask);
if (perfectValidator.validate(field, maxClearLine))
search(field, depth + 1);
field.reduce(mask);
}
}
}
}
Aggregations