use of common.datastore.MinoOperationWithKey in project solution-finder by knewjade.
the class ParityBasedPackSearcher method search.
public Stream<List<MinoOperationWithKey>> search(List<Piece> usingPieces) {
// 準備
MinoFactory minoFactory = new MinoFactory();
PositionLimitParser positionLimitParser = new PositionLimitParser(minoFactory, maxClearLine);
LockedReachableThreadLocal threadLocal = new LockedReachableThreadLocal(maxClearLine);
ParityField parityField = new ParityField(field);
PieceCounter pieceCounter = new PieceCounter(usingPieces);
ColumnParityLimitation limitation = new ColumnParityLimitation(pieceCounter, parityField, maxClearLine);
return limitation.enumerate().parallelStream().map(EstimateBuilder::create).flatMap(Collection::stream).flatMap(deltaLimitedMinos -> parseToSortedFullLimitedMinoStream(positionLimitParser, deltaLimitedMinos)).limit(// parallelでの並列数をリセットする(同時実行数を増やす)
Long.MAX_VALUE).flatMap(sets -> new CrossBuilder(sets, field, maxClearLine).create().stream()).filter(operationWithKeys -> BuildUp.existsValidBuildPattern(verifyField, operationWithKeys, maxClearLine, threadLocal.get()));
}
use of common.datastore.MinoOperationWithKey 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 common.datastore.MinoOperationWithKey in project solution-finder by knewjade.
the class BuildUpStreamTest method buildUp2.
@Test
void buildUp2() {
// 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,R,0,1;O,0,1,0;L,L,3,1;I,0,1,0");
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(16).doesNotContain("IJOL", "IJLO", "IOJL", "IOLJ", "ILOJ", // starts I
"ILJO").doesNotContain("OIJL", // starts OI
"OILJ").contains("OJLI", "OJIL", "JOIL", "JLIO", "LOJI", "LIOJ");
}
use of common.datastore.MinoOperationWithKey in project solution-finder by knewjade.
the class CSVPathOutput method outputOperationsToCSV.
private void outputOperationsToCSV(Field field, MyFile file, List<PathPair> pathPairs, SizedBit sizedBit) throws FinderExecuteException {
LockedBuildUpListUpThreadLocal threadLocal = new LockedBuildUpListUpThreadLocal(sizedBit.getHeight());
List<List<MinoOperationWithKey>> samples = pathPairs.parallelStream().map(resultPair -> {
Result result = resultPair.getResult();
LinkedList<MinoOperationWithKey> operations = result.getMemento().getSeparableMinoStream(sizedBit.getWidth()).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
BuildUpStream buildUpStream = threadLocal.get();
return buildUpStream.existsValidBuildPatternDirectly(field, operations).findFirst().orElse(Collections.emptyList());
}).collect(Collectors.toList());
try (BufferedWriter writer = file.newBufferedWriter()) {
for (List<MinoOperationWithKey> operationWithKeys : samples) {
Operations operations = OperationTransform.parseToOperations(field, operationWithKeys, sizedBit.getHeight());
String operationLine = OperationInterpreter.parseToString(operations);
writer.write(operationLine);
writer.newLine();
}
writer.flush();
} catch (IOException e) {
throw new FinderExecuteException("Failed to output file", e);
}
}
use of common.datastore.MinoOperationWithKey in project solution-finder by knewjade.
the class OneFumenParser method parse.
@Override
public String parse(List<MinoOperationWithKey> operations, Field field, int maxClearLine) {
// BlockField を生成
BlockField blockField = createBlockField(operations, maxClearLine);
// パターンを表す名前 を生成
String blocksName = operations.stream().map(OperationWithKey::getPiece).map(Piece::getName).collect(Collectors.joining());
// テト譜1ページを作成
TetfuElement tetfuElement = createTetfuElement(field, blockField, blocksName, maxClearLine);
Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
return tetfu.encode(Collections.singletonList(tetfuElement));
}
Aggregations