Search in sources :

Example 51 with Rotate

use of core.srs.Rotate in project solution-finder by knewjade.

the class DeepdropCandidateTest method testRandom.

@Test
void testRandom() throws Exception {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new PassedMinoShifter();
    DeepdropCandidate candidate = new DeepdropCandidate(minoFactory, minoShifter);
    for (int count = 0; count < 10000; count++) {
        int height = randoms.nextIntClosed(2, 12);
        int numOfMinos = randoms.nextIntClosed(4, height * 10 / 4 - 1);
        Field field = randoms.field(height, numOfMinos);
        height -= field.clearLine();
        Piece piece = randoms.block();
        Set<Action> actions = candidate.search(field, piece, 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();
                } else {
                    // おけない
                    assertThat(field.canPut(mino, x, y) && field.isOnGround(mino, x, y)).isFalse();
                }
            });
        }
    }
}
Also used : Action(common.datastore.action.Action) MinimalAction(common.datastore.action.MinimalAction) Test(org.junit.jupiter.api.Test) Randoms(lib.Randoms) Field(core.field.Field) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) core.mino(core.mino) Set(java.util.Set) FieldFactory(core.field.FieldFactory) Coordinates(lib.Coordinates) Rotate(core.srs.Rotate) Action(common.datastore.action.Action) MinimalAction(common.datastore.action.MinimalAction) Rotate(core.srs.Rotate) Field(core.field.Field) Randoms(lib.Randoms) Test(org.junit.jupiter.api.Test)

Example 52 with Rotate

use of core.srs.Rotate in project solution-finder by knewjade.

the class LockedCacheTest method assertCache.

private void assertCache(int height) {
    LockedCache cache = new LockedCache(height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < 10; x++) {
            for (Rotate rotate : Rotate.values()) {
                assertThat(cache.isVisit(x, y, rotate)).isFalse();
                cache.visit(x, y, rotate);
                assertThat(cache.isVisit(x, y, rotate)).isTrue();
                assertThat(cache.isFound(x, y, rotate)).isFalse();
                cache.found(x, y, rotate);
                assertThat(cache.isFound(x, y, rotate)).isTrue();
            }
        }
    }
    cache.clear();
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < 10; x++) {
            for (Rotate rotate : Rotate.values()) {
                assertThat(cache.isVisit(x, y, rotate)).isFalse();
                assertThat(cache.isFound(x, y, rotate)).isFalse();
            }
        }
    }
}
Also used : Rotate(core.srs.Rotate)

Example 53 with Rotate

use of core.srs.Rotate in project solution-finder by knewjade.

the class PassedMinoShifterTest method enumerateSameOtherActions.

@Test
void enumerateSameOtherActions() {
    Randoms randoms = new Randoms();
    PassedMinoShifter minoShifter = new PassedMinoShifter();
    for (int count = 0; count < 10000; count++) {
        Piece piece = randoms.block();
        Rotate rotate = randoms.rotate();
        int x = randoms.nextInt(10);
        int y = randoms.nextInt(0, 12);
        List<Action> actions = minoShifter.enumerateSameOtherActions(piece, rotate, x, y);
        assertThat(actions).isEmpty();
    }
}
Also used : Randoms(lib.Randoms) Action(common.datastore.action.Action) MinimalAction(common.datastore.action.MinimalAction) Rotate(core.srs.Rotate) Test(org.junit.jupiter.api.Test)

Example 54 with Rotate

use of core.srs.Rotate in project solution-finder by knewjade.

the class PassedMinoShifterTest method createTransformedAction.

@Test
void createTransformedAction() {
    Randoms randoms = new Randoms();
    PassedMinoShifter minoShifter = new PassedMinoShifter();
    for (int count = 0; count < 10000; count++) {
        Piece piece = randoms.block();
        Rotate rotate = randoms.rotate();
        int x = randoms.nextInt(10);
        int y = randoms.nextInt(0, 12);
        MinimalAction action = MinimalAction.create(x, y, rotate);
        Action actualAction = minoShifter.createTransformedAction(piece, action);
        assertThat(actualAction).isEqualTo(action);
    }
}
Also used : Randoms(lib.Randoms) Action(common.datastore.action.Action) MinimalAction(common.datastore.action.MinimalAction) MinimalAction(common.datastore.action.MinimalAction) Rotate(core.srs.Rotate) Test(org.junit.jupiter.api.Test)

Example 55 with Rotate

use of core.srs.Rotate in project solution-finder by knewjade.

the class PassedMinoShifterTest method createTransformedRotate.

@Test
void createTransformedRotate() {
    Randoms randoms = new Randoms();
    PassedMinoShifter minoShifter = new PassedMinoShifter();
    for (int count = 0; count < 10000; count++) {
        Piece piece = randoms.block();
        Rotate rotate = randoms.rotate();
        Rotate actualRotate = minoShifter.createTransformedRotate(piece, rotate);
        assertThat(actualRotate).isEqualTo(rotate);
    }
}
Also used : Randoms(lib.Randoms) Rotate(core.srs.Rotate) Test(org.junit.jupiter.api.Test)

Aggregations

Rotate (core.srs.Rotate)55 Mino (core.mino.Mino)25 Piece (core.mino.Piece)25 Test (org.junit.jupiter.api.Test)14 Action (common.datastore.action.Action)13 ColorType (common.tetfu.common.ColorType)11 Randoms (lib.Randoms)11 HashSet (java.util.HashSet)10 ColoredField (common.tetfu.field.ColoredField)9 MinoFactory (core.mino.MinoFactory)9 List (java.util.List)9 MinimalAction (common.datastore.action.MinimalAction)7 TetfuPage (common.tetfu.TetfuPage)7 ColorConverter (common.tetfu.common.ColorConverter)7 Arrays (java.util.Arrays)7 Collectors (java.util.stream.Collectors)7 Field (core.field.Field)6 FinderParseException (exceptions.FinderParseException)6 SimpleOperation (common.datastore.SimpleOperation)5 ColoredFieldFactory (common.tetfu.field.ColoredFieldFactory)5