use of common.datastore.Operations 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.Operations 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.Operations in project solution-finder by knewjade.
the class MoveEntryPoint method run.
@Override
public void run() throws FinderException {
output("# Setup Field");
// Setup field
Field field = settings.getField();
Verify.field(field);
int maxClearLine = settings.getMaxClearLine();
output(FieldView.toString(field, maxClearLine));
// Setup max depth
// パフェに必要なミノ数
int maxDepth = Verify.maxDepth(field, maxClearLine);
output();
// ========================================
output("Searching patterns:");
// Setup patterns
List<String> patterns = settings.getPatterns();
PatternGenerator generator = Verify.patterns(patterns);
// Output patterns
for (String pattern : patterns) output(" " + pattern);
output();
// ========================================
// baseファイル
MyFile base = new MyFile(settings.getOutputBaseFilePath());
base.mkdirs();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
ColorConverter colorConverter = new ColorConverter();
PerfectValidator perfectValidator = new PerfectValidator();
PutterNoHold<Action> putter = new PutterNoHold<>(minoFactory, perfectValidator);
output("# Calculate");
try (BufferedWriter bw = base.newBufferedWriter()) {
List<Pieces> pieces = generator.blocksStream().collect(Collectors.toList());
for (Pieces piece : pieces) {
String using = piece.blockStream().map(Piece::getName).collect(Collectors.joining());
output(" -> " + using);
TreeSet<Order> first = putter.first(field, piece.getPieceArray(), new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine), maxClearLine, maxDepth);
for (Order order : first) {
Stream<Operation> operationStream = order.getHistory().getOperationStream();
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, new Operations(operationStream), minoFactory, maxClearLine);
BlockField blockField = OperationTransform.parseToBlockField(operationWithKeys, minoFactory, maxClearLine);
String encodeColor = encodeColor(field, minoFactory, colorConverter, blockField);
String encodeGray = encodeGray(order.getField(), minoFactory, colorConverter);
bw.write(String.format("%s,%s,%s", using, encodeColor, encodeGray));
bw.newLine();
}
}
bw.flush();
} catch (IOException e) {
throw new FinderExecuteException("Failed to output file", e);
}
}
Aggregations