use of core.mino.Mino in project solution-finder by knewjade.
the class OperationWithKeyComparatorTest method compareDiffY.
@Test
void compareDiffY() throws Exception {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
int x = randoms.nextInt(10);
int y = randoms.nextInt(20);
long deleteKey = 0L;
long usingKey = 1049600L;
OperationWithKey operationWithKey1 = new FullOperationWithKey(minoFactory.create(Piece.I, Rotate.Spawn), x, y, deleteKey, usingKey);
int newY = randoms.nextInt(20);
if (newY == y)
newY += 1;
Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, newY, deleteKey, usingKey);
// assert is not 0 & sign reversed
OperationWithKeyComparator comparator = new OperationWithKeyComparator();
assertThat(comparator.compare(operationWithKey1, operationWithKey2) * comparator.compare(operationWithKey2, operationWithKey1)).as(operationWithKey2.toString()).isLessThan(0);
}
use of core.mino.Mino in project solution-finder by knewjade.
the class PathSettingParser method loadTetfu.
private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, PathSettings 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<Boolean> reservedOption = wrapper.getBoolOption("reserved");
reservedOption.ifPresent(settings::setReserved);
// 最大削除ラインの設定
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);
}
if (settings.isReserved())
settings.setFieldWithReserved(coloredField, settings.getMaxClearLine());
else
settings.setField(coloredField, settings.getMaxClearLine());
return wrapper;
}
use of core.mino.Mino in project solution-finder by knewjade.
the class OneFumenParser 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;
}
use of core.mino.Mino in project solution-finder by knewjade.
the class AllMinoFactory 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;
}
use of core.mino.Mino in project solution-finder by knewjade.
the class PercentSettingParser method loadTetfu.
private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, PercentSettings 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, settings.getMaxClearLine());
return wrapper;
}
Aggregations