use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class PathCore method run.
List<PathPair> run(Field field, SizedBit sizedBit, BlockField blockField) throws ExecutionException, InterruptedException {
int maxClearLine = sizedBit.getHeight();
List<Result> candidates = searcher.stream(resultStream -> {
return resultStream.filter(result -> {
LinkedList<MinoOperationWithKey> operations = result.getMemento().getSeparableMinoStream(sizedBit.getWidth()).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
BlockField mergedField = new BlockField(maxClearLine);
operations.forEach(operation -> {
Field operationField = createField(operation, maxClearLine);
mergedField.merge(operationField, operation.getPiece());
});
return mergedField.containsAll(blockField);
}).collect(Collectors.toList());
});
return candidates.stream().map(result -> {
LinkedList<MinoOperationWithKey> operations = result.getMemento().getSeparableMinoStream(sizedBit.getWidth()).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
// 地形の中で組むことができるoperationsを一つ作成
BuildUpStream buildUpStream = buildUpStreamThreadLocal.get();
List<MinoOperationWithKey> sampleOperations = buildUpStream.existsValidBuildPatternDirectly(field, operations).findFirst().orElse(Collections.emptyList());
// 地形の中で組むことができるものがないときはスキップ
if (sampleOperations.isEmpty())
return PathPair.EMPTY_PAIR;
// 地形の中で組むことができるSetを作成
HashSet<LongPieces> piecesSolution = buildUpStream.existsValidBuildPatternDirectly(field, operations).map(operationWithKeys -> operationWithKeys.stream().map(OperationWithKey::getPiece).collect(Collectors.toList())).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
// 探索シーケンスの中で組むことができるSetを作成
HashSet<LongPieces> piecesPattern = getPiecesPattern(piecesSolution);
// 探索シーケンスの中で組むことができるものがないときはスキップ
if (piecesPattern.isEmpty())
return PathPair.EMPTY_PAIR;
// 譜面の作成
String fumen = fumenParser.parse(sampleOperations, field, maxClearLine);
return new PathPair(result, piecesSolution, piecesPattern, fumen, new ArrayList<>(sampleOperations), validPieces);
}).filter(pathPair -> pathPair != PathPair.EMPTY_PAIR).collect(Collectors.toList());
}
Aggregations