Search in sources :

Example 11 with MinoRotation

use of core.srs.MinoRotation 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 12 with MinoRotation

use of core.srs.MinoRotation 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 13 with MinoRotation

use of core.srs.MinoRotation 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 14 with MinoRotation

use of core.srs.MinoRotation 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 15 with MinoRotation

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

the class LockedCandidateTest method testSearch1.

@Test
void testSearch1() throws Exception {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, 4);
    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) Test(org.junit.jupiter.api.Test)

Aggregations

MinoRotation (core.srs.MinoRotation)44 MinoFactory (core.mino.MinoFactory)38 Field (core.field.Field)37 MinoShifter (core.mino.MinoShifter)37 Test (org.junit.jupiter.api.Test)32 LongTest (module.LongTest)29 Action (common.datastore.action.Action)25 Piece (core.mino.Piece)17 LockedReachable (core.action.reachable.LockedReachable)16 ColumnField (core.column_field.ColumnField)16 InOutPairField (searcher.pack.InOutPairField)16 Randoms (lib.Randoms)15 LockedCandidate (core.action.candidate.LockedCandidate)14 MinimalAction (common.datastore.action.MinimalAction)12 PermutationIterable (common.iterable.PermutationIterable)12 List (java.util.List)10 PerfectValidator (searcher.common.validator.PerfectValidator)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)8 FieldFactory (core.field.FieldFactory)8