Search in sources :

Example 1 with SizedBit

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

the class Field4x10MinoPackingHelper method fixResult.

// 高さが4・最後の1列がのこる場合で、パフェできるパターンは2つしか存在しない
@Override
public Stream<Result> fixResult(PackSearcher searcher, long innerFieldBoard, MinoFieldMemento nextMemento) {
    SizedBit sizedBit = searcher.getSizedBit();
    SolutionFilter solutionFilter = searcher.getSolutionFilter();
    if (innerFieldBoard == sizedBit.getFillBoard()) {
        if (solutionFilter.testLast(nextMemento))
            return Stream.of(createResult(nextMemento));
    } else {
        assert innerFieldBoard == 0b111111110000L;
        MinoFieldMemento concatILeft = nextMemento.concat(LEFT_I_ONLY);
        if (solutionFilter.testLast(concatILeft))
            return Stream.of(createResult(concatILeft));
    }
    return Stream.empty();
}
Also used : SizedBit(searcher.pack.SizedBit) SolutionFilter(searcher.pack.memento.SolutionFilter) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

Example 2 with SizedBit

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

the class MinoPackingTaskWidthForWidth2 method split.

private PackingTask split(MinoField minoField) {
    ColumnField minoOuterField = minoField.getOuterField();
    // 注目範囲外outerで重なりがないか確認
    if (outerField.canMerge(minoOuterField)) {
        // 有効なおきかた
        SizedBit sizedBit = searcher.getSizedBit();
        ColumnField mergedOuterField = outerField.freeze(sizedBit.getHeight());
        mergedOuterField.merge(minoOuterField);
        long innerFieldBoard = mergedOuterField.getBoard(0) >> sizedBit.getMaxBitDigit();
        MinoFieldMemento nextMemento = memento.concat(minoField);
        return checkAndCreateTask(innerFieldBoard, nextMemento, index + 1);
    }
    return EMPTY_TASK;
}
Also used : SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

Example 3 with SizedBit

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

the class MinoPackingTaskWidthForWidth2 method splitAndFixResult.

private Stream<Result> splitAndFixResult(MinoField minoField) {
    ColumnField minoOuterField = minoField.getOuterField();
    // 注目範囲外outerで重なりがないか確認
    if (outerField.canMerge(minoOuterField)) {
        // 有効なおきかた
        SizedBit sizedBit = searcher.getSizedBit();
        ColumnField mergedOuterField = outerField.freeze(searcher.getSizedBit().getHeight());
        mergedOuterField.merge(minoOuterField);
        long innerFieldBoard = mergedOuterField.getBoard(0) >> sizedBit.getMaxBitDigit();
        MinoFieldMemento nextMemento = memento.concat(minoField);
        return searcher.getTaskResultHelper().fixResult(searcher, innerFieldBoard, nextMemento);
    }
    return Stream.empty();
}
Also used : SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

Example 4 with SizedBit

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

the class MinoPackingTaskWidthForWidth2 method compute.

@Override
public Stream<Result> compute() {
    if (searcher.isFilled(innerField, index)) {
        // innerFieldが埋まっている
        if (index == searcher.getLastIndex()) {
            // 最後の計算
            SizedBit sizedBit = searcher.getSizedBit();
            long innerFieldBoard = outerField.getBoard(0) >> sizedBit.getMaxBitDigit();
            MinoFieldMemento nextMemento = memento.skip();
            return searcher.getTaskResultHelper().fixResult(searcher, innerFieldBoard, nextMemento);
        } else {
            // 途中の計算  // 自分で計算する
            MinoFieldMemento nextMemento = memento.skip();
            long innerFieldBoard = outerField.getBoard(0) >> searcher.getSizedBit().getMaxBitDigit();
            return createTask(searcher, innerFieldBoard, nextMemento, index + 1).compute();
        }
    } else {
        MinoFields minoFields = searcher.getSolutions(index).parse(innerField);
        // innerFieldが埋まっていない
        if (index == searcher.getLastIndex()) {
            // 最後の計算
            return minoFields.stream().parallel().flatMap(this::splitAndFixResult);
        } else {
            // 途中の計算
            return minoFields.stream().parallel().map(this::split).filter(this::isValidTask).flatMap(PackingTask::compute);
        }
    }
}
Also used : MinoFields(searcher.pack.mino_fields.MinoFields) SizedBit(searcher.pack.SizedBit) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

Example 5 with SizedBit

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

the class MinoPackingTaskWidthForWidth3 method split.

private PackingTask split(MinoField minoField) {
    ColumnField outerField = searcher.getInOutPairFields().get(index).getOuterField();
    ColumnField minoOuterField = minoField.getOuterField();
    // 注目範囲外outerで重なりがないか確認
    if (outerField.canMerge(minoOuterField)) {
        // 有効なおきかた
        SizedBit sizedBit = searcher.getSizedBit();
        ColumnField mergedOuterField = outerField.freeze(sizedBit.getHeight());
        mergedOuterField.merge(minoOuterField);
        ColumnSmallField nextInnerField = ColumnFieldFactory.createField(mergedOuterField.getBoard(0) >> sizedBit.getMaxBitDigit());
        MinoFieldMemento nextMemento = memento.concat(minoField);
        return checkAndCreateTask(nextInnerField, nextMemento, index + 1);
    }
    return EMPTY_TASK;
}
Also used : ColumnSmallField(core.column_field.ColumnSmallField) SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

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