use of core.mino.Mino 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.mino.Mino in project solution-finder by knewjade.
the class LockedReachable method checkLeftRotation.
private boolean checkLeftRotation(Field field, Mino mino, int x, int y) {
Rotate currentRotate = mino.getRotate();
Mino minoBefore = minoFactory.create(mino.getPiece(), currentRotate.getRightRotate());
// 右回転前のテストパターンを取得
int[][] patterns = minoRotation.getLeftPatternsFrom(minoBefore);
for (int[] pattern : patterns) {
int fromX = x - pattern[0];
int fromY = y - pattern[1];
if (canPutMinoInField(field, minoBefore, fromX, fromY)) {
int[] kicks = minoRotation.getKicksWithLeftRotation(field, minoBefore, mino, fromX, fromY);
if (kicks != null && pattern[0] == kicks[0] && pattern[1] == kicks[1])
if (check(field, minoBefore, fromX, fromY, From.None))
return true;
}
}
return false;
}
use of core.mino.Mino in project solution-finder by knewjade.
the class OperationTransform method parseToOperationWithKeys.
// List<OperationWithKey>に変換する。正しく組み立てられるかはチェックしない
public static List<MinoOperationWithKey> parseToOperationWithKeys(Field fieldOrigin, Operations operations, MinoFactory minoFactory, int height) {
ArrayList<MinoOperationWithKey> keys = new ArrayList<>();
Field field = fieldOrigin.freeze(height);
for (Operation op : operations.getOperations()) {
Mino mino = minoFactory.create(op.getPiece(), op.getRotate());
int x = op.getX();
int y = op.getY();
long deleteKey = field.clearLineReturnKey();
// 一番上と一番下のy座標を抽出
Field vanilla = FieldFactory.createField(height);
vanilla.put(mino, x, y);
vanilla.insertWhiteLineWithKey(deleteKey);
int lowerY = vanilla.getLowerY();
int upperY = vanilla.getUpperYWith4Blocks();
// 接着に必ず消去されている必要がある行を抽出
long aboveLowerY = KeyOperators.getMaskForKeyAboveY(lowerY);
long belowUpperY = KeyOperators.getMaskForKeyBelowY(upperY + 1);
long keyLine = aboveLowerY & belowUpperY;
long needDeletedKey = deleteKey & keyLine;
long usingKey = keyLine & ~needDeletedKey;
// 操作・消去されている必要がある行をセットで記録
MinoOperationWithKey operationWithKey = new FullOperationWithKey(mino, x, needDeletedKey, usingKey, lowerY);
keys.add(operationWithKey);
// 次のフィールドを作成
field.put(mino, x, y);
field.insertBlackLineWithKey(deleteKey);
}
return keys;
}
use of core.mino.Mino in project solution-finder by knewjade.
the class MoveSettingParser method loadTetfu.
private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, MoveSettings settings) throws FinderParseException {
// テト譜面のエンコード
List<TetfuPage> decoded = encodeTetfu(data);
// 指定されたページを抽出
int page = wrapper.getIntegerOption("page").orElse(1);
TetfuPage tetfuPage = extractTetfuPage(decoded, page);
// コメントの抽出
// 先頭が数字ではない(--clear-line -p *p7のようになる)場合でも、parserはエラーにならない
// データ取得時にOptional.emptyがかえるだけ
String comment = "--clear-line " + tetfuPage.getComment();
List<String> splitComment = Arrays.stream(comment.split(" ")).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
// コマンド引数を配列に変換
String[] commentArgs = new String[splitComment.size()];
splitComment.toArray(commentArgs);
// オプションとして読み込む
try {
CommandLine commandLineTetfu = parseToCommandLine(options, parser, commentArgs);
CommandLineWrapper newWrapper = new NormalCommandLineWrapper(commandLineTetfu);
// 削除ラインが読み取れればOK
newWrapper.getIntegerOption("clear-line");
wrapper = new PriorityCommandLineWrapper(Arrays.asList(wrapper, newWrapper));
} catch (FinderParseException ignore) {
}
// 最大削除ラインの設定
Optional<Integer> maxClearLineOption = wrapper.getIntegerOption("clear-line");
maxClearLineOption.ifPresent(settings::setMaxClearLine);
// フィールドを設定
ColoredField coloredField = tetfuPage.getField();
if (tetfuPage.isPutMino()) {
ColorType colorType = tetfuPage.getColorType();
Rotate rotate = tetfuPage.getRotate();
int x = tetfuPage.getX();
int y = tetfuPage.getY();
ColorConverter colorConverter = new ColorConverter();
Mino mino = new Mino(colorConverter.parseToBlock(colorType), rotate);
coloredField.putMino(mino, x, y);
}
settings.setField(coloredField);
return wrapper;
}
use of core.mino.Mino in project solution-finder by knewjade.
the class PathCore method createField.
private Field createField(MinoOperationWithKey key, int maxClearLine) {
Mino mino = key.getMino();
Field test = FieldFactory.createField(maxClearLine);
test.put(mino, key.getX(), key.getY());
test.insertWhiteLineWithKey(key.getNeedDeletedKey());
return test;
}
Aggregations