Search in sources :

Example 36 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class AnalyzeTreeTest method randomLong.

@Test
@LongTest
void randomLong() throws SyntaxException {
    Randoms randoms = new Randoms();
    for (int size = 8; size <= 11; size++) {
        PatternGenerator generator = new LoadedPatternGenerator("*p7, *p" + (size - 7));
        AnalyzeTree tree = new AnalyzeTree();
        HashSet<LongPieces> success = new HashSet<>();
        HashSet<LongPieces> failed = new HashSet<>();
        generator.blocksStream().forEach(blocks -> {
            boolean flag = randoms.nextBoolean();
            List<Piece> pieceList = blocks.getPieces();
            tree.set(flag, pieceList);
            LongPieces longPieces = new LongPieces(pieceList);
            if (flag) {
                success.add(longPieces);
            } else {
                failed.add(longPieces);
            }
        });
        boolean isSucceed = success.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isVisited(blocks) && tree.isSucceed(blocks);
        });
        assertThat(isSucceed).isTrue();
        boolean isFailed = failed.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isVisited(blocks) && !tree.isSucceed(blocks);
        });
        assertThat(isFailed).isTrue();
        double percent = (double) success.size() / (success.size() + failed.size());
        assertThat(tree.getSuccessPercent()).isCloseTo(percent, offset(0.0001));
    }
}
Also used : Randoms(lib.Randoms) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 37 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class AnalyzeTreeTest method random.

@Test
void random() throws SyntaxException {
    Randoms randoms = new Randoms();
    for (int size = 1; size <= 7; size++) {
        PatternGenerator generator = new LoadedPatternGenerator("*p" + size);
        AnalyzeTree tree = new AnalyzeTree();
        HashSet<LongPieces> success = new HashSet<>();
        HashSet<LongPieces> failed = new HashSet<>();
        generator.blocksStream().forEach(blocks -> {
            boolean flag = randoms.nextBoolean();
            List<Piece> pieceList = blocks.getPieces();
            tree.set(flag, pieceList);
            LongPieces longPieces = new LongPieces(pieceList);
            if (flag) {
                success.add(longPieces);
            } else {
                failed.add(longPieces);
            }
        });
        boolean isSucceed = success.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isVisited(blocks) && tree.isSucceed(blocks);
        });
        assertThat(isSucceed).isTrue();
        boolean isFailed = failed.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isVisited(blocks) && !tree.isSucceed(blocks);
        });
        assertThat(isFailed).isTrue();
        double percent = (double) success.size() / (success.size() + failed.size());
        assertThat(tree.getSuccessPercent()).isCloseTo(percent, offset(0.0001));
    }
}
Also used : Randoms(lib.Randoms) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 38 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class ConcurrentVisitedTreeTest method randomLong.

@Test
@LongTest
void randomLong() throws SyntaxException {
    Randoms randoms = new Randoms();
    for (int size = 8; size <= 11; size++) {
        PatternGenerator generator = new LoadedPatternGenerator("*p7, *p" + (size - 7));
        ConcurrentVisitedTree tree = new ConcurrentVisitedTree();
        Set<LongPieces> success = Collections.synchronizedSet(new HashSet<>());
        Set<LongPieces> failed = Collections.synchronizedSet(new HashSet<>());
        List<Pieces> piecesList = generator.blocksStream().collect(Collectors.toList());
        piecesList.parallelStream().forEach(pieces -> {
            boolean flag = randoms.nextBoolean();
            List<Piece> blocks = pieces.getPieces();
            tree.set(flag, blocks);
            LongPieces longPieces = new LongPieces(blocks);
            if (flag) {
                success.add(longPieces);
            } else {
                failed.add(longPieces);
            }
        });
        boolean isSucceed = success.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
        });
        assertThat(isSucceed).isTrue();
        boolean isFailed = failed.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
        });
        assertThat(isFailed).isTrue();
    }
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) Randoms(lib.Randoms) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) Pieces(common.datastore.blocks.Pieces) LongPieces(common.datastore.blocks.LongPieces) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 39 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class ConcurrentVisitedTreeTest method random.

@Test
void random() throws SyntaxException {
    Randoms randoms = new Randoms();
    for (int size = 1; size <= 7; size++) {
        PatternGenerator generator = new LoadedPatternGenerator("*p" + size);
        ConcurrentVisitedTree tree = new ConcurrentVisitedTree();
        Set<LongPieces> success = Collections.synchronizedSet(new HashSet<>());
        Set<LongPieces> failed = Collections.synchronizedSet(new HashSet<>());
        List<Pieces> piecesList = generator.blocksStream().collect(Collectors.toList());
        piecesList.parallelStream().forEach(pieces -> {
            boolean flag = randoms.nextBoolean();
            List<Piece> blocks = pieces.getPieces();
            tree.set(flag, blocks);
            LongPieces longPieces = new LongPieces(blocks);
            if (flag) {
                success.add(longPieces);
            } else {
                failed.add(longPieces);
            }
        });
        boolean isSucceed = success.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
        });
        assertThat(isSucceed).isTrue();
        boolean isFailed = failed.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
        });
        assertThat(isFailed).isTrue();
    }
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) Randoms(lib.Randoms) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) Pieces(common.datastore.blocks.Pieces) LongPieces(common.datastore.blocks.LongPieces) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 40 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class VisitedTreeTest method random.

@Test
void random() throws SyntaxException {
    Randoms randoms = new Randoms();
    for (int size = 1; size <= 7; size++) {
        PatternGenerator generator = new LoadedPatternGenerator("*p" + size);
        VisitedTree tree = new VisitedTree();
        HashSet<LongPieces> success = new HashSet<>();
        HashSet<LongPieces> failed = new HashSet<>();
        generator.blocksStream().forEach(pieces -> {
            boolean flag = randoms.nextBoolean();
            List<Piece> blocks = pieces.getPieces();
            tree.set(flag, blocks);
            LongPieces longPieces = new LongPieces(blocks);
            if (flag) {
                success.add(longPieces);
            } else {
                failed.add(longPieces);
            }
        });
        boolean isSucceed = success.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
        });
        assertThat(isSucceed).isTrue();
        boolean isFailed = failed.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
        });
        assertThat(isFailed).isTrue();
    }
}
Also used : Randoms(lib.Randoms) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Aggregations

PatternGenerator (common.pattern.PatternGenerator)71 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)67 Test (org.junit.jupiter.api.Test)35 LongPieces (common.datastore.blocks.LongPieces)34 AnalyzeTree (common.tree.AnalyzeTree)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)27 Piece (core.mino.Piece)13 Randoms (lib.Randoms)12 Field (core.field.Field)10 Pieces (common.datastore.blocks.Pieces)9 MinoFactory (core.mino.MinoFactory)9 LongTest (module.LongTest)9 Action (common.datastore.action.Action)6 LockedCandidate (core.action.candidate.LockedCandidate)6 MinoShifter (core.mino.MinoShifter)6 HashSet (java.util.HashSet)6 PerfectValidator (searcher.common.validator.PerfectValidator)6 EntryPoint (entry.EntryPoint)5 ColorConverter (common.tetfu.common.ColorConverter)4