use of common.pattern.LoadedPatternGenerator 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.pattern.LoadedPatternGenerator 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.pattern.LoadedPatternGenerator 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);
}
use of common.pattern.LoadedPatternGenerator in project solution-finder by knewjade.
the class CheckerUsingHoldCountTest method testTemplateWithHoldI.
@Test
void testTemplateWithHoldI() throws Exception {
// Invoker
String pattern = "I, *p4";
int maxClearLine = 4;
int maxDepth = 4;
// Field
String marks = "" + "XXXXX_____" + "XXXXXX____" + "XXXXXXX___" + "XXXXXX____" + "";
Field field = FieldFactory.createField(marks);
// Initialize
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
PerfectValidator validator = new PerfectValidator();
CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
// Measure
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
AnalyzeTree tree = new AnalyzeTree();
PatternGenerator generator = new LoadedPatternGenerator(pattern);
generator.blocksStream().forEach(blocks -> {
List<Piece> pieceList = blocks.getPieces();
boolean result = checker.check(field, pieceList, candidate, maxClearLine, maxDepth);
tree.set(result, pieceList);
});
// Source: Nilgiri: https://docs.google.com/spreadsheets/d/1bVY3t_X96xRmUL0qdgB9tViSIGenu6RMKX4RW7qWg8Y/edit#gid=0
assertThat(tree.getSuccessPercent()).isEqualTo(711 / 840.0);
}
use of common.pattern.LoadedPatternGenerator in project solution-finder by knewjade.
the class AnalyzeTreeTest method randomLong.
@Test
@LongTest
void randomLong() throws SyntaxException {
Randoms randoms = new Randoms();
for (int size = 8; size <= 11; size++) {
PatternGenerator generator = new LoadedPatternGenerator("*p7, *p" + (size - 7));
AnalyzeTree tree = new AnalyzeTree();
HashSet<LongPieces> success = new HashSet<>();
HashSet<LongPieces> failed = new HashSet<>();
generator.blocksStream().forEach(blocks -> {
boolean flag = randoms.nextBoolean();
List<Piece> pieceList = blocks.getPieces();
tree.set(flag, pieceList);
LongPieces longPieces = new LongPieces(pieceList);
if (flag) {
success.add(longPieces);
} else {
failed.add(longPieces);
}
});
boolean isSucceed = success.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isVisited(blocks) && tree.isSucceed(blocks);
});
assertThat(isSucceed).isTrue();
boolean isFailed = failed.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isVisited(blocks) && !tree.isSucceed(blocks);
});
assertThat(isFailed).isTrue();
double percent = (double) success.size() / (success.size() + failed.size());
assertThat(tree.getSuccessPercent()).isCloseTo(percent, offset(0.0001));
}
}
Aggregations