use of common.tree.AnalyzeTree 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.tree.AnalyzeTree in project solution-finder by knewjade.
the class CheckerNoHoldCountTest method runTestCase.
private AnalyzeTree runTestCase(PatternGenerator blocksGenerator, int maxClearLine, int maxDepth, String marks) {
Field field = FieldFactory.createField(marks);
// Initialize
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
PerfectValidator validator = new PerfectValidator();
CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
// Measure
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
AnalyzeTree tree = new AnalyzeTree();
blocksGenerator.blocksStream().forEach(blocks -> {
List<Piece> pieceList = blocks.getPieces();
boolean result = checker.check(field, pieceList, candidate, maxClearLine, maxDepth);
tree.set(result, pieceList);
});
return tree;
}
use of common.tree.AnalyzeTree in project solution-finder by knewjade.
the class CheckerNoHoldCountTest method testCase4.
@Test
void testCase4() throws Exception {
// Invoker
PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p7");
int maxClearLine = 4;
int maxDepth = 6;
// Field
String marks = "" + "XXXX______" + "XXXX______" + "XXXX______" + "XXXX______" + "";
AnalyzeTree tree = runTestCase(blocksGenerator, maxClearLine, maxDepth, marks);
// Source: myself 20170415
assertThat(tree.getSuccessPercent()).isEqualTo(1902 / 5040.0);
}
use of common.tree.AnalyzeTree in project solution-finder by knewjade.
the class CheckerNoHoldCountTest method testCase2.
@Test
void testCase2() throws Exception {
// Invoker
PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p4");
int maxClearLine = 5;
int maxDepth = 4;
// Field
String marks = "" + "____XXXXXX" + "____XXXXXX" + "___XXXXXXX" + "__XXXXXXXX" + "___XXXXXXX" + "";
AnalyzeTree tree = runTestCase(blocksGenerator, maxClearLine, maxDepth, marks);
// Source: reply in twitter from @fullfool_14
assertThat(tree.getSuccessPercent()).isEqualTo(477 / 2520.0);
}
use of common.tree.AnalyzeTree in project solution-finder by knewjade.
the class CheckerNoHoldCountTest method testCase3.
@Test
void testCase3() throws Exception {
// Invoker
PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p7");
int maxClearLine = 4;
int maxDepth = 6;
// Field
String marks = "" + "X_________" + "X___X_____" + "XXXXXXX___" + "XXXXXX____" + "";
AnalyzeTree tree = runTestCase(blocksGenerator, maxClearLine, maxDepth, marks);
// Source: reply in twitter from @fullfool_14
assertThat(tree.getSuccessPercent()).isEqualTo(727 / 5040.0);
}
Aggregations