Search in sources :

Example 1 with Rotate

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

the class AllSeparableMinoFactory method create.

public Set<SeparableMino> create() {
    HashSet<SeparableMino> pieces = new HashSet<>();
    HashSet<Mino> createdCheckSet = new HashSet<>();
    for (Piece piece : Piece.values()) {
        for (Rotate originRotate : Rotate.values()) {
            Rotate rotate = minoShifter.createTransformedRotate(piece, originRotate);
            Mino mino = minoFactory.create(piece, rotate);
            // 追加済みかチェック
            if (createdCheckSet.contains(mino))
                continue;
            createdCheckSet.add(mino);
            // ミノの高さを計算
            int minoHeight = mino.getMaxY() - mino.getMinY() + 1;
            // フィールドの高さ以上にミノを使う場合はおけない
            if (fieldHeight < minoHeight)
                continue;
            // 行候補をリストにする
            ArrayList<Integer> lineIndexes = getLineIndexes(fieldHeight);
            // リストアップ
            ArrayList<SeparableMino> piecesEachMino = generatePiecesEachMino(mino, lineIndexes, minoHeight);
            // 追加
            pieces.addAll(piecesEachMino);
        }
    }
    return pieces;
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) HashSet(java.util.HashSet)

Example 2 with Rotate

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

the class ActionParser method parseToOperation.

static Operation parseToOperation(int value) {
    int x = value % 10;
    value /= 10;
    int y = value % 24;
    value /= 24;
    Rotate rotate = Rotate.getRotate(value % 4);
    value /= 4;
    Piece piece = Piece.getBlock(value);
    return new SimpleOperation(piece, rotate, x, y);
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) SimpleOperation(common.datastore.SimpleOperation)

Example 3 with Rotate

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

the class SlideXOperationWithKeyTest method get.

@Test
void get() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 10000; count++) {
        Piece piece = randoms.block();
        Rotate rotate = randoms.rotate();
        Mino mino = new Mino(piece, rotate);
        int x = randoms.nextInt(0, 10);
        int y = randoms.nextInt(0, 10);
        long usingKey = randoms.key();
        long deleteKey = randoms.key();
        FullOperationWithKey operationWithKey = new FullOperationWithKey(mino, x, y, deleteKey, usingKey);
        int slide = randoms.nextInt(4);
        SlideXOperationWithKey key = new SlideXOperationWithKey(operationWithKey, slide);
        assertThat(key).returns(x + slide, SlideXOperationWithKey::getX).returns(y, SlideXOperationWithKey::getY).returns(deleteKey, SlideXOperationWithKey::getNeedDeletedKey).returns(usingKey, SlideXOperationWithKey::getUsingKey);
    }
}
Also used : Randoms(lib.Randoms) Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Example 4 with Rotate

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

the class HarddropCandidateTest method testRandom.

@Test
void testRandom() throws Exception {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new PassedMinoShifter();
    HarddropCandidate candidate = new HarddropCandidate(minoFactory, minoShifter);
    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> actions = candidate.search(field, piece, height);
        for (Rotate rotate : minoShifter.getUniqueRotates(piece)) {
            Coordinates.walk(minoFactory.create(piece, rotate), height).map(coordinate -> MinimalAction.create(coordinate.x, coordinate.y, rotate)).forEach(action -> {
                int x = action.getX();
                int y = action.getY();
                Mino mino = minoFactory.create(piece, action.getRotate());
                boolean canPut = field.isOnGround(mino, x, y) && IntStream.range(y, height - mino.getMinY()).allMatch(up -> field.canPut(mino, x, up));
                assertThat(actions.contains(action)).isEqualTo(canPut);
            });
        }
    }
}
Also used : Action(common.datastore.action.Action) MinimalAction(common.datastore.action.MinimalAction) Test(org.junit.jupiter.api.Test) IntStream(java.util.stream.IntStream) Randoms(lib.Randoms) Field(core.field.Field) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) core.mino(core.mino) Set(java.util.Set) FieldFactory(core.field.FieldFactory) Coordinates(lib.Coordinates) Rotate(core.srs.Rotate) Action(common.datastore.action.Action) MinimalAction(common.datastore.action.MinimalAction) Rotate(core.srs.Rotate) Field(core.field.Field) Randoms(lib.Randoms) Test(org.junit.jupiter.api.Test)

Example 5 with Rotate

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

the class LockedCandidateTest method testRandom.

@Test
void testRandom() throws Exception {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new PassedMinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    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 height = randomHeight - field.clearLine();
        Piece piece = randoms.block();
        LockedCandidate candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
        Set<Action> actions = candidate.search(field, piece, height);
        LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
        for (Rotate rotate : Rotate.values()) {
            Coordinates.walk(minoFactory.create(piece, rotate), height).map(coordinate -> MinimalAction.create(coordinate.x, coordinate.y, rotate)).forEach(action -> {
                int x = action.getX();
                int y = action.getY();
                Mino mino = minoFactory.create(piece, action.getRotate());
                if (actions.contains(action)) {
                    // おける
                    assertThat(field.canPut(mino, x, y)).isTrue();
                    assertThat(field.isOnGround(mino, x, y)).isTrue();
                    assertThat(reachable.checks(field, mino, x, y, height)).isTrue();
                } else {
                    // おけない
                    boolean canPut = field.canPut(mino, x, y) && field.isOnGround(mino, x, y) && reachable.checks(field, mino, x, y, height);
                    assertThat(canPut).isFalse();
                }
            });
        }
    }
}
Also used : MinimalAction(common.datastore.action.MinimalAction) Randoms(lib.Randoms) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Coordinates(lib.Coordinates) Rotate(core.srs.Rotate) Action(common.datastore.action.Action) Test(org.junit.jupiter.api.Test) Field(core.field.Field) core.mino(core.mino) FieldFactory(core.field.FieldFactory) MinoRotation(core.srs.MinoRotation) LockedReachable(core.action.reachable.LockedReachable) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) Rotate(core.srs.Rotate) MinoRotation(core.srs.MinoRotation) Field(core.field.Field) Randoms(lib.Randoms) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test)

Aggregations

Rotate (core.srs.Rotate)55 Mino (core.mino.Mino)25 Piece (core.mino.Piece)25 Test (org.junit.jupiter.api.Test)14 Action (common.datastore.action.Action)13 ColorType (common.tetfu.common.ColorType)11 Randoms (lib.Randoms)11 HashSet (java.util.HashSet)10 ColoredField (common.tetfu.field.ColoredField)9 MinoFactory (core.mino.MinoFactory)9 List (java.util.List)9 MinimalAction (common.datastore.action.MinimalAction)7 TetfuPage (common.tetfu.TetfuPage)7 ColorConverter (common.tetfu.common.ColorConverter)7 Arrays (java.util.Arrays)7 Collectors (java.util.stream.Collectors)7 Field (core.field.Field)6 FinderParseException (exceptions.FinderParseException)6 SimpleOperation (common.datastore.SimpleOperation)5 ColoredFieldFactory (common.tetfu.field.ColoredFieldFactory)5