Search in sources :

Example 11 with SizedBit

use of searcher.pack.SizedBit in project solution-finder by knewjade.

the class MappedBasicSolutionsFactoryTest method create3x3.

@Test
void create3x3() throws Exception {
    SizedBit sizedBit = new SizedBit(3, 3);
    int expectedSolutions = 254;
    int expectedSolutionItems = 3972;
    assertCache(sizedBit, expectedSolutions, expectedSolutionItems);
}
Also used : SizedBit(searcher.pack.SizedBit) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 12 with SizedBit

use of searcher.pack.SizedBit in project solution-finder by knewjade.

the class MappedBasicSolutionsFactoryTest method create3x4.

@Test
void create3x4() throws Exception {
    SizedBit sizedBit = new SizedBit(3, 4);
    int expectedSolutions = 2211;
    int expectedSolutionItems = 228022;
    assertCache(sizedBit, expectedSolutions, expectedSolutionItems);
}
Also used : SizedBit(searcher.pack.SizedBit) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 13 with SizedBit

use of searcher.pack.SizedBit in project solution-finder by knewjade.

the class MappedBasicSolutionsFactoryTest method create3x1.

@Test
void create3x1() throws Exception {
    SizedBit sizedBit = new SizedBit(3, 1);
    int expectedSolutions = 3;
    int expectedSolutionItems = 3;
    assertCache(sizedBit, expectedSolutions, expectedSolutionItems);
}
Also used : SizedBit(searcher.pack.SizedBit) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 14 with SizedBit

use of searcher.pack.SizedBit in project solution-finder by knewjade.

the class MappedBasicSolutionsFactoryTest method create2x6.

@Test
@LongTest
void create2x6() throws Exception {
    SizedBit sizedBit = new SizedBit(2, 6);
    int expectedSolutions = 3490;
    int expectedSolutionItems = 8380826;
    assertCache(sizedBit, expectedSolutions, expectedSolutionItems);
}
Also used : SizedBit(searcher.pack.SizedBit) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 15 with SizedBit

use of searcher.pack.SizedBit in project solution-finder by knewjade.

the class PatternCSVPathOutput method output.

@Override
public void output(List<PathPair> pathPairs, Field field, SizedBit sizedBit) throws FinderExecuteException {
    this.lastException = null;
    outputLog("Found path = " + pathPairs.size());
    AtomicInteger validCounter = new AtomicInteger();
    AtomicInteger allCounter = new AtomicInteger();
    try (AsyncBufferedFileWriter writer = outputBaseFile.newAsyncWriter()) {
        writer.writeAndNewLine("ツモ,対応地形数,使用ミノ,未使用ミノ,テト譜");
        generator.blocksStream().parallel().map(blocks -> {
            // シーケンス名を取得
            String sequenceName = blocks.blockStream().map(Piece::getName).collect(Collectors.joining());
            // パフェ可能な地形を抽出
            List<PathPair> valid = pathPairs.stream().filter(pathPair -> {
                HashSet<? extends Pieces> buildBlocks = pathPair.blocksHashSetForPattern();
                return buildBlocks.contains(blocks);
            }).collect(Collectors.toList());
            // パフェ可能な地形数
            int possibleSize = valid.size();
            // パフェ可能ならカウンターをインクリメント
            allCounter.incrementAndGet();
            if (0 < possibleSize)
                validCounter.incrementAndGet();
            // パフェ可能な地形のテト譜を連結
            String fumens = valid.stream().sorted(Comparator.comparing(PathPair::getPatternSize).reversed()).map(pathPair -> "v115@" + pathPair.getFumen()).collect(Collectors.joining(";"));
            // 使うミノ一覧を抽出
            Set<PieceCounter> usesSet = valid.stream().map(PathPair::getBlockCounter).collect(Collectors.toSet());
            String uses = usesSet.stream().map(blockCounter -> {
                return blockCounter.getBlockStream().sorted().map(Piece::getName).collect(Collectors.joining());
            }).collect(Collectors.joining(";"));
            // 残せるミノ一覧を抽出
            PieceCounter orderPieceCounter = new PieceCounter(blocks.blockStream());
            String noUses = usesSet.stream().map(orderPieceCounter::removeAndReturnNew).distinct().map(blockCounter -> {
                return blockCounter.getBlockStream().sorted().map(Piece::getName).collect(Collectors.joining());
            }).collect(Collectors.joining(";"));
            return String.format("%s,%d,%s,%s,%s", sequenceName, possibleSize, uses, noUses, fumens);
        }).forEach(writer::writeAndNewLine);
        writer.flush();
    } catch (IOException e) {
        throw new FinderExecuteException("Failed to output file", e);
    }
    outputLog("");
    outputLog("perfect clear percent");
    outputLog(String.format("  -> success = %.2f%% (%d/%d)", 100.0 * validCounter.get() / allCounter.get(), validCounter.get(), allCounter.get()));
    if (lastException != null)
        throw new FinderExecuteException("Error to output file", lastException);
}
Also used : Piece(core.mino.Piece) Pieces(common.datastore.blocks.Pieces) PatternGenerator(common.pattern.PatternGenerator) Set(java.util.Set) ReducePatternGenerator(entry.path.ReducePatternGenerator) IOException(java.io.IOException) FinderExecuteException(exceptions.FinderExecuteException) FinderInitializeException(exceptions.FinderInitializeException) Collectors(java.util.stream.Collectors) File(java.io.File) HashSet(java.util.HashSet) PieceCounter(common.datastore.PieceCounter) SizedBit(searcher.pack.SizedBit) List(java.util.List) Field(core.field.Field) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AsyncBufferedFileWriter(lib.AsyncBufferedFileWriter) PathPair(entry.path.PathPair) Comparator(java.util.Comparator) PathEntryPoint(entry.path.PathEntryPoint) PathSettings(entry.path.PathSettings) Set(java.util.Set) HashSet(java.util.HashSet) PieceCounter(common.datastore.PieceCounter) IOException(java.io.IOException) PathPair(entry.path.PathPair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AsyncBufferedFileWriter(lib.AsyncBufferedFileWriter) Piece(core.mino.Piece) List(java.util.List) FinderExecuteException(exceptions.FinderExecuteException)

Aggregations

SizedBit (searcher.pack.SizedBit)53 Test (org.junit.jupiter.api.Test)32 ColumnField (core.column_field.ColumnField)29 SeparableMinos (searcher.pack.SeparableMinos)22 Field (core.field.Field)18 LongTest (module.LongTest)18 MinoFactory (core.mino.MinoFactory)15 MinoShifter (core.mino.MinoShifter)15 SolutionFilter (searcher.pack.memento.SolutionFilter)15 InOutPairField (searcher.pack.InOutPairField)14 Piece (core.mino.Piece)13 Collectors (java.util.stream.Collectors)13 BasicSolutions (searcher.pack.calculator.BasicSolutions)13 Predicate (java.util.function.Predicate)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 SeparableMino (searcher.pack.separable_mino.SeparableMino)11 PerfectPackSearcher (searcher.pack.task.PerfectPackSearcher)11 Result (searcher.pack.task.Result)11 TaskResultHelper (searcher.pack.task.TaskResultHelper)10 Stream (java.util.stream.Stream)9