Search in sources :

Example 21 with Randoms

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);
    }
}
Also used : MinoRotation(core.srs.MinoRotation) Field(core.field.Field) Randoms(lib.Randoms) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 22 with Randoms

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();
                }
            });
        }
    }
}
Also used : MinimalAction(common.datastore.action.MinimalAction) Randoms(lib.Randoms) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Coordinates(lib.Coordinates) Rotate(core.srs.Rotate) Action(common.datastore.action.Action) Test(org.junit.jupiter.api.Test) Field(core.field.Field) core.mino(core.mino) FieldFactory(core.field.FieldFactory) MinoRotation(core.srs.MinoRotation) LockedReachable(core.action.reachable.LockedReachable) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) Rotate(core.srs.Rotate) MinoRotation(core.srs.MinoRotation) Field(core.field.Field) Randoms(lib.Randoms) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test)

Example 23 with Randoms

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

Example 24 with Randoms

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

Example 25 with Randoms

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

Aggregations

Randoms (lib.Randoms)108 Test (org.junit.jupiter.api.Test)103 Piece (core.mino.Piece)58 LongTest (module.LongTest)32 Field (core.field.Field)29 Action (common.datastore.action.Action)25 LongPieces (common.datastore.blocks.LongPieces)24 MinoFactory (core.mino.MinoFactory)20 ArrayList (java.util.ArrayList)19 LockedCandidate (core.action.candidate.LockedCandidate)17 Mino (core.mino.Mino)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 MinoShifter (core.mino.MinoShifter)14 MinoRotation (core.srs.MinoRotation)14 Rotate (core.srs.Rotate)13 Collectors (java.util.stream.Collectors)13 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)12 PatternGenerator (common.pattern.PatternGenerator)12 List (java.util.List)12 SeparableMino (searcher.pack.separable_mino.SeparableMino)12