use of module.BasicModule in project solution-finder by knewjade.
the class NeighborsTest method nextRightRotateDestinations.
@Test
void nextRightRotateDestinations() {
Injector injector = Guice.createInjector(new BasicModule(6));
Neighbors neighbors = createNeighbors(injector);
Neighbor neighbor = neighbors.get(Piece.T, Rotate.Spawn, 4, 3);
assertThat(neighbor.getNextRightRotateDestinations()).containsExactlyInAnyOrder(neighbors.get(Piece.T, Rotate.Right, 4, 3), neighbors.get(Piece.T, Rotate.Right, 3, 3), neighbors.get(Piece.T, Rotate.Right, 3, 4), neighbors.get(Piece.T, Rotate.Right, 4, 1), neighbors.get(Piece.T, Rotate.Right, 3, 1));
}
use of module.BasicModule in project solution-finder by knewjade.
the class NeighborsTest method nextMovesSources.
@Test
void nextMovesSources() {
Injector injector = Guice.createInjector(new BasicModule());
Neighbors neighbors = createNeighbors(injector);
Neighbor neighbor = neighbors.get(Piece.T, Rotate.Spawn, 4, 1);
assertThat(neighbor.getNextMovesSources()).containsExactlyInAnyOrder(neighbors.get(Piece.T, Rotate.Spawn, 3, 1), neighbors.get(Piece.T, Rotate.Spawn, 5, 1), neighbors.get(Piece.T, Rotate.Spawn, 4, 2));
}
use of module.BasicModule 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 module.BasicModule in project solution-finder by knewjade.
the class LockedNeighborCandidateTest method random.
@Test
void random() {
Injector injector = Guice.createInjector(new BasicModule());
int maxClearLine = 3;
LockedCandidate candidate1 = createLockedCandidate(injector, maxClearLine);
LockedNeighborCandidate candidate2 = createLockedNeighborCandidate(injector, maxClearLine);
MinoShifter minoShifter = injector.getInstance(MinoShifter.class);
Stopwatch stopwatch1 = Stopwatch.createStartedStopwatch();
Stopwatch stopwatch2 = Stopwatch.createStartedStopwatch();
Randoms randoms = new Randoms();
for (int count = 0; count < 10000; count++) {
Field field = randoms.field(maxClearLine, 7);
for (Piece piece : Piece.values()) {
// LockedCandidate
stopwatch1.start();
Set<Action> search1 = candidate1.search(field, piece, maxClearLine);
stopwatch1.stop();
// LockedNeighborCandidate
stopwatch2.start();
Set<Neighbor> neighbors = candidate2.search(field, piece, maxClearLine);
stopwatch2.stop();
Set<Action> search2 = neighbors.stream().map(Neighbor::getPiece).map(this::createMinimalAction).map(action -> minoShifter.createTransformedAction(piece, action)).collect(Collectors.toSet());
assertThat(search2).isEqualTo(search1);
}
}
System.out.println(stopwatch1.toMessage(TimeUnit.NANOSECONDS));
System.out.println(stopwatch2.toMessage(TimeUnit.NANOSECONDS));
}
use of module.BasicModule in project solution-finder by knewjade.
the class LockedNeighborCandidateTest method testField.
@ParameterizedTest
@ArgumentsSource(FieldTestCase.class)
void testField(Field field, Piece piece) {
Injector injector = Guice.createInjector(new BasicModule());
int maxClearLine = 4;
LockedCandidate candidate1 = createLockedCandidate(injector, maxClearLine);
LockedNeighborCandidate candidate2 = createLockedNeighborCandidate(injector, maxClearLine);
MinoShifter minoShifter = injector.getInstance(MinoShifter.class);
// LockedCandidate
Set<Action> search1 = candidate1.search(field, piece, maxClearLine);
// LockedNeighborCandidate
Set<Neighbor> neighbors = candidate2.search(field, piece, maxClearLine);
Set<Action> search2 = neighbors.stream().map(Neighbor::getPiece).map(this::createMinimalAction).map(action -> minoShifter.createTransformedAction(piece, action)).collect(Collectors.toSet());
assertThat(search2).isEqualTo(search1);
}
Aggregations