use of common.datastore.blocks.Pieces 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.Pieces in project solution-finder by knewjade.
the class CheckerNoHoldInvokerTest method random.
@LongTest
@ParameterizedTest
@ArgumentsSource(InvokerTestCase.class)
void random(IntFunction<ConcurrentCheckerInvoker> invokerGenerator) throws FinderExecuteException, SyntaxException {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
PerfectValidator validator = new PerfectValidator();
CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
for (int count = 0; count < 40; count++) {
int maxClearLine = randoms.nextInt(3, 6);
int maxDepth = randoms.nextIntClosed(3, 5);
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
Field field = randoms.field(maxClearLine, maxDepth);
PatternGenerator blocksGenerator = createPiecesGenerator(maxDepth);
List<Pieces> searchingPieces = blocksGenerator.blocksStream().collect(Collectors.toList());
ConcurrentCheckerInvoker invoker = invokerGenerator.apply(maxClearLine);
AnalyzeTree tree = runTestCase(invoker, field, searchingPieces, maxClearLine, maxDepth);
for (Pieces pieces : searchingPieces) {
boolean check = checker.check(field, pieces.getPieces(), candidate, maxClearLine, maxDepth);
assertThat(tree.isSucceed(pieces)).isEqualTo(check);
}
}
}
use of common.datastore.blocks.Pieces in project solution-finder by knewjade.
the class CheckerUsingHoldInvokerTest method runTestCase.
private AnalyzeTree runTestCase(ConcurrentCheckerInvoker invoker, String marks, PatternGenerator blocksGenerator, int maxClearLine, int maxDepth) throws FinderExecuteException {
List<Pieces> searchingPieces = blocksGenerator.blocksStream().collect(Collectors.toList());
Field field = FieldFactory.createField(marks);
List<Pair<Pieces, Boolean>> resultPairs = invoker.search(field, searchingPieces, maxClearLine, maxDepth);
// 結果を集計する
AnalyzeTree tree = new AnalyzeTree();
for (Pair<Pieces, Boolean> resultPair : resultPairs) {
Pieces pieces = resultPair.getKey();
Boolean result = resultPair.getValue();
tree.set(result, pieces);
}
System.out.println(tree.show());
return tree;
}
use of common.datastore.blocks.Pieces in project solution-finder by knewjade.
the class CheckerUsingHoldInvokerTest method random.
@LongTest
@ParameterizedTest
@ArgumentsSource(InvokerTestCase.class)
void random(IntFunction<ConcurrentCheckerInvoker> invokerGenerator) throws FinderExecuteException, SyntaxException {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
PerfectValidator validator = new PerfectValidator();
CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
for (int count = 0; count < 20; count++) {
int maxClearLine = randoms.nextInt(3, 6);
int maxDepth = randoms.nextIntClosed(3, 5);
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
Field field = randoms.field(maxClearLine, maxDepth);
PatternGenerator blocksGenerator = createPiecesGenerator(maxDepth);
List<Pieces> searchingPieces = blocksGenerator.blocksStream().collect(Collectors.toList());
Injector injector = Guice.createInjector(new BasicModule(maxClearLine));
ExecutorService executorService = injector.getInstance(ExecutorService.class);
ConcurrentCheckerInvoker invoker = invokerGenerator.apply(maxClearLine);
List<Pair<Pieces, Boolean>> resultPairs = invoker.search(field, searchingPieces, maxClearLine, maxDepth);
// 結果を集計する
AnalyzeTree tree1 = new AnalyzeTree();
for (Pair<Pieces, Boolean> resultPair : resultPairs) {
Pieces pieces1 = resultPair.getKey();
Boolean result = resultPair.getValue();
tree1.set(result, pieces1);
}
System.out.println(tree1.show());
executorService.shutdown();
AnalyzeTree tree = tree1;
for (Pieces pieces : searchingPieces) {
boolean check = checker.check(field, pieces.getPieces(), candidate, maxClearLine, maxDepth);
assertThat(tree.isSucceed(pieces)).isEqualTo(check);
}
}
}
use of common.datastore.blocks.Pieces in project solution-finder by knewjade.
the class ConcurrentCheckerNoHoldInvoker method search.
@Override
public List<Pair<Pieces, Boolean>> search(Field field, List<Pieces> searchingPieces, int maxClearLine, int maxDepth) throws FinderExecuteException {
ConcurrentVisitedTree visitedTree = new ConcurrentVisitedTree();
Obj obj = new Obj(field, maxClearLine, maxDepth, visitedTree);
ArrayList<Task> tasks = new ArrayList<>();
for (Pieces target : searchingPieces) tasks.add(new Task(obj, commonObj, target));
try {
return execute(tasks);
} catch (InterruptedException | ExecutionException e) {
throw new FinderExecuteException(e);
}
}
Aggregations