Search in sources :

Example 6 with ColumnSmallField

use of core.column_field.ColumnSmallField in project solution-finder by knewjade.

the class InOutPairFieldTest method createMaxOuterBoard3x4.

@Test
void createMaxOuterBoard3x4() {
    Field field = FieldFactory.createField("" + "___X__X_XX" + "__X__XXXX_" + "_X__XX_XX_" + "X___X__X_X");
    int width = 3;
    int height = 4;
    SizedBit sizedBit = new SizedBit(width, height);
    ColumnSmallField maxOuterBoard = InOutPairField.createMaxOuterBoard(sizedBit, field);
    ColumnSmallField expects = ColumnFieldFactory.createField("" + "___X__" + "_____X" + "____XX" + "____X_", height);
    assertThat(maxOuterBoard).isEqualTo(expects);
}
Also used : Field(core.field.Field) ColumnSmallField(core.column_field.ColumnSmallField) ColumnSmallField(core.column_field.ColumnSmallField) Test(org.junit.jupiter.api.Test)

Example 7 with ColumnSmallField

use of core.column_field.ColumnSmallField in project solution-finder by knewjade.

the class BasicSolutionsCalculator method addColumnSmallField.

private void addColumnSmallField(ColumnSmallField basicField) {
    Field wallField = createWallField(basicField);
    ColumnSmallField initOuterField = ColumnFieldFactory.createField();
    RecursiveMinoFields calculate = calculate(basicField, initOuterField, wallField);
    resultsMap.put(basicField, calculate);
}
Also used : ColumnField(core.column_field.ColumnField) SmallField(core.field.SmallField) Field(core.field.Field) ColumnSmallField(core.column_field.ColumnSmallField) ColumnSmallField(core.column_field.ColumnSmallField) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields) MemorizedRecursiveMinoFields(searcher.pack.mino_fields.MemorizedRecursiveMinoFields) OnDemandRecursiveMinoFields(searcher.pack.mino_fields.OnDemandRecursiveMinoFields)

Example 8 with ColumnSmallField

use of core.column_field.ColumnSmallField in project solution-finder by knewjade.

the class OnDemandBasicSolutions method addColumnSmallField.

private RecursiveMinoFields addColumnSmallField(ColumnField basicField) {
    Field wallField = createWallField(basicField);
    ColumnSmallField initOuterField = ColumnFieldFactory.createField();
    return calculate(basicField, initOuterField, wallField);
}
Also used : ColumnField(core.column_field.ColumnField) SmallField(core.field.SmallField) Field(core.field.Field) ColumnSmallField(core.column_field.ColumnSmallField) ColumnSmallField(core.column_field.ColumnSmallField)

Example 9 with ColumnSmallField

use of core.column_field.ColumnSmallField in project solution-finder by knewjade.

the class BasicMinoPackingHelper method fixResult.

@Override
public Stream<Result> fixResult(PackSearcher searcher, long innerFieldBoard, MinoFieldMemento nextMemento) {
    SizedBit sizedBit = searcher.getSizedBit();
    SolutionFilter solutionFilter = searcher.getSolutionFilter();
    long fillBoard = sizedBit.getFillBoard();
    long board = innerFieldBoard & fillBoard;
    int resultIndex = searcher.getLastIndex() + 1;
    ColumnSmallField nextInnerField = ColumnFieldFactory.createField(board);
    if (searcher.isFilled(nextInnerField, resultIndex)) {
        if (solutionFilter.testLast(nextMemento))
            return Stream.of(createResult(nextMemento));
        return Stream.empty();
    } else {
        ColumnSmallField over = ColumnFieldFactory.createField(innerFieldBoard & ~fillBoard);
        MinoFields minoFields = searcher.getSolutions(resultIndex).parse(nextInnerField);
        return minoFields.stream().filter(minoField -> over.canMerge(minoField.getOuterField())).map(nextMemento::concat).filter(solutionFilter::testLast).map(this::createResult);
    }
}
Also used : SolutionFilter(searcher.pack.memento.SolutionFilter) SizedBit(searcher.pack.SizedBit) Stream(java.util.stream.Stream) ColumnFieldFactory(core.column_field.ColumnFieldFactory) ColumnSmallField(core.column_field.ColumnSmallField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento) MinoFields(searcher.pack.mino_fields.MinoFields) ColumnSmallField(core.column_field.ColumnSmallField) MinoFields(searcher.pack.mino_fields.MinoFields) SizedBit(searcher.pack.SizedBit) SolutionFilter(searcher.pack.memento.SolutionFilter)

Example 10 with ColumnSmallField

use of core.column_field.ColumnSmallField in project solution-finder by knewjade.

the class ColumnFieldComparatorTest method compare.

@Test
void compare() throws Exception {
    Randoms randoms = new Randoms();
    ColumnFieldComparator comparator = new ColumnFieldComparator();
    for (int count = 0; count < 10000; count++) {
        // same field
        int height = randoms.nextInt(1, 10);
        ColumnSmallField field1 = ColumnFieldFactory.createField();
        ColumnSmallField field2 = ColumnFieldFactory.createField();
        int maxBlock = randoms.nextInt(1, 15);
        for (int block = 0; block < maxBlock; block++) {
            int x = randoms.nextInt(10);
            int y = randoms.nextInt(height);
            field1.setBlock(x, y, height);
            field2.setBlock(x, y, height);
        }
        assertThat(comparator.compare(field1, field2)).isEqualTo(0);
        assertThat(comparator.compare(field2, field1)).isEqualTo(0);
        // 1block different field
        int x = randoms.nextInt(10);
        int y = randoms.nextInt(height);
        if (field1.isEmpty(x, y, height))
            field1.setBlock(x, y, height);
        else
            field1.removeBlock(x, y, height);
        // assert is not 0 & reversed sign
        assertThat(comparator.compare(field1, field2) * comparator.compare(field2, field1)).isLessThan(0);
    }
}
Also used : ColumnSmallField(core.column_field.ColumnSmallField) Randoms(lib.Randoms) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnSmallField (core.column_field.ColumnSmallField)18 Field (core.field.Field)11 ColumnField (core.column_field.ColumnField)8 Test (org.junit.jupiter.api.Test)7 SmallField (core.field.SmallField)3 SizedBit (searcher.pack.SizedBit)2 MinoFieldMemento (searcher.pack.memento.MinoFieldMemento)2 ColumnFieldFactory (core.column_field.ColumnFieldFactory)1 Mino (core.mino.Mino)1 EntryPoint (entry.EntryPoint)1 ArrayList (java.util.ArrayList)1 Stream (java.util.stream.Stream)1 Randoms (lib.Randoms)1 SeparableMinos (searcher.pack.SeparableMinos)1 SolutionFilter (searcher.pack.memento.SolutionFilter)1 MemorizedRecursiveMinoFields (searcher.pack.mino_fields.MemorizedRecursiveMinoFields)1 MinoFields (searcher.pack.mino_fields.MinoFields)1 OnDemandRecursiveMinoFields (searcher.pack.mino_fields.OnDemandRecursiveMinoFields)1 RecursiveMinoFields (searcher.pack.mino_fields.RecursiveMinoFields)1 MinoMask (searcher.pack.separable_mino.mask.MinoMask)1