Search in sources :

Example 76 with MinoFactory

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

the class OperationWithKeyComparatorTest method compareDiffUsingKey.

@Test
void compareDiffUsingKey() 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);
    Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
    Long choose = randoms.key();
    OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, deleteKey, choose);
    // assert is 0
    OperationWithKeyComparator<OperationWithKey> comparator = new OperationWithKeyComparator<>();
    int compare1 = comparator.compare(operationWithKey1, operationWithKey2);
    assertThat(compare1).as(operationWithKey1.toString()).isEqualTo(0);
    int compare2 = comparator.compare(operationWithKey2, operationWithKey1);
    assertThat(compare2).as(operationWithKey2.toString()).isEqualTo(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 77 with MinoFactory

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

the class OperationWithKeyComparatorTest method compareDiffY.

@Test
void compareDiffY() 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 newY = randoms.nextInt(20);
    if (newY == y)
        newY += 1;
    Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
    OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, newY, 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 78 with MinoFactory

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

the class CheckerNoHoldCountTest method runTestCase.

private AnalyzeTree runTestCase(PatternGenerator blocksGenerator, int maxClearLine, int maxDepth, String marks) {
    Field field = FieldFactory.createField(marks);
    // Initialize
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    PerfectValidator validator = new PerfectValidator();
    CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
    // Measure
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    AnalyzeTree tree = new AnalyzeTree();
    blocksGenerator.blocksStream().forEach(blocks -> {
        List<Piece> pieceList = blocks.getPieces();
        boolean result = checker.check(field, pieceList, candidate, maxClearLine, maxDepth);
        tree.set(result, pieceList);
    });
    return tree;
}
Also used : Action(common.datastore.action.Action) AnalyzeTree(common.tree.AnalyzeTree) Field(core.field.Field) MinoRotation(core.srs.MinoRotation) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) PerfectValidator(searcher.common.validator.PerfectValidator)

Example 79 with MinoFactory

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

the class CheckerUsingHoldCountTest method testTemplate.

@Test
void testTemplate() throws Exception {
    // Invoker
    List<Piece> pieces = Arrays.asList(I, T, S, Z, J, L, O);
    int popCount = 4;
    int maxClearLine = 4;
    int maxDepth = 3;
    // Field
    String marks = "" + "XXXXX____X" + "XXXXXX___X" + "XXXXXXX__X" + "XXXXXX___X" + "";
    Field field = FieldFactory.createField(marks);
    // Initialize
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    PerfectValidator validator = new PerfectValidator();
    CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
    // Measure
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    AnalyzeTree tree = new AnalyzeTree();
    Iterable<List<Piece>> combinations = new PermutationIterable<>(pieces, popCount);
    for (List<Piece> combination : combinations) {
        boolean result = checker.check(field, combination, candidate, maxClearLine, maxDepth);
        tree.set(result, combination);
    }
    // Source: Nilgiri: https://docs.google.com/spreadsheets/d/1bVY3t_X96xRmUL0qdgB9tViSIGenu6RMKX4RW7qWg8Y/edit#gid=0
    assertThat(tree.getSuccessPercent()).isEqualTo(514 / 840.0);
}
Also used : Action(common.datastore.action.Action) PermutationIterable(common.iterable.PermutationIterable) AnalyzeTree(common.tree.AnalyzeTree) Field(core.field.Field) MinoRotation(core.srs.MinoRotation) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) List(java.util.List) PerfectValidator(searcher.common.validator.PerfectValidator) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 80 with MinoFactory

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

the class CheckerUsingHoldCountTest method testBT4_5.

@Test
@LongTest
void testBT4_5() throws Exception {
    // Invoker
    List<Piece> pieces = Arrays.asList(I, T, S, Z, J, L, O);
    int popCount = 7;
    int maxClearLine = 6;
    int maxDepth = 7;
    // Field
    String marks = "" + "XX________" + "XX________" + "XXX______X" + "XXXXXXX__X" + "XXXXXX___X" + "XXXXXXX_XX" + "";
    Field field = FieldFactory.createField(marks);
    // Initialize
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    PerfectValidator validator = new PerfectValidator();
    CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
    // Measure
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    AnalyzeTree tree = new AnalyzeTree();
    Iterable<List<Piece>> combinations = new PermutationIterable<>(pieces, popCount);
    for (List<Piece> combination : combinations) {
        boolean result = checker.check(field, combination, candidate, maxClearLine, maxDepth);
        tree.set(result, combination);
    }
    // Source: myself 20170415
    assertThat(tree.getSuccessPercent()).isEqualTo(5038 / 5040.0);
}
Also used : Action(common.datastore.action.Action) PermutationIterable(common.iterable.PermutationIterable) AnalyzeTree(common.tree.AnalyzeTree) Field(core.field.Field) MinoRotation(core.srs.MinoRotation) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) List(java.util.List) PerfectValidator(searcher.common.validator.PerfectValidator) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

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