use of core.mino.MinoShifter in project solution-finder by knewjade.
the class OnDemandBasicSolutionsTest method createSeparableMinos.
private static SeparableMinos createSeparableMinos(SizedBit sizedBit) {
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
return SeparableMinos.createSeparableMinos(minoFactory, minoShifter, sizedBit);
}
use of core.mino.MinoShifter in project solution-finder by knewjade.
the class LimitIterationCandidateTest method testSearch3When3Iteration.
@Test
void testSearch3When3Iteration() throws Exception {
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
Candidate<Action> candidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 3);
String marks = "" + "XXXX______" + "XX_XXXXX__" + "X___X_____" + "XX_X______";
Field field = FieldFactory.createField(marks);
Set<Action> actions = candidate.search(field, Piece.T, 4);
assertThat(actions).hasSize(9).contains(MinimalAction.create(8, 0, Rotate.Spawn)).contains(MinimalAction.create(7, 0, Rotate.Spawn)).contains(MinimalAction.create(8, 1, Rotate.Reverse)).contains(MinimalAction.create(7, 1, Rotate.Reverse)).contains(MinimalAction.create(6, 1, Rotate.Reverse)).contains(MinimalAction.create(8, 3, Rotate.Reverse)).contains(MinimalAction.create(9, 1, Rotate.Left)).contains(MinimalAction.create(8, 1, Rotate.Left)).contains(MinimalAction.create(8, 1, Rotate.Right));
}
use of core.mino.MinoShifter in project solution-finder by knewjade.
the class LimitIterationCandidateTest method testRandomLocked.
@Disabled
@Test
@LongTest
// TODO: mesure time, 移動回数をチェックしていないためテストに失敗することがある
void testRandomLocked() {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
LimitIterationCandidate limitIterationCandidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 12);
for (int count = 0; count < 10; count++) {
int randomHeight = randoms.nextIntClosed(10, 12);
int numOfMinos = randoms.nextIntClosed(4, randomHeight * 10 / 4 - 1);
Field field = randoms.field(randomHeight, numOfMinos);
int clearLine = field.clearLine();
int height = randomHeight - clearLine;
Piece piece = randoms.block();
String description = FieldView.toString(field, height) + piece;
Set<Action> actions1 = limitIterationCandidate.search(field, piece, height);
LockedCandidate lockedCandidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
Set<Action> actions2 = lockedCandidate.search(field, piece, height);
assertThat(actions2).as(description).isEqualTo(actions1);
}
}
use of core.mino.MinoShifter in project solution-finder by knewjade.
the class LockedNeighborCandidateTest method createLockedNeighborCandidate.
private LockedNeighborCandidate createLockedNeighborCandidate(Injector injector, int maxClearLine) {
MinoFactory minoFactory = injector.getInstance(MinoFactory.class);
MinoShifter minoShifter = injector.getInstance(MinoShifter.class);
MinoRotation minoRotation = injector.getInstance(MinoRotation.class);
OriginalPieceFactory pieceFactory = new OriginalPieceFactory(maxClearLine + 3);
return new LockedNeighborCandidate(minoFactory, minoShifter, minoRotation, pieceFactory);
}
use of core.mino.MinoShifter 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));
}
Aggregations