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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations