Search in sources :

Example 1 with CommentDecoder

use of common.tetfu.decorder.CommentDecoder 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)

Aggregations

ENCODE_TABLE_SIZE (common.tetfu.TetfuTable.ENCODE_TABLE_SIZE)1 TetfuTable.decodeData (common.tetfu.TetfuTable.decodeData)1 ActionFlags (common.tetfu.common.ActionFlags)1 ColorConverter (common.tetfu.common.ColorConverter)1 ColorType (common.tetfu.common.ColorType)1 Coordinate (common.tetfu.common.Coordinate)1 ActionDecoder (common.tetfu.decorder.ActionDecoder)1 CommentDecoder (common.tetfu.decorder.CommentDecoder)1 ActionEncoder (common.tetfu.encorder.ActionEncoder)1 CommentEncoder (common.tetfu.encorder.CommentEncoder)1 FieldEncoder (common.tetfu.encorder.FieldEncoder)1 ColoredField (common.tetfu.field.ColoredField)1 ColoredFieldFactory (common.tetfu.field.ColoredFieldFactory)1 Mino (core.mino.Mino)1 MinoFactory (core.mino.MinoFactory)1 Piece (core.mino.Piece)1 Rotate (core.srs.Rotate)1 FinderParseException (exceptions.FinderParseException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1