use of common.tetfu.common.ColorType in project solution-finder by knewjade.
the class ArrayColoredField method putMino.
@Override
public void putMino(Mino mino, int x, int y) {
Piece piece = mino.getPiece();
ColorType type = converter.parseToColorType(piece);
for (int[] positions : mino.getPositions()) setColorType(type, x + positions[0], y + positions[1]);
}
use of common.tetfu.common.ColorType in project solution-finder by knewjade.
the class ColoredFieldFactory method createColoredField.
public static ColoredField createColoredField(String marks) {
if (marks.length() % 10 != 0)
throw new IllegalArgumentException("length of marks should be 'mod 10'");
int maxY = marks.length() / 10;
ColoredField field = new ArrayColoredField(MAX_HEIGHT);
for (int y = 0; y < maxY; y++) {
for (int x = 0; x < 10; x++) {
char mark = marks.charAt((maxY - y - 1) * 10 + x);
ColorType colorType = get(mark);
if (colorType != ColorType.Empty) {
field.setColorType(colorType, x, y);
}
}
}
return field;
}
use of common.tetfu.common.ColorType in project solution-finder by knewjade.
the class SetupSettingParser method loadTetfu.
private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, SetupSettings settings) throws FinderParseException {
// テト譜面のエンコード
List<TetfuPage> decoded = encodeTetfu(data);
// 指定されたページを抽出
int page = wrapper.getIntegerOption("page").orElse(1);
TetfuPage tetfuPage = extractTetfuPage(decoded, page);
// コメントの抽出
String comment = 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);
wrapper = new PriorityCommandLineWrapper(Arrays.asList(wrapper, newWrapper));
} catch (FinderParseException ignore) {
}
// 固定ピースの指定があるか
// Optional<Boolean> reservedOption = wrapper.getBoolOption("reserved");
// reservedOption.ifPresent(settings::setReserved);
// マージン色の指定があるか
Optional<String> fillColorOption = wrapper.getStringOption("fill");
if (fillColorOption.isPresent()) {
settings.setFillColorType(fillColorOption.get());
}
// マージン色の指定があるか
Optional<String> marginColorOption = wrapper.getStringOption("margin");
if (marginColorOption.isPresent()) {
settings.setMarginColorType(marginColorOption.get());
}
// フィールドを設定
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);
}
// 最大削除ラインの設定
Optional<Integer> maxHeightOption = wrapper.getIntegerOption("line");
int maxHeight = maxHeightOption.orElse(coloredField.getUsingHeight());
if (settings.isReserved()) {
Field initField = FieldFactory.createField(maxHeight);
Field needFilledField = FieldFactory.createField(maxHeight);
Field notFilledField = FieldFactory.createField(maxHeight);
ColorType marginColorType = settings.getMarginColorType();
ColorType fillColorType = settings.getFillColorType();
for (int y = 0; y < maxHeight; y++) {
for (int x = 0; x < 10; x++) {
ColorType colorType = coloredField.getColorType(x, y);
if (colorType.equals(marginColorType)) {
coloredField.setColorType(ColorType.Empty, x, y);
} else if (colorType.equals(fillColorType)) {
coloredField.setColorType(ColorType.Empty, x, y);
needFilledField.setBlock(x, y);
} else {
switch(colorType) {
case Gray:
initField.setBlock(x, y);
notFilledField.setBlock(x, y);
coloredField.setColorType(ColorType.Empty, x, y);
break;
case Empty:
notFilledField.setBlock(x, y);
break;
default:
break;
}
}
}
}
settings.setFieldWithReserved(initField, needFilledField, notFilledField, coloredField, maxHeight);
} else {
Field initField = FieldFactory.createField(maxHeight);
Field needFilledField = FieldFactory.createField(maxHeight);
Field notFilledField = FieldFactory.createField(maxHeight);
ColorType marginColorType = settings.getMarginColorType();
ColorType fillColorType = settings.getFillColorType();
for (int y = 0; y < maxHeight; y++) {
for (int x = 0; x < 10; x++) {
ColorType colorType = coloredField.getColorType(x, y);
if (colorType.equals(marginColorType)) {
// skip
} else if (colorType.equals(fillColorType)) {
needFilledField.setBlock(x, y);
} else {
switch(colorType) {
case Empty:
notFilledField.setBlock(x, y);
break;
case Gray:
default:
initField.setBlock(x, y);
notFilledField.setBlock(x, y);
break;
}
}
}
}
settings.setField(initField, needFilledField, notFilledField, maxHeight);
}
return wrapper;
}
use of common.tetfu.common.ColorType in project solution-finder by knewjade.
the class SetupSettings method setFieldWithReserved.
void setFieldWithReserved(Field initField, Field needFilledField, Field notFilledField, ColoredField coloredField, int maxHeight) {
BlockField blockField = new BlockField(maxHeight);
for (int y = 0; y < maxHeight; y++) {
for (int x = 0; x < 10; x++) {
ColorConverter colorConverter = new ColorConverter();
ColorType colorType = colorConverter.parseToColorType(coloredField.getBlockNumber(x, y));
switch(colorType) {
case Gray:
case Empty:
break;
default:
Piece piece = colorConverter.parseToBlock(colorType);
blockField.setBlock(piece, x, y);
break;
}
}
}
setMaxHeight(maxHeight);
setInitField(initField);
setNeedFilledField(needFilledField);
setNotFilledField(notFilledField);
setReservedBlock(blockField);
}
use of common.tetfu.common.ColorType in project solution-finder by knewjade.
the class FigUtilEntryPoint method createBag.
private Bag createBag(ColorConverter colorConverter, int startPageIndex, List<TetfuPage> tetfuPages, Quiz quiz, List<TetfuPage> usingTetfuPages) {
String comment = quiz.comment;
if (settings.isUsingHold() && comment != null) {
int holdIndex = comment.indexOf('[') + 1;
char holdChar = comment.charAt(holdIndex);
Piece hold = null;
if (holdChar != ']')
hold = Piece.valueOf(String.valueOf(holdChar).toUpperCase());
int currentIndex = comment.indexOf('(') + 1;
int currentChar = comment.charAt(currentIndex);
String next = comment.substring(comment.indexOf(')') + 1, comment.length());
List<Piece> pieces = IntStream.concat(IntStream.of(currentChar), next.chars()).mapToObj(value -> (char) value).map(String::valueOf).map(String::toUpperCase).map(Piece::valueOf).collect(Collectors.toList());
Bag bag = new Bag(pieces, hold);
for (int index = quiz.index; index < startPageIndex; index++) {
ColorType colorType = tetfuPages.get(index).getColorType();
bag.use(colorConverter.parseToBlock(colorType));
}
return bag;
} else {
List<Piece> collect = usingTetfuPages.stream().map(TetfuPage::getColorType).filter(ColorType::isMinoBlock).map(colorConverter::parseToBlock).collect(Collectors.toList());
return new Bag(collect, null);
}
}
Aggregations