use of core.mino.Mino in project solution-finder by knewjade.
the class FieldOnlyFigGenerator method updateMino.
@Override
public void updateMino(ColorType colorType, Rotate rotate, int xIndex, int yIndex) {
Piece piece = colorConverter.parseToBlock(colorType);
Mino mino = minoFactory.create(piece, rotate);
FigColor figColor = FigColor.parse(colorType);
Color color = figColor.getStrongColor();
graphics.setColor(color);
for (int[] positions : mino.getPositions()) {
Rectangle rectangle = positionDecider.getInField(xIndex + positions[0], yIndex + positions[1]);
fillRect(rectangle);
}
}
use of core.mino.Mino 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 core.mino.Mino in project solution-finder by knewjade.
the class DeleteKeyParser method initializeMaps.
private EnumMap<Piece, EnumMap<Rotate, List<DeleteKey>>> initializeMaps(MinoFactory minoFactory, int maxClearLine) {
EnumMap<Piece, EnumMap<Rotate, List<DeleteKey>>> maps = new EnumMap<>(Piece.class);
for (Piece piece : Piece.values()) {
EnumMap<Rotate, List<DeleteKey>> rotateMaps = maps.computeIfAbsent(piece, blk -> new EnumMap<>(Rotate.class));
for (Rotate rotate : Rotate.values()) {
Mino mino = minoFactory.create(piece, rotate);
// ミノの高さを計算
int minoHeight = mino.getMaxY() - mino.getMinY() + 1;
// 行候補をリストにする
ArrayList<Integer> lineIndexes = new ArrayList<>();
for (int index = 0; index < maxClearLine; index++) lineIndexes.add(index);
// ブロックが置かれる行を選択する
CombinationIterable<Integer> combinationIterable = new CombinationIterable<>(lineIndexes, minoHeight);
// リストアップ
ArrayList<DeleteKey> deleteLimitedMinos = new ArrayList<>();
for (List<Integer> indexes : combinationIterable) {
// ソートする
indexes.sort(Integer::compare);
// 一番下の行と一番上の行を取得
int lowerY = indexes.get(0);
int upperY = indexes.get(indexes.size() - 1);
// ミノに挟まれる全ての行を含むdeleteKey
long deleteKey = KeyOperators.getMaskForKeyAboveY(lowerY) & KeyOperators.getMaskForKeyBelowY(upperY + 1);
long usingKey = 0L;
assert Long.bitCount(deleteKey) == upperY - lowerY + 1;
for (Integer index : indexes) {
long bitKey = KeyOperators.getDeleteBitKey(index);
// ブロックのある行のフラグを取り消す
deleteKey &= ~bitKey;
// ブロックのある行のフラグをたてる
usingKey |= bitKey;
}
assert Long.bitCount(deleteKey) + indexes.size() == upperY - lowerY + 1;
deleteLimitedMinos.add(DeleteKey.create(mino, deleteKey, usingKey, lowerY, upperY));
}
rotateMaps.put(rotate, deleteLimitedMinos);
}
}
return maps;
}
use of core.mino.Mino in project solution-finder by knewjade.
the class FullLimitedMinos method compareToMino.
private int compareToMino(FullLimitedMino o1, FullLimitedMino o2) {
Mino mino = o1.getMino();
Mino oMino = o2.getMino();
int block = mino.getPiece().compareTo(oMino.getPiece());
if (block != 0)
return block;
int rotate = mino.getRotate().compareTo(oMino.getRotate());
if (rotate != 0)
return rotate;
int position = o1.getPositionLimit().compareTo(o2.getPositionLimit());
if (position != 0)
return position;
int deleteKey = Long.compare(o1.getDeleteKey(), o2.getDeleteKey());
if (deleteKey != 0)
return deleteKey;
return Integer.compare(o1.getLowerY(), o2.getLowerY());
}
use of core.mino.Mino in project solution-finder by knewjade.
the class PositionLimitParser method createLJ.
private List<PositionLimitedMino> createLJ(Piece piece, DeltaLimit delta) {
Mino spawn = minoFactory.create(piece, Rotate.Spawn);
Mino reverse = minoFactory.create(piece, Rotate.Reverse);
Mino left = minoFactory.create(piece, Rotate.Left);
Mino right = minoFactory.create(piece, Rotate.Right);
switch(delta) {
case OddUp:
return Arrays.asList(PositionLimitedMino.create(spawn, PositionLimit.EvenX), PositionLimitedMino.create(reverse, PositionLimit.EvenX), PositionLimitedMino.create(left, PositionLimit.OddX), PositionLimitedMino.create(right, PositionLimit.OddX));
case EvenUp:
return Arrays.asList(PositionLimitedMino.create(spawn, PositionLimit.OddX), PositionLimitedMino.create(reverse, PositionLimit.OddX), PositionLimitedMino.create(left, PositionLimit.EvenX), PositionLimitedMino.create(right, PositionLimit.EvenX));
}
throw new IllegalStateException("No reachable");
}
Aggregations