Search in sources :

Example 6 with Operation

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);
}
Also used : Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) OperationTransform(common.parser.OperationTransform) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement) ColorConverter(common.tetfu.common.ColorConverter) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Operations(common.datastore.Operations) List(java.util.List) Field(core.field.Field) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) Operation(common.datastore.Operation) ColoredField(common.tetfu.field.ColoredField) ColoredField(common.tetfu.field.ColoredField) ArrayList(java.util.ArrayList) Operation(common.datastore.Operation) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Operations(common.datastore.Operations) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement)

Example 7 with Operation

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);
    }
}
Also used : Randoms(lib.Randoms) Rotate(core.srs.Rotate) Piece(core.mino.Piece) SimpleOperation(common.datastore.SimpleOperation) SimpleOperation(common.datastore.SimpleOperation) Operation(common.datastore.Operation) Operations(common.datastore.Operations) Test(org.junit.jupiter.api.Test)

Example 8 with Operation

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());
}
Also used : SyntaxException(common.SyntaxException) java.util(java.util) Pieces(common.datastore.blocks.Pieces) BlockField(common.datastore.BlockField) LongPieces(common.datastore.blocks.LongPieces) PatternGenerator(common.pattern.PatternGenerator) MinoOperationWithKey(common.datastore.MinoOperationWithKey) SizedBit(searcher.pack.SizedBit) OrderLookup(common.order.OrderLookup) Operation(common.datastore.Operation) FieldFactory(core.field.FieldFactory) StackOrder(common.order.StackOrder) BuildUpStream(common.buildup.BuildUpStream) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKey(common.datastore.OperationWithKey) ReverseOrderLookUp(common.order.ReverseOrderLookUp) Piece(core.mino.Piece) Result(searcher.pack.task.Result) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Field(core.field.Field) Stream(java.util.stream.Stream) SeparableMino(searcher.pack.separable_mino.SeparableMino) FumenParser(entry.path.output.FumenParser) Mino(core.mino.Mino) Result(searcher.pack.task.Result) MinoOperationWithKey(common.datastore.MinoOperationWithKey) LongPieces(common.datastore.blocks.LongPieces) BuildUpStream(common.buildup.BuildUpStream)

Example 9 with Operation

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);
}
Also used : SimpleOperation(common.datastore.SimpleOperation) CSVStore(helper.CSVStore) BeforeEach(org.junit.jupiter.api.BeforeEach) Piece(core.mino.Piece) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Rotate(core.srs.Rotate) EntryPointMain(entry.EntryPointMain) Assertions.entry(org.assertj.core.api.Assertions.entry) Test(org.junit.jupiter.api.Test) Operations(common.datastore.Operations) Field(core.field.Field) _usecase(_usecase) Operation(common.datastore.Operation) FieldFactory(core.field.FieldFactory) Mino(core.mino.Mino) Field(core.field.Field) Mino(core.mino.Mino) SimpleOperation(common.datastore.SimpleOperation) Operation(common.datastore.Operation) Test(org.junit.jupiter.api.Test)

Example 10 with Operation

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);
    }
}
Also used : Randoms(lib.Randoms) MinimalAction(common.datastore.action.MinimalAction) Rotate(core.srs.Rotate) Piece(core.mino.Piece) ArrayList(java.util.ArrayList) SimpleOperation(common.datastore.SimpleOperation) SimpleOperation(common.datastore.SimpleOperation) Operation(common.datastore.Operation) Test(org.junit.jupiter.api.Test)

Aggregations

Operation (common.datastore.Operation)14 SimpleOperation (common.datastore.SimpleOperation)9 Test (org.junit.jupiter.api.Test)8 Piece (core.mino.Piece)7 Field (core.field.Field)5 MinoOperationWithKey (common.datastore.MinoOperationWithKey)4 Operations (common.datastore.Operations)4 BlockField (common.datastore.BlockField)3 Pieces (common.datastore.blocks.Pieces)3 PatternGenerator (common.pattern.PatternGenerator)3 FieldFactory (core.field.FieldFactory)3 Mino (core.mino.Mino)3 Rotate (core.srs.Rotate)3 SyntaxException (common.SyntaxException)2 BuildUpStream (common.buildup.BuildUpStream)2 OperationWithKey (common.datastore.OperationWithKey)2 Action (common.datastore.action.Action)2 LongPieces (common.datastore.blocks.LongPieces)2 Order (common.datastore.order.Order)2 OrderLookup (common.order.OrderLookup)2