use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class PackSearcherComparingParityBasedTest 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);
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class CheckerUsingHoldTest method assertResult.
private void assertResult(Field field, int maxClearLine, LockedReachable reachable, List<Piece> blocks) {
Result result = checker.getResult();
// Check blocks is same
List<Piece> resultPieces = parseToBlocks(result);
Piece lastHoldPiece = result.getLastHold();
HashSet<LongPieces> pieces = OrderLookup.reverseBlocks(resultPieces, blocks.size()).stream().map(StackOrder::toStream).map(stream -> stream.map(block -> block != null ? block : lastHoldPiece)).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
assertThat(pieces).contains(new LongPieces(blocks));
// Check can build result
Operations operations = parseToOperations(result);
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, maxClearLine);
boolean cansBuild = BuildUp.cansBuild(field, operationWithKeys, maxClearLine, reachable);
assertThat(cansBuild).isTrue();
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class CheckerUsingHoldTest method testPossiblePerfect.
@Test
@LongTest
void testPossiblePerfect() throws Exception {
// Field
Field field = FieldFactory.createSmallField();
int maxClearLine = 4;
int maxDepth = 10;
// Set to check No Possible Perfect
String noPerfectPath = ClassLoader.getSystemResource("orders/noperfect.txt").getPath();
HashSet<LongPieces> noPerfectSet = Files.lines(Paths.get(noPerfectPath)).map(BlockInterpreter::parse).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
Randoms randoms = new Randoms();
for (int count = 0; count < 100; count++) {
// Set test case
int cycle = randoms.nextIntClosed(0, 8);
List<Piece> pieces = randoms.block11InCycle(cycle);
// Execute
boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
boolean expectedFlag = !noPerfectSet.contains(new LongPieces(pieces));
assertThat(isSucceed).isEqualTo(expectedFlag);
// Check result
if (isSucceed)
assertResult(field, maxClearLine, reachable, pieces);
}
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class HoldBreakEnumeratePiecesTest method enumerateJustAny.
@Test
void enumerateJustAny() throws Exception {
PatternGenerator generator = new LoadedPatternGenerator("T, O, S");
HoldBreakEnumeratePieces core = new HoldBreakEnumeratePieces(generator, 3);
Set<LongPieces> pieces = core.enumerate();
assertThat(pieces).hasSize(4);
assertThat(core.getCounter()).isEqualTo(1);
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class HoldBreakEnumeratePiecesTest method enumerateMulti.
@Test
void enumerateMulti() throws Exception {
PatternGenerator generator = new LoadedPatternGenerator(Arrays.asList("T, J, O, Z", "T, O, J, T", "T, J, O, Z"));
HoldBreakEnumeratePieces core = new HoldBreakEnumeratePieces(generator, 3);
Set<LongPieces> pieces = core.enumerate();
assertThat(pieces).hasSize(13);
assertThat(core.getCounter()).isEqualTo(3);
}
Aggregations