use of lib.Randoms in project solution-finder by knewjade.
the class LimitIterationCandidateTest method testRandomHarddrop.
@Test
void testRandomHarddrop() {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
HarddropCandidate harddropCandidate = new HarddropCandidate(minoFactory, minoShifter);
LimitIterationCandidate limitIterationCandidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 0);
for (int count = 0; count < 10000; count++) {
int randomHeight = randoms.nextIntClosed(2, 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();
Set<Action> actions1 = harddropCandidate.search(field, piece, height);
Set<Action> actions2 = limitIterationCandidate.search(field, piece, height);
assertThat(actions2).isEqualTo(actions1);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class LockedCandidateTest method testRandom.
@Test
void testRandom() throws Exception {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new PassedMinoShifter();
MinoRotation minoRotation = new MinoRotation();
for (int count = 0; count < 10000; count++) {
int randomHeight = randoms.nextIntClosed(2, 12);
int numOfMinos = randoms.nextIntClosed(4, randomHeight * 10 / 4 - 1);
Field field = randoms.field(randomHeight, numOfMinos);
int height = randomHeight - field.clearLine();
Piece piece = randoms.block();
LockedCandidate candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
Set<Action> actions = candidate.search(field, piece, height);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
for (Rotate rotate : Rotate.values()) {
Coordinates.walk(minoFactory.create(piece, rotate), height).map(coordinate -> MinimalAction.create(coordinate.x, coordinate.y, rotate)).forEach(action -> {
int x = action.getX();
int y = action.getY();
Mino mino = minoFactory.create(piece, action.getRotate());
if (actions.contains(action)) {
// おける
assertThat(field.canPut(mino, x, y)).isTrue();
assertThat(field.isOnGround(mino, x, y)).isTrue();
assertThat(reachable.checks(field, mino, x, y, height)).isTrue();
} else {
// おけない
boolean canPut = field.canPut(mino, x, y) && field.isOnGround(mino, x, y) && reachable.checks(field, mino, x, y, height);
assertThat(canPut).isFalse();
}
});
}
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class NeighborTest method getNextLeftRotateDestinations.
@Test
void getNextLeftRotateDestinations() {
OriginalPiece piece = new OriginalPiece(new Mino(Piece.T, Rotate.Spawn), 1, 0, 4);
Neighbor neighbor = new Neighbor(piece);
OriginalPieceFactory factory = new OriginalPieceFactory(4);
List<OriginalPiece> pieces = new ArrayList<>(factory.create());
Randoms randoms = new Randoms();
List<Neighbor> samples = randoms.sample(pieces, 4).stream().map(Neighbor::new).collect(Collectors.toList());
neighbor.updateLeftRotateDestination(samples);
assertThat(neighbor.getNextLeftRotateDestinations()).containsAll(samples);
}
use of lib.Randoms in project solution-finder by knewjade.
the class NeighborTest method getNextMovesSources.
@Test
void getNextMovesSources() {
OriginalPiece piece = new OriginalPiece(new Mino(Piece.T, Rotate.Spawn), 1, 0, 4);
Neighbor neighbor = new Neighbor(piece);
OriginalPieceFactory factory = new OriginalPieceFactory(4);
List<OriginalPiece> pieces = new ArrayList<>(factory.create());
Randoms randoms = new Randoms();
ArrayList<Neighbor> all = new ArrayList<>();
// left
for (OriginalPiece sample : randoms.sample(pieces, 3)) {
Neighbor nei = new Neighbor(sample);
if (!all.contains(nei)) {
neighbor.updateLeft(nei);
all.add(nei);
}
}
// right
for (OriginalPiece sample : randoms.sample(pieces, 3)) {
Neighbor nei = new Neighbor(sample);
if (!all.contains(nei)) {
neighbor.updateRight(nei);
all.add(nei);
}
}
// up
for (OriginalPiece sample : randoms.sample(pieces, 3)) {
Neighbor nei = new Neighbor(sample);
if (!all.contains(nei)) {
neighbor.updateUp(nei);
all.add(nei);
}
}
assertThat(neighbor.getNextMovesSources()).containsAll(all);
}
use of lib.Randoms in project solution-finder by knewjade.
the class NeighborTest method getNextLeftRotateSources.
@Test
void getNextLeftRotateSources() {
OriginalPiece piece = new OriginalPiece(new Mino(Piece.T, Rotate.Spawn), 1, 0, 4);
Neighbor neighbor = new Neighbor(piece);
OriginalPieceFactory factory = new OriginalPieceFactory(4);
List<OriginalPiece> pieces = new ArrayList<>(factory.create());
Randoms randoms = new Randoms();
List<Neighbor> samples = randoms.sample(pieces, 4).stream().map(Neighbor::new).collect(Collectors.toList());
neighbor.updateLeftRotateSource(samples);
assertThat(neighbor.getNextLeftRotateSources()).containsAll(samples);
}
Aggregations