Search in sources :

Example 6 with Mino

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);
}
Also used : Randoms(lib.Randoms) OperationWithKey(common.datastore.OperationWithKey) FullOperationWithKey(common.datastore.FullOperationWithKey) Mino(core.mino.Mino) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Example 7 with Mino

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);
    }
}
Also used : Randoms(lib.Randoms) Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Example 8 with Mino

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();
}
Also used : Field(core.field.Field) Injector(com.google.inject.Injector) BasicModule(module.BasicModule) Mino(core.mino.Mino) Test(org.junit.jupiter.api.Test)

Example 9 with Mino

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);
}
Also used : Randoms(lib.Randoms) ArrayList(java.util.ArrayList) Mino(core.mino.Mino) Test(org.junit.jupiter.api.Test)

Example 10 with Mino

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);
}
Also used : Randoms(lib.Randoms) ArrayList(java.util.ArrayList) Mino(core.mino.Mino) Test(org.junit.jupiter.api.Test)

Aggregations

Mino (core.mino.Mino)103 Test (org.junit.jupiter.api.Test)46 Rotate (core.srs.Rotate)27 Field (core.field.Field)24 Piece (core.mino.Piece)20 Randoms (lib.Randoms)16 MinoFactory (core.mino.MinoFactory)14 ColorType (common.tetfu.common.ColorType)12 ColoredField (common.tetfu.field.ColoredField)12 ArrayList (java.util.ArrayList)12 FullOperationWithKey (common.datastore.FullOperationWithKey)9 HashSet (java.util.HashSet)9 ColorConverter (common.tetfu.common.ColorConverter)8 OriginalPiece (core.neighbor.OriginalPiece)8 List (java.util.List)8 MinoOperationWithKey (common.datastore.MinoOperationWithKey)7 OperationWithKey (common.datastore.OperationWithKey)7 TetfuPage (common.tetfu.TetfuPage)7 Arrays (java.util.Arrays)7 Collectors (java.util.stream.Collectors)7