use of core.neighbor.Neighbor in project solution-finder by knewjade.
the class LockedNeighborCandidate method loop.
private void loop(HashSet<Neighbor> results, Neighbor neighbor) {
cache.resetTrail();
if (check(neighbor)) {
results.add(neighbor);
} else {
OriginalPiece piece = neighbor.getPiece();
Mino mino = piece.getMino();
Piece block = mino.getPiece();
List<Action> actions = minoShifter.enumerateSameOtherActions(block, mino.getRotate(), piece.getX(), piece.getY());
for (Action action : actions) {
Neighbor similar = neighbors.get(block, action.getRotate(), action.getX(), action.getY());
if (check(similar))
results.add(similar);
}
}
}
use of core.neighbor.Neighbor in project solution-finder by knewjade.
the class LockedNeighborCandidate method checkLeftRotation.
private boolean checkLeftRotation(Neighbor current) {
List<Neighbor> nextLeftRotateSources = current.getNextLeftRotateSources();
for (Neighbor source : nextLeftRotateSources) {
if (!field.canPut(source.getPiece()))
continue;
// もう一度回して戻ってくるか
List<Neighbor> destinations = source.getNextLeftRotateDestinations();
Neighbor destination = getDestination(destinations);
if (current.equals(destination) && check(source)) {
cache.found(current);
return true;
}
}
return false;
}
use of core.neighbor.Neighbor in project solution-finder by knewjade.
the class LockedNeighborCandidate method checkRightRotation.
private boolean checkRightRotation(Neighbor current) {
List<Neighbor> nextRightRotateSources = current.getNextRightRotateSources();
for (Neighbor source : nextRightRotateSources) {
if (!field.canPut(source.getPiece()))
continue;
// もう一度回して戻ってくるか
List<Neighbor> destinations = source.getNextRightRotateDestinations();
Neighbor destination = getDestination(destinations);
if (current.equals(destination) && check(source)) {
cache.found(current);
return true;
}
}
return false;
}
use of core.neighbor.Neighbor in project solution-finder by knewjade.
the class LockedNeighborReachable method checkRightRotation.
private boolean checkRightRotation(Neighbor current) {
List<Neighbor> sources = current.getNextRightRotateSources();
for (Neighbor source : sources) {
if (!field.canPut(source.getPiece()))
continue;
// もう一度回して戻ってくるか
List<Neighbor> destinations = source.getNextRightRotateDestinations();
Neighbor destination = getDestination(destinations);
if (current.equals(destination) && check(source)) {
return true;
}
}
return false;
}
use of core.neighbor.Neighbor 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