use of searcher.checker.CheckerUsingHold in project solution-finder by knewjade.
the class BuildUpTest method cansBuildRandomShortByCheck.
@Test
void cansBuildRandomShortByCheck() {
Randoms randoms = new Randoms();
// Create field
int height = 4;
// Initialize
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
PerfectValidator validator = new PerfectValidator();
CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
AtomicInteger counter = new AtomicInteger();
for (int count = 0; count < 10000; count++) {
// Pickup solution from checker
int numOfMinos = randoms.nextInt(1, 7);
Field field = randoms.field(height, numOfMinos);
List<Piece> pieces = randoms.blocks(numOfMinos);
boolean check = checker.check(field, pieces, candidate, height, numOfMinos);
if (check) {
counter.incrementAndGet();
Stream<Operation> operationStream = ResultHelper.createOperationStream(checker.getResult());
Operations operations = new Operations(operationStream);
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
assertThat(BuildUp.cansBuild(field, operationWithKeys, height, reachable)).as(FieldView.toString(field) + pieces).isTrue();
}
}
System.out.println(counter);
}
use of searcher.checker.CheckerUsingHold 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 searcher.checker.CheckerUsingHold in project solution-finder by knewjade.
the class CheckerUsingHoldThreadLocal method initialValue.
@Override
protected Checker<T> initialValue() {
MinoFactory minoFactory = new MinoFactory();
PerfectValidator validator = new PerfectValidator();
return new CheckerUsingHold<>(minoFactory, validator);
}
use of searcher.checker.CheckerUsingHold in project solution-finder by knewjade.
the class BuildUpTest method cansBuildRandomLongByCheck.
@Test
@LongTest
void cansBuildRandomLongByCheck() {
Randoms randoms = new Randoms();
// Create field
int height = 4;
// Initialize
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
PerfectValidator validator = new PerfectValidator();
CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
AtomicInteger counter = new AtomicInteger();
for (int count = 0; count < 100; count++) {
// Pickup solution from checker
int numOfMinos = randoms.nextIntClosed(7, 10);
Field field = randoms.field(height, numOfMinos);
List<Piece> pieces = randoms.blocks(numOfMinos);
boolean check = checker.check(field, pieces, candidate, height, numOfMinos);
if (check) {
counter.incrementAndGet();
Stream<Operation> operationStream = ResultHelper.createOperationStream(checker.getResult());
Operations operations = new Operations(operationStream);
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
assertThat(BuildUp.cansBuild(field, operationWithKeys, height, reachable)).as(FieldView.toString(field) + pieces).isTrue();
}
}
System.out.println(counter);
}
Aggregations