Search in sources :

Example 26 with MinoFactory

use of core.mino.MinoFactory in project solution-finder by knewjade.

the class LimitIterationCandidateTest method testSearch3When4Iteration.

@Test
void testSearch3When4Iteration() throws Exception {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    Candidate<Action> candidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 4);
    String marks = "" + "XXXX______" + "XX_XXXXX__" + "X___X_____" + "XX_X______";
    Field field = FieldFactory.createField(marks);
    Set<Action> actions = candidate.search(field, Piece.T, 4);
    assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Spawn)).hasSize(3).contains(MinimalAction.create(8, 0, Rotate.Spawn)).contains(MinimalAction.create(7, 0, Rotate.Spawn)).contains(MinimalAction.create(6, 0, Rotate.Spawn)).doesNotContain(MinimalAction.create(5, 0, Rotate.Spawn));
}
Also used : MinoRotation(core.srs.MinoRotation) Field(core.field.Field) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 27 with MinoFactory

use of core.mino.MinoFactory in project solution-finder by knewjade.

the class LimitIterationCandidateTest method testSearch1.

@Test
void testSearch1() throws Exception {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    Candidate<Action> candidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 3);
    String marks = "" + "__________" + "__________" + "____X_____";
    Field field = FieldFactory.createField(marks);
    Set<Action> actions = candidate.search(field, Piece.T, 4);
    assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Spawn)).hasSize(8);
    assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Right)).hasSize(9);
    assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Reverse)).hasSize(8);
    assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Left)).hasSize(9);
}
Also used : MinoRotation(core.srs.MinoRotation) Field(core.field.Field) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 28 with MinoFactory

use of core.mino.MinoFactory in project solution-finder by knewjade.

the class LimitIterationCandidateTest method testSearch4.

@Test
void testSearch4() throws Exception {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    Candidate<Action> candidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 4);
    String marks = "" + "XXXXX__XXX" + "XXXXX___XX" + "XXXX___XXX" + "";
    Field field = FieldFactory.createField(marks);
    Set<Action> actions = candidate.search(field, Piece.T, 3);
    assertThat(actions).hasSize(5).contains(MinimalAction.create(6, 1, Rotate.Spawn)).contains(MinimalAction.create(5, 1, Rotate.Right)).contains(MinimalAction.create(6, 1, Rotate.Right)).contains(MinimalAction.create(6, 1, Rotate.Left)).contains(MinimalAction.create(6, 1, Rotate.Reverse));
}
Also used : MinoRotation(core.srs.MinoRotation) Field(core.field.Field) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 29 with MinoFactory

use of core.mino.MinoFactory 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 30 with MinoFactory

use of core.mino.MinoFactory in project solution-finder by knewjade.

the class CoordinatesTest method walkSizeWithI.

@Test
void walkSizeWithI() {
    MinoFactory minoFactory = new MinoFactory();
    assertThat(Coordinates.walk(minoFactory.create(Piece.I, Rotate.Spawn), 4)).hasSize(28);
    assertThat(Coordinates.walk(minoFactory.create(Piece.I, Rotate.Left), 4)).hasSize(10);
    assertThat(Coordinates.walk(minoFactory.create(Piece.I, Rotate.Reverse), 4)).hasSize(28);
    assertThat(Coordinates.walk(minoFactory.create(Piece.I, Rotate.Right), 4)).hasSize(10);
}
Also used : MinoFactory(core.mino.MinoFactory) Test(org.junit.jupiter.api.Test)

Aggregations

MinoFactory (core.mino.MinoFactory)113 Test (org.junit.jupiter.api.Test)70 MinoShifter (core.mino.MinoShifter)59 LongTest (module.LongTest)51 Field (core.field.Field)45 MinoRotation (core.srs.MinoRotation)40 ColorConverter (common.tetfu.common.ColorConverter)33 Piece (core.mino.Piece)28 Action (common.datastore.action.Action)22 ColumnField (core.column_field.ColumnField)22 Randoms (lib.Randoms)22 InOutPairField (searcher.pack.InOutPairField)21 LockedReachable (core.action.reachable.LockedReachable)17 PerfectValidator (searcher.common.validator.PerfectValidator)17 LockedCandidate (core.action.candidate.LockedCandidate)16 MinoOperationWithKey (common.datastore.MinoOperationWithKey)15 List (java.util.List)15 Collectors (java.util.stream.Collectors)15 PermutationIterable (common.iterable.PermutationIterable)12 LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)12