use of core.mino.Mino in project solution-finder by knewjade.
the class OperationWithKeyComparatorTest method compareDiffX.
@Test
void compareDiffX() throws Exception {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
int x = randoms.nextInt(10);
int y = randoms.nextInt(20);
long deleteKey = 0L;
long usingKey = 1049600L;
OperationWithKey operationWithKey1 = new FullOperationWithKey(minoFactory.create(Piece.I, Rotate.Spawn), x, y, deleteKey, usingKey);
int newX = randoms.nextInt(10);
if (newX == x)
newX += 1;
Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, newX, y, deleteKey, usingKey);
// assert is not 0 & sign reversed
OperationWithKeyComparator comparator = new OperationWithKeyComparator();
assertThat(comparator.compare(operationWithKey1, operationWithKey2) * comparator.compare(operationWithKey2, operationWithKey1)).as(operationWithKey2.toString()).isLessThan(0);
}
use of core.mino.Mino in project solution-finder by knewjade.
the class SlideXOperationWithKeyTest method get.
@Test
void get() {
Randoms randoms = new Randoms();
for (int count = 0; count < 10000; count++) {
Piece piece = randoms.block();
Rotate rotate = randoms.rotate();
Mino mino = new Mino(piece, rotate);
int x = randoms.nextInt(0, 10);
int y = randoms.nextInt(0, 10);
long usingKey = randoms.key();
long deleteKey = randoms.key();
FullOperationWithKey operationWithKey = new FullOperationWithKey(mino, x, y, deleteKey, usingKey);
int slide = randoms.nextInt(4);
SlideXOperationWithKey key = new SlideXOperationWithKey(operationWithKey, slide);
assertThat(key).returns(x + slide, SlideXOperationWithKey::getX).returns(y, SlideXOperationWithKey::getY).returns(deleteKey, SlideXOperationWithKey::getNeedDeletedKey).returns(usingKey, SlideXOperationWithKey::getUsingKey);
}
}
use of core.mino.Mino in project solution-finder by knewjade.
the class LockedNeighborReachableTest method checks1.
@Test
void checks1() {
int maxClearLine = 4;
Injector injector = Guice.createInjector(new BasicModule(maxClearLine));
LockedNeighborReachable reachable = createLockedNeighborReachable(injector, maxClearLine);
Field field = FieldFactory.createField("" + "XXXX______" + "___X______" + "___X______" + "__________");
assertThat(reachable.checks(field, new Mino(Piece.T, Rotate.Spawn), 8, 0, maxClearLine)).isTrue();
assertThat(reachable.checks(field, new Mino(Piece.T, Rotate.Spawn), 1, 0, maxClearLine)).isFalse();
}
use of core.mino.Mino 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 core.mino.Mino 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);
}
Aggregations