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);
}
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);
}
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);
}
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);
}
}
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);
}
}
Aggregations