Search in sources :

Example 11 with OperationWithKey

use of common.datastore.OperationWithKey in project solution-finder by knewjade.

the class OperationWithKeyComparatorTest method compareDiffUsingKey.

@Test
void compareDiffUsingKey() throws Exception {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    int x = randoms.nextInt(10);
    int y = randoms.nextInt(20);
    long deleteKey = 0L;
    long usingKey = 1049600L;
    OperationWithKey operationWithKey1 = new FullOperationWithKey(minoFactory.create(Piece.I, Rotate.Spawn), x, y, deleteKey, usingKey);
    Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
    Long choose = randoms.key();
    OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, deleteKey, choose);
    // assert is 0
    OperationWithKeyComparator<OperationWithKey> comparator = new OperationWithKeyComparator<>();
    int compare1 = comparator.compare(operationWithKey1, operationWithKey2);
    assertThat(compare1).as(operationWithKey1.toString()).isEqualTo(0);
    int compare2 = comparator.compare(operationWithKey2, operationWithKey1);
    assertThat(compare2).as(operationWithKey2.toString()).isEqualTo(0);
}
Also used : Randoms(lib.Randoms) OperationWithKey(common.datastore.OperationWithKey) FullOperationWithKey(common.datastore.FullOperationWithKey) Mino(core.mino.Mino) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Example 12 with OperationWithKey

use of common.datastore.OperationWithKey in project solution-finder by knewjade.

the class OperationWithKeyComparatorTest method compareDiffY.

@Test
void compareDiffY() throws Exception {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    int x = randoms.nextInt(10);
    int y = randoms.nextInt(20);
    long deleteKey = 0L;
    long usingKey = 1049600L;
    OperationWithKey operationWithKey1 = new FullOperationWithKey(minoFactory.create(Piece.I, Rotate.Spawn), x, y, deleteKey, usingKey);
    int newY = randoms.nextInt(20);
    if (newY == y)
        newY += 1;
    Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
    OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, newY, deleteKey, usingKey);
    // assert is not 0 & sign reversed
    OperationWithKeyComparator comparator = new OperationWithKeyComparator();
    assertThat(comparator.compare(operationWithKey1, operationWithKey2) * comparator.compare(operationWithKey2, operationWithKey1)).as(operationWithKey2.toString()).isLessThan(0);
}
Also used : Randoms(lib.Randoms) OperationWithKey(common.datastore.OperationWithKey) FullOperationWithKey(common.datastore.FullOperationWithKey) Mino(core.mino.Mino) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Example 13 with OperationWithKey

use of common.datastore.OperationWithKey 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));
}
Also used : OperationWithKey(common.datastore.OperationWithKey) MinoOperationWithKey(common.datastore.MinoOperationWithKey) BlockField(common.datastore.BlockField) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement)

Example 14 with OperationWithKey

use of common.datastore.OperationWithKey in project solution-finder by knewjade.

the class EasyPath method buildUp.

public Set<LongPieces> buildUp(String goalFieldMarks, Field initField, int width, int height) throws ExecutionException, InterruptedException {
    assert !initField.existsAbove(height);
    SizedBit sizedBit = new SizedBit(width, height);
    Field goalField = FieldFactory.createInverseField(goalFieldMarks);
    List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(sizedBit, goalField);
    // Create
    BasicSolutions basicSolutions = createMappedBasicSolutions(sizedBit);
    TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
    // Assert
    SolutionFilter solutionFilter = createSRSSolutionFilter(sizedBit, initField);
    // パフェ手順の列挙
    PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
    LockedReachableThreadLocal reachableThreadLocal = easyPool.getLockedReachableThreadLocal(height);
    List<Result> results = searcher.toList();
    return results.stream().map(Result::getMemento).map(memento -> {
        return memento.getSeparableMinoStream(width).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toList());
    }).map(operations -> new BuildUpStream(reachableThreadLocal.get(), height).existsValidBuildPattern(initField, operations)).flatMap(listStream -> {
        return listStream.map(operationWithKeys -> {
            Stream<Piece> blocks = operationWithKeys.stream().map(OperationWithKey::getPiece);
            return new LongPieces(blocks);
        });
    }).collect(Collectors.toSet());
}
Also used : TaskResultHelper(searcher.pack.task.TaskResultHelper) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields) BasicSolutionsCalculator(searcher.pack.solutions.BasicSolutionsCalculator) LongPieces(common.datastore.blocks.LongPieces) ColumnField(core.column_field.ColumnField) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) Map(java.util.Map) SeparableMinos(searcher.pack.SeparableMinos) FieldFactory(core.field.FieldFactory) BuildUpStream(common.buildup.BuildUpStream) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKey(common.datastore.OperationWithKey) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) MinoShifter(core.mino.MinoShifter) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) Piece(core.mino.Piece) Result(searcher.pack.task.Result) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) BasicSolutions(searcher.pack.calculator.BasicSolutions) Stream(java.util.stream.Stream) SeparableMino(searcher.pack.separable_mino.SeparableMino) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) SeparableMino(searcher.pack.separable_mino.SeparableMino) TaskResultHelper(searcher.pack.task.TaskResultHelper) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) BasicSolutions(searcher.pack.calculator.BasicSolutions) Result(searcher.pack.task.Result) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) SizedBit(searcher.pack.SizedBit) InOutPairField(searcher.pack.InOutPairField) LongPieces(common.datastore.blocks.LongPieces) SolutionFilter(searcher.pack.memento.SolutionFilter) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) BuildUpStream(common.buildup.BuildUpStream) Stream(java.util.stream.Stream) BuildUpStream(common.buildup.BuildUpStream)

Example 15 with OperationWithKey

use of common.datastore.OperationWithKey in project solution-finder by knewjade.

the class PathPairComparator method compare.

@Override
public int compare(PathPair o1, PathPair o2) {
    int compareDeletedLine = Boolean.compare(o1.isDeletedLine(), o2.isDeletedLine());
    if (compareDeletedLine != 0)
        return compareDeletedLine;
    List<OperationWithKey> operations1 = o1.getSampleOperations();
    List<OperationWithKey> operations2 = o2.getSampleOperations();
    int compareSize = Integer.compare(operations1.size(), operations2.size());
    if (compareSize != 0)
        return compareSize;
    for (int index = 0; index < operations1.size(); index++) {
        OperationWithKey operation1 = operations1.get(index);
        OperationWithKey operation2 = operations2.get(index);
        int compareBlock = operation1.getPiece().compareTo(operation2.getPiece());
        if (compareBlock != 0)
            return compareBlock;
        int compareRotate = operation1.getRotate().compareTo(operation2.getRotate());
        if (compareRotate != 0)
            return compareRotate;
    }
    return 0;
}
Also used : OperationWithKey(common.datastore.OperationWithKey)

Aggregations

OperationWithKey (common.datastore.OperationWithKey)16 MinoFactory (core.mino.MinoFactory)9 Field (core.field.Field)8 Mino (core.mino.Mino)8 Randoms (lib.Randoms)8 Test (org.junit.jupiter.api.Test)8 FullOperationWithKey (common.datastore.FullOperationWithKey)7 Piece (core.mino.Piece)7 MinoOperationWithKey (common.datastore.MinoOperationWithKey)6 Collectors (java.util.stream.Collectors)6 SizedBit (searcher.pack.SizedBit)6 SeparableMino (searcher.pack.separable_mino.SeparableMino)6 FieldFactory (core.field.FieldFactory)5 ExecutionException (java.util.concurrent.ExecutionException)5 PerfectPackSearcher (searcher.pack.task.PerfectPackSearcher)5 Result (searcher.pack.task.Result)5 LongPieces (common.datastore.blocks.LongPieces)4 ColumnField (core.column_field.ColumnField)4 List (java.util.List)4 Stream (java.util.stream.Stream)4