Search in sources :

Example 31 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class OrderLookupTest method reverseOverBlocksRandom.

@Test
void reverseOverBlocksRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 1; size <= 13; size++) {
        List<Piece> pieceList = randoms.blocks(size);
        int fromDepth = pieceList.size() + 1;
        Comparator<List<Piece>> comparator = new ListComparator<>(Comparator.nullsFirst(Comparator.comparingInt(Piece::getNumber)));
        List<List<Piece>> forward1 = OrderLookup.reverseBlocks(pieceList, fromDepth).stream().map(StackOrder::toList).sorted(comparator).collect(Collectors.toList());
        ReverseOrderLookUp lookUp = new ReverseOrderLookUp(pieceList.size(), fromDepth);
        List<List<Piece>> forward2 = lookUp.parse(pieceList).map(blockStream -> blockStream.collect(Collectors.toList())).sorted(comparator).collect(Collectors.toList());
        assertThat(forward2).isEqualTo(forward1);
    }
}
Also used : Randoms(lib.Randoms) Piece(core.mino.Piece) ListComparator(lib.ListComparator) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 32 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class OperationInterpreterTest method parseRandom.

@Test
void parseRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 1; size < 20; size++) {
        List<Operation> operationList = Stream.generate(() -> {
            Piece piece = randoms.block();
            Rotate rotate = randoms.rotate();
            int x = randoms.nextInt(10);
            int y = randoms.nextInt(4);
            return new SimpleOperation(piece, rotate, x, y);
        }).limit(size).collect(Collectors.toList());
        Operations operations = new Operations(operationList);
        String str = OperationInterpreter.parseToString(operations);
        Operations actual = OperationInterpreter.parseToOperations(str);
        assertThat(actual).isEqualTo(operations);
    }
}
Also used : Randoms(lib.Randoms) Rotate(core.srs.Rotate) Piece(core.mino.Piece) SimpleOperation(common.datastore.SimpleOperation) SimpleOperation(common.datastore.SimpleOperation) Operation(common.datastore.Operation) Operations(common.datastore.Operations) Test(org.junit.jupiter.api.Test)

Example 33 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class PieceInterpreterTest method parseRandom.

@Test
void parseRandom() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 10000; count++) {
        int size = randoms.nextInt(1, 100);
        List<Piece> pieces = randoms.blocks(size);
        String name = pieces.stream().map(Piece::getName).collect(Collectors.joining());
        Stream<Piece> stream = BlockInterpreter.parse(name);
        assertThat(stream).containsExactlyElementsOf(pieces);
    }
}
Also used : Randoms(lib.Randoms) Piece(core.mino.Piece) Test(org.junit.jupiter.api.Test)

Example 34 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class FieldFactoryTest method testRandom.

@Test
void testRandom() {
    Randoms randoms = new Randoms();
    int width = 10;
    for (int count = 0; count < 10000; count++) {
        int height = randoms.nextIntClosed(1, 12);
        boolean[][] fields = new boolean[height][width];
        for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) fields[y][x] = randoms.nextBoolean();
        StringBuilder builder = new StringBuilder();
        for (int y = height - 1; 0 <= y; y--) {
            for (int x = 0; x < width; x++) {
                boolean isEmpty = fields[y][x];
                builder.append(isEmpty ? '_' : 'X');
            }
        }
        String marks = builder.toString();
        Field field = FieldFactory.createField(marks);
        for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) assertThat(field.isEmpty(x, y)).isEqualTo(fields[y][x]);
    }
}
Also used : Randoms(lib.Randoms) Test(org.junit.jupiter.api.Test)

Example 35 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class LongBoardMapTest method insertBlackLine.

@Test
void insertBlackLine() {
    Randoms randoms = new Randoms();
    BooleanWalker.walk(6).forEach(booleans -> {
        SmallField expect = new SmallField();
        SmallField field = new SmallField();
        long deleteKey = 0L;
        int expectY = 0;
        for (int y = 0; y < booleans.size(); y++) {
            if (booleans.get(y)) {
                // ラインを全て埋める
                for (int x = 0; x < 10; x++) expect.setBlock(x, y);
                deleteKey += KeyOperators.getDeleteBitKey(y);
            } else {
                // ラインを全て埋めない
                for (int x = 0; x < 10; x++) {
                    if (randoms.nextBoolean(0.8)) {
                        expect.setBlock(x, y);
                        field.setBlock(x, expectY);
                    }
                }
                int removeX = randoms.nextInt(0, 10);
                expect.removeBlock(removeX, y);
                field.removeBlock(removeX, expectY);
                expectY += 1;
            }
        }
        long board = field.getXBoard();
        assertThat(LongBoardMap.insertBlackLine(board, deleteKey)).isEqualTo(expect.getXBoard());
    });
}
Also used : Randoms(lib.Randoms) Test(org.junit.jupiter.api.Test)

Aggregations

Randoms (lib.Randoms)108 Test (org.junit.jupiter.api.Test)103 Piece (core.mino.Piece)58 LongTest (module.LongTest)32 Field (core.field.Field)29 Action (common.datastore.action.Action)25 LongPieces (common.datastore.blocks.LongPieces)24 MinoFactory (core.mino.MinoFactory)20 ArrayList (java.util.ArrayList)19 LockedCandidate (core.action.candidate.LockedCandidate)17 Mino (core.mino.Mino)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 MinoShifter (core.mino.MinoShifter)14 MinoRotation (core.srs.MinoRotation)14 Rotate (core.srs.Rotate)13 Collectors (java.util.stream.Collectors)13 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)12 PatternGenerator (common.pattern.PatternGenerator)12 List (java.util.List)12 SeparableMino (searcher.pack.separable_mino.SeparableMino)12