use of common.datastore.Operation in project solution-finder by knewjade.
the class SequenceFumenParser method parse.
@Override
public String parse(List<MinoOperationWithKey> operations, Field field, int maxClearLine) {
Operations operations2 = OperationTransform.parseToOperations(field, operations, maxClearLine);
List<? extends Operation> operationsList = operations2.getOperations();
// ブロック順に変換
List<Piece> pieceList = operationsList.stream().map(Operation::getPiece).collect(Collectors.toList());
// テト譜を作成
String quiz = Tetfu.encodeForQuiz(pieceList);
ArrayList<TetfuElement> tetfuElements = new ArrayList<>();
// 最初のelement
Operation firstKey = operationsList.get(0);
ColorType colorType1 = colorConverter.parseToColorType(firstKey.getPiece());
ColoredField coloredField = createInitColoredField(field, maxClearLine);
TetfuElement firstElement = new TetfuElement(coloredField, colorType1, firstKey.getRotate(), firstKey.getX(), firstKey.getY(), quiz);
tetfuElements.add(firstElement);
// 2番目以降のelement
if (1 < operationsList.size()) {
operationsList.subList(1, operationsList.size()).stream().map(operation -> {
ColorType colorType = colorConverter.parseToColorType(operation.getPiece());
return new TetfuElement(colorType, operation.getRotate(), operation.getX(), operation.getY(), quiz);
}).forEach(tetfuElements::add);
}
Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
return tetfu.encode(tetfuElements);
}
use of common.datastore.Operation in project solution-finder by knewjade.
the class OperationInterpreterTest method parseRandom.
@Test
void parseRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 1; size < 20; size++) {
List<Operation> operationList = Stream.generate(() -> {
Piece piece = randoms.block();
Rotate rotate = randoms.rotate();
int x = randoms.nextInt(10);
int y = randoms.nextInt(4);
return new SimpleOperation(piece, rotate, x, y);
}).limit(size).collect(Collectors.toList());
Operations operations = new Operations(operationList);
String str = OperationInterpreter.parseToString(operations);
Operations actual = OperationInterpreter.parseToOperations(str);
assertThat(actual).isEqualTo(operations);
}
}
use of common.datastore.Operation in project solution-finder by knewjade.
the class PathCore method run.
List<PathPair> run(Field field, SizedBit sizedBit) throws ExecutionException, InterruptedException {
List<Result> candidates = searcher.toList();
int maxClearLine = sizedBit.getHeight();
return candidates.parallelStream().map(result -> {
LinkedList<MinoOperationWithKey> operations = result.getMemento().getSeparableMinoStream(sizedBit.getWidth()).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
// 地形の中で組むことができるoperationsをすべてリスト化する
BuildUpStream buildUpStream2 = buildUpStreamThreadLocal.get();
List<List<MinoOperationWithKey>> validOperaions = buildUpStream2.existsValidBuildPatternDirectly(field, operations).collect(Collectors.toList());
// 地形の中で組むことができるものがないときはスキップ
if (validOperaions.isEmpty())
return PathPair.EMPTY_PAIR;
// 地形の中で組むことができるSetを作成
HashSet<LongPieces> piecesSolution = validOperaions.stream().map(operationWithKeys -> operationWithKeys.stream().map(OperationWithKey::getPiece)).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
// 探索シーケンスの中で組むことができるSetを作成
HashSet<LongPieces> piecesPattern = getPiecesPattern(piecesSolution);
// 探索シーケンスの中で組むことができるものがないときはスキップ
if (piecesPattern.isEmpty())
return PathPair.EMPTY_PAIR;
// 探索シーケンスの中でテト譜にするoperationsを選択する
List<MinoOperationWithKey> operationsToUrl = validOperaions.stream().filter(o -> validPieces.contains(new LongPieces(o.stream().map(Operation::getPiece)))).findFirst().orElse(Collections.emptyList());
// 譜面の作成
String fumen = fumenParser.parse(operationsToUrl, field, maxClearLine);
return new PathPair(result, piecesSolution, piecesPattern, fumen, new ArrayList<>(operationsToUrl), validPieces);
}).filter(pathPair -> pathPair != PathPair.EMPTY_PAIR).collect(Collectors.toList());
}
use of common.datastore.Operation in project solution-finder by knewjade.
the class PathCSVCaseTest method none1.
@Test
void none1() throws Exception {
// フォーマットをCSV
/*
comment: 4 -p I,*p6
X_________
XXXXX_____
XXXXX_____
XXXXX_____
*/
String tetfu = "v115@9gA8IeE8EeE8EeE8OeAgWQA0no2ANI98AwN88AjPEN?B";
int height = 4;
ConfigFileHelper.createFieldFile(FieldFactory.createField(height), height);
ConfigFileHelper.createPatternFile("*p2");
String command = String.format("path -t %s -f csv -k none", tetfu);
Log log = RunnerHelper.runnerCatchingLog(() -> EntryPointMain.main(command.split(" ")));
assertThat(log.getOutput()).contains("I,*p6").contains(Messages.clearLine(4)).contains(Messages.uniqueCount(186)).contains(Messages.minimalCount(142)).contains(Messages.useHold());
assertThat(log.getReturnCode()).isEqualTo(0);
Field field = FieldFactory.createField("" + "X_________" + "XXXXX_____" + "XXXXX_____" + "XXXXX_____");
// unique
PathCSV uniqueCSV = OutputFileHelper.loadPathUniqueNoneCSV();
assertThat(uniqueCSV.operations().stream().map(operations -> {
Field freeze = field.freeze(height);
for (Operation operation : operations.getOperations()) {
freeze.put(new Mino(operation.getPiece(), operation.getRotate()), operation.getX(), operation.getY());
freeze.clearLine();
}
return freeze;
})).hasSize(186).allMatch(Field::isPerfect);
// minimal
PathCSV minimalCSV = OutputFileHelper.loadPathMinimalNoneCSV();
assertThat(minimalCSV.operations().stream().map(operations -> {
Field freeze = field.freeze(height);
for (Operation operation : operations.getOperations()) {
freeze.put(new Mino(operation.getPiece(), operation.getRotate()), operation.getX(), operation.getY());
freeze.clearLine();
}
return freeze;
})).hasSize(142).allMatch(Field::isPerfect);
}
use of common.datastore.Operation in project solution-finder by knewjade.
the class OperationHistoryTest method random.
@Test
void random() throws ExecutionException, InterruptedException {
Randoms randoms = new Randoms();
for (int count = 0; count < 1000; count++) {
int size = randoms.nextInt(1, 10);
ArrayList<Operation> operations = new ArrayList<>();
OperationHistory history = new OperationHistory(size);
for (int index = 0; index < size; index++) {
Piece piece = randoms.block();
Rotate rotate = randoms.rotate();
int y = randoms.nextInt(4);
int x = randoms.nextInt(10);
MinimalAction action = MinimalAction.create(x, y, rotate);
history = history.recordAndReturnNew(piece, action);
operations.add(new SimpleOperation(piece, rotate, x, y));
}
List<Operation> actual = history.getOperationStream().collect(Collectors.toList());
assertThat(actual).isEqualTo(operations);
}
}
Aggregations