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