use of core.field.Field in project solution-finder by knewjade.
the class FilterOnDemandBasicSolutions method addColumnSmallField.
private RecursiveMinoFields addColumnSmallField(ColumnField basicField) {
Field wallField = createWallField(basicField);
ColumnSmallField initOuterField = ColumnFieldFactory.createField();
RecursiveMinoFields recursiveMinoFields = calculate(basicField, initOuterField, wallField);
return new FilteredRecursiveMinoFields(recursiveMinoFields, solutionFilter);
}
use of core.field.Field in project solution-finder by knewjade.
the class ConnectionsToStreamCallable method parseWhenFilled.
private Stream<RecursiveMinoField> parseWhenFilled(ColumnField columnField, ColumnField outerColumnField, Field wallField, SeparableMino currentMino) {
// これからブロックをおく場所以外を、すでにブロックで埋めたフィールドを作成
Field freeze = wallField.freeze(calculator.getHeight());
Field invertedOuterField = calculator.parseInvertedOuterField(outerColumnField);
freeze.merge(invertedOuterField);
// 置くブロック以外がすでに埋まっていると仮定したとき、正しく接着できる順があるか確認
SeparableMinos separableMinos = calculator.getSeparableMinos();
RecursiveMinoField result = new RecursiveMinoField(currentMino, outerColumnField.freeze(calculator.getHeight()), separableMinos);
// 次に埋めるべき場所がないときは結果をそのまま返す
if (needFilledField.isPerfect()) {
return Stream.of(result);
}
// 現在のフィールドに埋めるべきところがないが、次以降のフィールドに残っている場合をケアする
List<SeparableMino> allMinos = separableMinos.getMinos();
return over(columnField, outerColumnField, allMinos, separableMinos, result);
}
use of core.field.Field in project solution-finder by knewjade.
the class CheckmateUsingHoldReuse method search.
@Override
public List<Result> search(Field initFieldOrigin, Piece[] pieces, Candidate<T> candidate, int maxClearLine, int maxDepth) {
Field initField = initFieldOrigin.freeze(maxClearLine);
int deleteLine = initField.clearLine();
int height = maxClearLine - deleteLine;
TreeSet<Order> orders = new TreeSet<>();
// 最初の探索開始depthとordersを調整
int startDepth;
if (!equalsField(lastField, initField) || lastPieces == null) {
// mementoの初期化
// 初めから
memento = new ArrayList<>();
orders.add(new NormalOrder(initField, pieces[0], height, maxDepth));
startDepth = 1;
memento.add(new TreeSet<>(orders));
} else {
int reuseIndex = -1;
int minLength = lastPieces.length < pieces.length ? lastPieces.length : pieces.length;
int max = maxDepth + 1 < minLength ? maxDepth + 1 : minLength;
for (int index = 0; index < max; index++) {
if (lastPieces[index] == pieces[index])
reuseIndex = index;
else
break;
}
if (reuseIndex < 0) {
memento = new ArrayList<>();
orders.add(new NormalOrder(initField, pieces[0], height, maxDepth));
startDepth = 1;
memento.add(new TreeSet<>(orders));
} else if (reuseIndex == maxDepth) {
return dataPool.getResults();
} else {
orders.addAll(memento.get(reuseIndex));
startDepth = reuseIndex + 1;
memento = memento.subList(0, reuseIndex + 1);
}
}
dataPool.resetResults();
for (int depth = startDepth; depth <= maxDepth; depth++) {
dataPool.initEachDepth();
boolean isLast = depth == maxDepth;
if (depth < pieces.length) {
Piece drawn = pieces[depth];
for (int count = 0, size = orders.size(); count < size; count++) {
Order order = orders.pollFirst();
searcherCore.stepWithNext(candidate, drawn, order, isLast);
}
} else {
for (int count = 0, size = orders.size(); count < size; count++) {
Order order = orders.pollFirst();
searcherCore.stepWhenNoNext(candidate, order, isLast);
}
}
orders = dataPool.getNexts();
memento.add(new TreeSet<>(orders));
}
lastPieces = pieces;
lastField = initField;
return dataPool.getResults();
}
use of core.field.Field in project solution-finder by knewjade.
the class SimpleSearcherCore method step.
private void step(Candidate<T> candidate, Piece drawn, Piece nextHold, Order order, boolean isLast) {
Field currentField = order.getField();
int max = order.getMaxClearLine();
Set<T> candidateList = candidate.search(currentField, drawn, max);
OperationHistory history = order.getHistory();
for (T action : candidateList) {
Field field = currentField.freeze(max);
Mino mino = minoFactory.create(drawn, action.getRotate());
field.put(mino, action.getX(), action.getY());
int clearLine = field.clearLine();
int maxClearLine = max - clearLine;
if (!validator.validate(field, maxClearLine))
continue;
if (validator.satisfies(field, maxClearLine)) {
Result result = new Result(order, drawn, action, nextHold);
dataPool.addResult(result);
continue;
}
if (isLast)
continue;
OperationHistory nextHistory = history.recordAndReturnNew(drawn, action);
Order nextOrder = new NormalOrder(field, nextHold, maxClearLine, nextHistory);
dataPool.addOrder(nextOrder);
}
}
use of core.field.Field 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);
}
Aggregations