use of core.mino.Piece 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.mino.Piece in project solution-finder by knewjade.
the class AllSeparableMinoFactory method create.
public Set<SeparableMino> create() {
HashSet<SeparableMino> pieces = new HashSet<>();
HashSet<Mino> createdCheckSet = new HashSet<>();
for (Piece piece : Piece.values()) {
for (Rotate originRotate : Rotate.values()) {
Rotate rotate = minoShifter.createTransformedRotate(piece, originRotate);
Mino mino = minoFactory.create(piece, rotate);
// 追加済みかチェック
if (createdCheckSet.contains(mino))
continue;
createdCheckSet.add(mino);
// ミノの高さを計算
int minoHeight = mino.getMaxY() - mino.getMinY() + 1;
// フィールドの高さ以上にミノを使う場合はおけない
if (fieldHeight < minoHeight)
continue;
// 行候補をリストにする
ArrayList<Integer> lineIndexes = getLineIndexes(fieldHeight);
// リストアップ
ArrayList<SeparableMino> piecesEachMino = generatePiecesEachMino(mino, lineIndexes, minoHeight);
// 追加
pieces.addAll(piecesEachMino);
}
}
return pieces;
}
use of core.mino.Piece in project solution-finder by knewjade.
the class ActionParser method parseToOperation.
static Operation parseToOperation(int value) {
int x = value % 10;
value /= 10;
int y = value % 24;
value /= 24;
Rotate rotate = Rotate.getRotate(value % 4);
value /= 4;
Piece piece = Piece.getBlock(value);
return new SimpleOperation(piece, rotate, x, y);
}
use of core.mino.Piece in project solution-finder by knewjade.
the class ResultHelper method createOperationStream.
public static Stream<Operation> createOperationStream(Result result) {
Order order = result.getOrder();
OperationHistory history = order.getHistory();
Stream<Operation> operationStream = history.getOperationStream();
Piece lastPiece = result.getLastPiece();
Action lastAction = result.getLastAction();
SimpleOperation lastOperation = new SimpleOperation(lastPiece, lastAction.getRotate(), lastAction.getX(), lastAction.getY());
return Stream.concat(operationStream, Stream.of(lastOperation));
}
use of core.mino.Piece in project solution-finder by knewjade.
the class BuildUp method existsValidByOrder.
// block順番で組み立てられる手順が存在するかチェックする
// operationsで使用するミノとblocksが一致していること
public static boolean existsValidByOrder(Field field, Stream<MinoOperationWithKey> operations, List<Piece> pieces, int height, Reachable reachable) {
EnumMap<Piece, LinkedList<MinoOperationWithKey>> eachBlocks = operations.sequential().collect(() -> new EnumMap<Piece, LinkedList<MinoOperationWithKey>>(Piece.class), (blockLinkedListEnumMap, operationWithKey) -> {
Piece piece = operationWithKey.getPiece();
LinkedList<MinoOperationWithKey> operationWithKeys = blockLinkedListEnumMap.computeIfAbsent(piece, b -> new LinkedList<>());
operationWithKeys.add(operationWithKey);
}, EnumMap::putAll);
return existsValidByOrder(field.freeze(height), eachBlocks, pieces, height, reachable, 0);
}
Aggregations