use of common.datastore.MinoOperationWithKey in project solution-finder by knewjade.
the class SRSValidSolutionFilter method testLast.
@Override
public boolean testLast(MinoFieldMemento memento) {
if (!test(memento))
return false;
LinkedList<MinoOperationWithKey> operations = memento.getSeparableMinoStream(sizedBit.getWidth()).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
Reachable reachable = reachableThreadLocal.get();
return BuildUp.existsValidBuildPattern(field, operations, sizedBit.getHeight(), reachable);
}
use of common.datastore.MinoOperationWithKey in project solution-finder by knewjade.
the class BuildUp method cansBuild.
// 指定した手順で組み立てられるか確認
public static boolean cansBuild(Field fieldOrigin, List<MinoOperationWithKey> operationWithKeys, int height, Reachable reachable) {
Field field = fieldOrigin.freeze(height);
for (MinoOperationWithKey operationWithKey : operationWithKeys) {
long deleteKey = field.clearLineReturnKey();
long needDeletedKey = operationWithKey.getNeedDeletedKey();
if ((deleteKey & needDeletedKey) != needDeletedKey) {
// 必要な列が消えていない
return false;
}
// すでに下のラインが消えているときは、その分スライドさせる
int originalY = operationWithKey.getY();
int deletedLines = Long.bitCount(KeyOperators.getMaskForKeyBelowY(originalY) & deleteKey);
Mino mino = operationWithKey.getMino();
int x = operationWithKey.getX();
int y = originalY - deletedLines;
if (field.isOnGround(mino, x, y) && field.canPut(mino, x, y) && reachable.checks(field, mino, x, y, height)) {
field.put(mino, x, y);
field.insertBlackLineWithKey(deleteKey);
} else {
return false;
}
}
return true;
}
use of common.datastore.MinoOperationWithKey in project solution-finder by knewjade.
the class BuildUp method existsValidBuildPatternRecursive.
private static boolean existsValidBuildPatternRecursive(Field field, LinkedList<MinoOperationWithKey> operationWithKeys, int height, Reachable reachable) {
long deleteKey = field.clearLineReturnKey();
for (int index = 0; index < operationWithKeys.size(); index++) {
MinoOperationWithKey key = operationWithKeys.remove(index);
long needDeletedKey = key.getNeedDeletedKey();
if ((deleteKey & needDeletedKey) != needDeletedKey) {
// 必要な列が消えていない
operationWithKeys.add(index, key);
continue;
}
// すでに下のラインが消えているときは、その分スライドさせる
int originalY = key.getY();
int deletedLines = Long.bitCount(KeyOperators.getMaskForKeyBelowY(originalY) & deleteKey);
Mino mino = key.getMino();
int x = key.getX();
int y = originalY - deletedLines;
if (field.isOnGround(mino, x, y) && field.canPut(mino, x, y) && reachable.checks(field, mino, x, y, height - mino.getMinY())) {
if (operationWithKeys.isEmpty())
return true;
Field nextField = field.freeze(height);
nextField.put(mino, x, y);
nextField.insertBlackLineWithKey(deleteKey);
boolean exists = existsValidBuildPatternRecursive(nextField, operationWithKeys, height, reachable);
if (exists)
return true;
}
operationWithKeys.add(index, key);
}
field.insertBlackLineWithKey(deleteKey);
return false;
}
use of common.datastore.MinoOperationWithKey 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);
}
use of common.datastore.MinoOperationWithKey in project solution-finder by knewjade.
the class BuildUpStreamTest method buildUp1.
@Test
void buildUp1() {
// Create LockedReachable
int height = 4;
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
// Create OperationWithKey List
Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX");
Operations operations = OperationInterpreter.parseToOperations("J,0,1,0;S,L,1,2;O,0,2,1;J,2,2,1");
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
// Create Pieces
Set<String> valid = new BuildUpStream(reachable, height).existsValidBuildPattern(field, operationWithKeys).map(op -> op.stream().map(OperationWithKey::getPiece).map(Piece::name).collect(Collectors.joining())).collect(Collectors.toSet());
// Assertion
assertThat(valid).hasSize(2).contains("JSOJ", "JOSJ");
}
Aggregations