Search in sources :

Example 16 with Rotate

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

the class Tetfu method decodeMain.

private List<TetfuPage> decodeMain(String str) {
    LinkedList<Integer> values = str.replace("?", "").chars().boxed().map(c -> decodeData((char) c.intValue())).collect(Collectors.toCollection(LinkedList::new));
    ArrayList<TetfuPage> pages = new ArrayList<>();
    ColoredField prevField = ColoredFieldFactory.createField(TETFU_MAX_HEIGHT);
    ColoredField currentField = ColoredFieldFactory.createField(TETFU_MAX_HEIGHT);
    int[] blockUp = new int[FILED_WIDTH];
    int repeatCount = -1;
    while (!values.isEmpty()) {
        if (repeatCount <= 0) {
            int index = 0;
            boolean isChange = false;
            while (index < TETFU_FIELD_BLOCKS) {
                int diffBlock = pollValues(values, 2);
                int diff = diffBlock / TETFU_FIELD_BLOCKS;
                int block = diffBlock % TETFU_FIELD_BLOCKS;
                if (block != TETFU_FIELD_BLOCKS - 1)
                    isChange = true;
                for (int b = 0; b < block + 1; b++) {
                    int x = index % 10;
                    int y = TETFU_FIELD_TOP - (index / 10) - 1;
                    if (0 <= y) {
                        int prevBlockNumber = prevField.getBlockNumber(x, y);
                        currentField.setBlockNumber(x, y, diff + prevBlockNumber - 8);
                    } else {
                        blockUp[x] += diff - 8;
                    }
                    index += 1;
                }
            }
            if (!isChange)
                repeatCount = pollValues(values, 1);
        } else {
            currentField = prevField;
            repeatCount -= 1;
        }
        int action = pollValues(values, 3);
        ActionDecoder actionDecoder = new ActionDecoder(action);
        String escapedComment = "";
        if (actionDecoder.isComment) {
            List<Integer> commentValues = new ArrayList<>();
            int commentLength = pollValues(values, 2);
            for (int commentCounter = 0; commentCounter < (commentLength + 3) / 4; commentCounter++) {
                int commentValue = pollValues(values, 5);
                commentValues.add(commentValue);
            }
            CommentDecoder commentDecoder = new CommentDecoder(commentLength, commentValues);
            escapedComment = commentDecoder.getEscapedComment();
        }
        TetfuPage tetfuPage = new DecodedTetfuPage(actionDecoder, escapedComment, currentField);
        pages.add(tetfuPage);
        ColorType colorType = actionDecoder.colorType;
        if (actionDecoder.isLock) {
            if (ColorType.isMinoBlock(colorType)) {
                Rotate rotate = actionDecoder.rotate;
                Coordinate coordinate = actionDecoder.coordinate;
                Piece piece = converter.parseToBlock(colorType);
                Mino mino = minoFactory.create(piece, rotate);
                currentField.putMino(mino, coordinate.x, coordinate.y);
            }
            currentField.clearLine();
            if (actionDecoder.isBlockUp) {
                currentField.blockUp();
                for (int x = 0; x < TETFU_FIELD_WIDTH; x++) currentField.setBlockNumber(x, 0, blockUp[x]);
            }
            if (actionDecoder.isMirror)
                currentField.mirror();
        }
        prevField = currentField;
    }
    return pages;
}
Also used : CommentDecoder(common.tetfu.decorder.CommentDecoder) Piece(core.mino.Piece) Arrays(java.util.Arrays) ColorType(common.tetfu.common.ColorType) ActionFlags(common.tetfu.common.ActionFlags) ActionDecoder(common.tetfu.decorder.ActionDecoder) CommentEncoder(common.tetfu.encorder.CommentEncoder) FinderParseException(exceptions.FinderParseException) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) ENCODE_TABLE_SIZE(common.tetfu.TetfuTable.ENCODE_TABLE_SIZE) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) FieldEncoder(common.tetfu.encorder.FieldEncoder) Coordinate(common.tetfu.common.Coordinate) LinkedList(java.util.LinkedList) ColoredField(common.tetfu.field.ColoredField) TetfuTable.decodeData(common.tetfu.TetfuTable.decodeData) ActionEncoder(common.tetfu.encorder.ActionEncoder) Mino(core.mino.Mino) ColoredField(common.tetfu.field.ColoredField) ActionDecoder(common.tetfu.decorder.ActionDecoder) Rotate(core.srs.Rotate) ArrayList(java.util.ArrayList) CommentDecoder(common.tetfu.decorder.CommentDecoder) Coordinate(common.tetfu.common.Coordinate) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Mino(core.mino.Mino)

Example 17 with Rotate

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

the class OperationInterpreter method createOperation.

private static Operation createOperation(String strings) {
    String[] split = strings.split(",");
    assert split.length == 4;
    Piece piece = StringEnumTransform.toPiece(split[0].trim());
    Rotate rotate = StringEnumTransform.toRotate(split[1].trim());
    int x = Integer.valueOf(split[2].trim());
    int y = Integer.valueOf(split[3].trim());
    return new SimpleOperation(piece, rotate, x, y);
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) SimpleOperation(common.datastore.SimpleOperation)

Example 18 with Rotate

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

the class Neighbors method createNeighbors.

private Neighbor[][][][] createNeighbors(OriginalPieceFactory pieceFactory, int maxHeight) {
    int maxBlock = Piece.values().length;
    int maxRotate = Rotate.values().length;
    Neighbor[][][][] neighbors = new Neighbor[maxBlock][maxRotate][maxHeight][FIELD_WIDTH];
    Collection<OriginalPiece> pieces = pieceFactory.create();
    for (OriginalPiece piece : pieces) {
        Mino mino = piece.getMino();
        Piece block = mino.getPiece();
        Rotate rotate = mino.getRotate();
        int x = piece.getX();
        int y = piece.getY();
        Neighbor neighbor = new Neighbor(piece);
        neighbors[block.getNumber()][rotate.getNumber()][y][x] = neighbor;
    }
    return neighbors;
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino)

Example 19 with Rotate

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

the class OriginalPieceFactory method createPieces.

private Set<OriginalPiece> createPieces(int fieldHeight) {
    Set<OriginalPiece> pieces = new HashSet<>();
    for (Piece block : Piece.values()) {
        for (Rotate rotate : Rotate.values()) {
            Mino mino = new Mino(block, rotate);
            for (int y = -mino.getMinY(); y < fieldHeight - mino.getMaxY(); y++) {
                for (int x = -mino.getMinX(); x < FIELD_WIDTH - mino.getMaxX(); x++) {
                    OriginalPiece piece = new OriginalPiece(mino, x, y, fieldHeight);
                    pieces.add(piece);
                }
            }
        }
    }
    return pieces;
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) HashSet(java.util.HashSet)

Example 20 with Rotate

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

the class MinoShifter method getUniqueRotates.

public Set<Rotate> getUniqueRotates(Piece piece) {
    HashSet<Rotate> uniques = new HashSet<>();
    for (Rotate rotate : Rotate.values()) {
        Rotate newRotate = transformers.get(piece).transformRotate(rotate);
        uniques.add(newRotate);
    }
    return uniques;
}
Also used : Rotate(core.srs.Rotate) HashSet(java.util.HashSet)

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