use of common.tetfu.field.ColoredField in project solution-finder by knewjade.
the class FieldOnlyFigGenerator method updateField.
@Override
public void updateField(ColoredField field, Mino mino, int x, int y) {
ColoredField freeze = field.freeze(field.getMaxHeight());
if (mino != null)
freeze.putMino(mino, x, y);
int heightBlock = setting.getFieldHeightBlock();
int widthBlock = setting.getFieldWidthBlock();
for (int yIndex = 0; yIndex < heightBlock; yIndex++) {
boolean isFilledLine = freeze.isFilledLine(yIndex);
for (int xIndex = 0; xIndex < widthBlock; xIndex++) {
ColorType type = field.getColorType(xIndex, yIndex);
FigColor figColor = FigColor.parse(type);
Color color = getColor(figColor, isFilledLine);
graphics.setColor(color);
Rectangle rectangle = positionDecider.getInField(xIndex, yIndex);
fillRect(rectangle);
}
}
}
use of common.tetfu.field.ColoredField in project solution-finder by knewjade.
the class NoHoldFigGenerator method updateField.
@Override
public void updateField(ColoredField field, Mino mino, int x, int y) {
ColoredField freeze = field.freeze(field.getMaxHeight());
if (mino != null)
freeze.putMino(mino, x, y);
int heightBlock = setting.getFieldHeightBlock();
int widthBlock = setting.getFieldWidthBlock();
for (int yIndex = 0; yIndex < heightBlock; yIndex++) {
boolean isFilledLine = freeze.isFilledLine(yIndex);
for (int xIndex = 0; xIndex < widthBlock; xIndex++) {
ColorType type = field.getColorType(xIndex, yIndex);
FigColor figColor = FigColor.parse(type);
Color color = getColor(figColor, isFilledLine);
graphics.setColor(color);
Rectangle rectangle = positionDecider.getInField(xIndex, yIndex);
fillRect(rectangle);
}
}
}
use of common.tetfu.field.ColoredField in project solution-finder by knewjade.
the class GifWriter method write.
@Override
public void write(List<TetfuPage> tetfuPages) throws IOException {
boolean isLoop = isInfiniteLoop;
try (ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(outputFile)) {
// imageWriterの準備
ImageWriter imageWriter = getGifImageWriter();
imageWriter.setOutput(imageOutputStream);
imageWriter.prepareWriteSequence(null);
for (TetfuPage tetfuPage : tetfuPages) {
// リセット
figGenerator.reset();
// 現在のミノを取得
ColorType colorType = tetfuPage.getColorType();
Rotate rotate = tetfuPage.getRotate();
Mino mino = ColorType.isMinoBlock(colorType) ? minoFactory.create(colorConverter.parseToBlock(colorType), rotate) : null;
int x = tetfuPage.getX();
int y = tetfuPage.getY();
// フィールドの更新
ColoredField field = tetfuPage.getField();
figGenerator.updateField(field, mino, x, y);
// ミノを置くかチェック
if (ColorType.isMinoBlock(colorType)) {
// 現在のミノの更新
figGenerator.updateMino(colorType, rotate, x, y);
// bagの更新
Piece piece = colorConverter.parseToBlock(colorType);
bag.use(piece);
}
// ネクストの更新
figGenerator.updateNext(bag.getNext(nextBoxCount));
// ホールドの更新
figGenerator.updateHold(bag.getHold());
// 画像の生成
BufferedImage image = figGenerator.fix();
// メタデータの作成
IIOMetadata metadata = createMetadata(imageWriter, image, delay, isLoop);
IIOImage iioImage = new IIOImage(image, null, metadata);
imageWriter.writeToSequence(iioImage, null);
// 無限ループの設定は最大1度までで十分
isLoop = false;
}
// imageWriterの終了処理
imageWriter.endWriteSequence();
}
}
use of common.tetfu.field.ColoredField 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 common.tetfu.field.ColoredField in project solution-finder by knewjade.
the class LinkPathOutput method outputOperationsToSimpleHTML.
private void outputOperationsToSimpleHTML(Field field, MyFile file, List<PathPair> pathPairs, SizedBit sizedBit) throws FinderExecuteException {
// Get height
int maxClearLine = sizedBit.getHeight();
// テト譜用のフィールド作成
ColoredField initField = ColoredFieldFactory.createField(24);
for (int y = 0; y < maxClearLine; y++) for (int x = 0; x < 10; x++) if (!field.isEmpty(x, y))
initField.setColorType(ColorType.Gray, x, y);
// 並び替える
Comparator<PathPair> comparator = new PathPairComparator();
pathPairs.sort(comparator);
// HTMLの生成 // true: ライン消去あり, false: ライン消去なし
HTMLBuilder<HTMLColumn> htmlBuilder = new HTMLBuilder<>("Path Result");
htmlBuilder.addHeader(String.format("<div>%dパターン</div>", pathPairs.size()));
pathPairs.parallelStream().forEach(pathPair -> {
PathHTMLColumn htmlColumn = getHTMLColumn(pathPair);
Pair<String, Integer> linkAndPriority = createALink(pathPair);
String line = String.format("<div>%s</div>", linkAndPriority.getKey());
htmlBuilder.addColumn(htmlColumn, line, -linkAndPriority.getValue());
});
// 出力
try (BufferedWriter writer = file.newBufferedWriter()) {
List<HTMLColumn> priorityList = Arrays.asList(PathHTMLColumn.NotDeletedLine, PathHTMLColumn.DeletedLine);
for (String line : htmlBuilder.toList(priorityList, false)) writer.write(line);
writer.flush();
} catch (Exception e) {
throw new FinderExecuteException("Failed to output file", e);
}
}
Aggregations