Search in sources :

Example 41 with LongPieces

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

the class ForwardOrderLookUpTest method parseOverBlocks.

@Test
void parseOverBlocks() throws Exception {
    List<Piece> pieceList = Arrays.asList(Piece.I, Piece.T, Piece.Z, Piece.O, Piece.I, Piece.L);
    int toDepth = pieceList.size() - 1;
    PiecesNumberComparator comparator = new PiecesNumberComparator();
    List<LongPieces> forward1 = OrderLookup.forwardBlocks(pieceList, toDepth).stream().map(StackOrder::toList).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
    ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth, pieceList.size());
    List<LongPieces> forward2 = lookUp.parse(pieceList).map(blockStream -> blockStream.collect(Collectors.toList())).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
    assertThat(forward2).isEqualTo(forward1);
}
Also used : Test(org.junit.jupiter.api.Test) HashSet(java.util.HashSet) Piece(core.mino.Piece) Randoms(lib.Randoms) Arrays(java.util.Arrays) List(java.util.List) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) PiecesNumberComparator(common.comparator.PiecesNumberComparator) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces) PiecesNumberComparator(common.comparator.PiecesNumberComparator) Test(org.junit.jupiter.api.Test)

Example 42 with LongPieces

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

the class PiecesNameComparatorTest method compare.

@Test
void compare() throws Exception {
    LongPieces pieces1 = new LongPieces(Arrays.asList(Piece.T, Piece.O, Piece.I));
    LongPieces pieces2 = new LongPieces(Arrays.asList(Piece.T, Piece.O, Piece.I));
    PiecesNameComparator comparator = new PiecesNameComparator();
    assertThat(comparator.compare(pieces1, pieces2)).isEqualTo(0);
    assertThat(comparator.compare(pieces2, pieces1)).isEqualTo(0);
}
Also used : LongPieces(common.datastore.blocks.LongPieces) Test(org.junit.jupiter.api.Test)

Example 43 with LongPieces

use of common.datastore.blocks.LongPieces 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 44 with LongPieces

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

the class PackSearcherComparingParityBasedOnDemandTest method testAllSRSValidPacksHeight4.

// 高さ4: パリティベースとの探索結果を比較する (同一ミノは2つまで)
@Test
@LongTest
void testAllSRSValidPacksHeight4() throws Exception {
    int width = 3;
    int height = 4;
    String resultPath = ClassLoader.getSystemResource("perfects/pack_height4.txt").getPath();
    List<TestData> testCases = Files.lines(Paths.get(resultPath)).map(line -> line.split("//")[0]).map(String::trim).filter(line -> !line.isEmpty()).map(line -> line.split("=")).map(split -> {
        Stream<Piece> blocks = BlockInterpreter.parse(split[0]);
        LongPieces pieces = new LongPieces(blocks);
        int count = Integer.valueOf(split[1]);
        return new TestData(pieces, count);
    }).collect(Collectors.toList());
    compareCount(width, height, testCases);
}
Also used : Pieces(common.datastore.blocks.Pieces) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) ColumnField(core.column_field.ColumnField) FilterWrappedBasicSolutions(searcher.pack.solutions.FilterWrappedBasicSolutions) HashSet(java.util.HashSet) PieceCounter(common.datastore.PieceCounter) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) CombinationIterable(common.iterable.CombinationIterable) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) BlockInterpreter(common.parser.BlockInterpreter) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) 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) Paths(java.nio.file.Paths) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) Collections(java.util.Collections) LongPieces(common.datastore.blocks.LongPieces) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 45 with LongPieces

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

the class PackSearcherComparingParityBasedOnDemandTest method testAllSRSValidPacksHeight5.

// 高さ5: パリティベースとの探索結果を比較する (同一ミノは2つまで)
@Test
void testAllSRSValidPacksHeight5() throws Exception {
    int width = 2;
    int height = 5;
    String resultPath = ClassLoader.getSystemResource("perfects/pack_height5.txt").getPath();
    List<TestData> testCases = Files.lines(Paths.get(resultPath)).map(line -> line.split("//")[0]).map(String::trim).filter(line -> !line.isEmpty()).map(line -> line.split("=")).map(split -> {
        Stream<Piece> blocks = BlockInterpreter.parse(split[0]);
        LongPieces pieces = new LongPieces(blocks);
        int count = Integer.valueOf(split[1]);
        return new TestData(pieces, count);
    }).collect(Collectors.toList());
    compareCount(width, height, testCases);
}
Also used : Pieces(common.datastore.blocks.Pieces) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) ColumnField(core.column_field.ColumnField) FilterWrappedBasicSolutions(searcher.pack.solutions.FilterWrappedBasicSolutions) HashSet(java.util.HashSet) PieceCounter(common.datastore.PieceCounter) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) CombinationIterable(common.iterable.CombinationIterable) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) BlockInterpreter(common.parser.BlockInterpreter) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) 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) Paths(java.nio.file.Paths) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) Collections(java.util.Collections) LongPieces(common.datastore.blocks.LongPieces) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Aggregations

LongPieces (common.datastore.blocks.LongPieces)71 Test (org.junit.jupiter.api.Test)58 Piece (core.mino.Piece)42 PatternGenerator (common.pattern.PatternGenerator)38 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)36 Randoms (lib.Randoms)27 Collectors (java.util.stream.Collectors)22 Field (core.field.Field)19 Pieces (common.datastore.blocks.Pieces)16 LongTest (module.LongTest)16 List (java.util.List)14 Stream (java.util.stream.Stream)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 FieldFactory (core.field.FieldFactory)12 ArrayList (java.util.ArrayList)12 SizedBit (searcher.pack.SizedBit)12 MinoFactory (core.mino.MinoFactory)11 HashSet (java.util.HashSet)11 ExecutionException (java.util.concurrent.ExecutionException)10 BlockInterpreter (common.parser.BlockInterpreter)9