use of common.tetfu.TetfuElement in project solution-finder by knewjade.
the class Main3 method parseBlockFieldToTetfuElement.
private static TetfuElement parseBlockFieldToTetfuElement(Field initField, ColorConverter colorConverter, Obj obj) {
ColoredField coloredField = ColoredFieldFactory.createField(24);
fillInField(coloredField, ColorType.Gray, initField);
BlockField blockField = obj.blockField;
for (Piece piece : Piece.values()) {
Field target = blockField.get(piece);
ColorType colorType = colorConverter.parseToColorType(piece);
fillInField(coloredField, colorType, target);
}
String blocks = obj.pieces.toString();
if (0 < obj.duplicate)
blocks += " 他 " + obj.duplicate + "pattern";
return new TetfuElement(coloredField, ColorType.Empty, Rotate.Reverse, 0, 0, blocks);
}
use of common.tetfu.TetfuElement in project solution-finder by knewjade.
the class Main3 method viewTetfu.
private static void viewTetfu(List<TetfuElement> elements) {
if (elements.isEmpty()) {
System.out.printf("<p>該当なし</p>%n");
} else {
MinoFactory minoFactory = new MinoFactory();
ColorConverter colorConverter = new ColorConverter();
int sizePerOne = 40;
int split = ((elements.size() - 1) / sizePerOne) + 1;
for (int index = 0; index < split; index++) {
int startIndex = index * sizePerOne;
int toIndex = index == split - 1 ? elements.size() : startIndex + sizePerOne;
List<TetfuElement> subList = elements.subList(startIndex, toIndex);
Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
String encode = tetfu.encode(subList);
if (split == 1)
System.out.printf("<p><a href='http://fumen.zui.jp/?v115@%s' target='_blank'>全 %d パターン</a></p>%n", encode, elements.size());
else
System.out.printf("<p><a href='http://fumen.zui.jp/?v115@%s' target='_blank'>全 %d パターン (%d/%d)</a></p>%n", encode, elements.size(), index + 1, split);
}
}
}
use of common.tetfu.TetfuElement in project solution-finder by knewjade.
the class Main3 method main.
public static void main(String[] args) {
Field field = FieldFactory.createField("" + "X_______XX" + "X_______XX" + "X_______XX" + "X_______XX");
int maxClearLine = 4;
Field verifyField = field.freeze(maxClearLine);
System.out.println(FieldView.toString(field, maxClearLine));
Stopwatch stopwatch = Stopwatch.createStoppedStopwatch();
stopwatch.start();
Set<List<Piece>> sets = new HashSet<>();
List<Piece> allPieces = Piece.valueList();
List<Piece> pieces = new ArrayList<>(allPieces);
int popCount = (maxClearLine * 10 - field.getNumOfAllBlocks()) / 4;
CombinationIterable<Piece> combinationIterable = new CombinationIterable<>(pieces, popCount);
for (List<Piece> pieceList : combinationIterable) {
pieceList.sort(Comparator.comparingInt(allPieces::indexOf));
sets.add(pieceList);
}
TreeSet<Obj> allObjSet = new TreeSet<>();
int counter = 0;
for (List<Piece> usedPieces : sets) {
counter++;
System.out.println(usedPieces);
System.out.println(counter + " / " + sets.size());
List<List<MinoOperationWithKey>> operationsWithKey = search(usedPieces, field, maxClearLine, verifyField);
List<Obj> objs = operationsWithKey.stream().map(operationWithKeys -> {
boolean isDeleted = false;
BlockField blockField = new BlockField(maxClearLine);
for (MinoOperationWithKey key : operationWithKeys) {
Field test = FieldFactory.createField(maxClearLine);
Mino mino = key.getMino();
test.put(mino, key.getX(), key.getY());
test.insertWhiteLineWithKey(key.getNeedDeletedKey());
blockField.merge(test, mino.getPiece());
if (key.getNeedDeletedKey() != 0L)
isDeleted = true;
}
return new Obj(usedPieces, blockField, isDeleted, operationWithKeys);
}).collect(Collectors.toList());
System.out.println(objs.size());
objs.stream().map(obj -> OperationWithKeyInterpreter.parseToString(obj.operations)).sorted().sequential().forEach(System.out::println);
allObjSet.addAll(objs);
}
System.out.println(allObjSet.size());
System.exit(0);
ArrayList<Obj> allObjs = new ArrayList<>(allObjSet);
allObjs.sort(Main3::blockListComparator);
// System.out.println(operationsWithKey.size());
ColorConverter colorConverter = new ColorConverter();
System.out.println("<h3>各ミノ最大1つずつ & ライン消去なし</h3>");
Predicate<Obj> objPredicate = obj -> !obj.isDouble && !obj.isDeleted;
List<TetfuElement> oneNoDelete = createTetfuElements(field, allObjs, colorConverter, objPredicate);
viewTetfu(oneNoDelete);
System.out.println("<h3>同一ミノを2つ利用 & ライン消去なし</h3>");
Predicate<Obj> objPredicate1 = obj -> obj.isDouble && !obj.isDeleted;
List<TetfuElement> doubleNoDelete = createTetfuElements(field, allObjs, colorConverter, objPredicate1);
viewTetfu(doubleNoDelete);
System.out.println("<h3>各ミノ最大1つずつ & ライン消去あり</h3>");
Predicate<Obj> objPredicate2 = obj -> !obj.isDouble && obj.isDeleted;
List<TetfuElement> oneDeleted = createTetfuElements(field, allObjs, colorConverter, objPredicate2);
viewTetfu(oneDeleted);
System.out.println("<h3>同一ミノを2つ利用 & ライン消去あり</h3>");
Predicate<Obj> objPredicate3 = obj -> obj.isDouble && obj.isDeleted;
List<TetfuElement> doubleDeleted = createTetfuElements(field, allObjs, colorConverter, objPredicate3);
viewTetfu(doubleDeleted);
// List<List<FullLimitedMino>> lists = Arrays.asList(
// singletonList(create(minoFactory, Piece.I, Rotate.Left, PositionLimit.OddX, 0L, 0, 3)),
// singletonList(create(minoFactory, Piece.O, Rotate.Spawn, PositionLimit.OddX, 0L, 0, 1)),
// singletonList(create(minoFactory, Piece.O, Rotate.Spawn, PositionLimit.OddX, 0L, 2, 3)),
// singletonList(create(minoFactory, Piece.L, Rotate.Reverse, PositionLimit.OddX, 0L, 0, 1)),
// singletonList(create(minoFactory, Piece.J, Rotate.Reverse, PositionLimit.OddX, 0L, 0, 1)),
// singletonList(create(minoFactory, Piece.Z, Rotate.Spawn, PositionLimit.EvenX, 0L, 2, 3)),
// singletonList(create(minoFactory, Piece.S, Rotate.Left, PositionLimit.OddX, 1024L, 0, 3)),
// singletonList(create(minoFactory, Piece.Z, Rotate.Left, PositionLimit.EvenX, 1024L, 0, 3)),
// singletonList(create(minoFactory, Piece.T, Rotate.Spawn, PositionLimit.OddX, 0L, 0, 1)),
// singletonList(create(minoFactory, Piece.T, Rotate.Reverse, PositionLimit.EvenX, 0L, 2, 3))
// );
// CrossBuilder crossBuilder = new CrossBuilder(lists, FieldFactory.createField(maxClearLine), maxClearLine);
// List<List<OperationWithKey>> lists1 = crossBuilder.create();
// System.out.println(lists1.size());
// List<List<OperationWithKey>> search = new Search(FieldFactory.createField(4), Arrays.asList(
// create(minoFactory, Piece.O, Rotate.Spawn, PositionLimit.NoLimit, 0L, 0, 1),
// create(minoFactory, Piece.O, Rotate.Spawn, PositionLimit.NoLimit, 0L, 2, 3),
// create(minoFactory, Piece.I, Rotate.Right, PositionLimit.NoLimit, 0L, 0, 3),
// create(minoFactory, Piece.L, Rotate.Reverse, PositionLimit.NoLimit, 0L, 0, 1),
// create(minoFactory, Piece.J, Rotate.Reverse, PositionLimit.NoLimit, 0L, 0, 1),
// create(minoFactory, Piece.T, Rotate.Spawn, PositionLimit.NoLimit, 0L, 0, 1),
// create(minoFactory, Piece.T, Rotate.Reverse, PositionLimit.NoLimit, 0L, 2, 3),
// create(minoFactory, Piece.Z, Rotate.Right, PositionLimit.NoLimit, 0x400L, 0, 3),
// create(minoFactory, Piece.S, Rotate.Right, PositionLimit.NoLimit, 0x400L, 0, 3)
// ), maxClearLine).search();
// System.out.println("--");
// for (List<OperationWithKey> operationWithKeys : search) {
// System.out.println(operationWithKeys);
// }
// MinoFactory minoFactory = new MinoFactory();
// List<List<FullLimitedMino>> lists = Arrays.asList(
// singletonList(create(minoFactory, Piece.J, Rotate.Right, PositionLimit.OddX, 0L, 0, 2)),
// singletonList(create(minoFactory, Piece.L, Rotate.Left, PositionLimit.EvenX, 1048576, 0, 4))
// );
// CrossBuilder crossBuilder = new CrossBuilder(lists, FieldFactory.createField("" +
// "__XXXXXXXX" +
// "__XXXXXXXX" +
// "__XXXXXXXX" +
// "__XXXXXXXX"
// ), maxClearLine);
// List<List<OperationWithKey>> lists1 = crossBuilder.create();
// for (List<OperationWithKey> operationWithKeys : lists1) {
// System.out.println(operationWithKeys);
// }
// System.out.println(lists1.size());
stopwatch.stop();
System.out.println(stopwatch.toMessage(TimeUnit.MILLISECONDS));
}
use of common.tetfu.TetfuElement in project solution-finder by knewjade.
the class OneFumenParser method createTetfuElement.
private TetfuElement createTetfuElement(Field initField, BlockField blockField, String comment, int maxClearLine) {
ColoredField coloredField = createInitColoredField(initField, maxClearLine);
for (Piece piece : Piece.values()) {
Field target = blockField.get(piece);
ColorType colorType = this.colorConverter.parseToColorType(piece);
fillInField(coloredField, colorType, target, maxClearLine);
}
return new TetfuElement(coloredField, ColorType.Empty, Rotate.Reverse, 0, 0, comment);
}
use of common.tetfu.TetfuElement in project solution-finder by knewjade.
the class OneFumenParser method parse.
@Override
public String parse(List<MinoOperationWithKey> operations, Field field, int maxClearLine) {
// BlockField を生成
BlockField blockField = createBlockField(operations, maxClearLine);
// パターンを表す名前 を生成
String blocksName = operations.stream().map(OperationWithKey::getPiece).map(Piece::getName).collect(Collectors.joining());
// テト譜1ページを作成
TetfuElement tetfuElement = createTetfuElement(field, blockField, blocksName, maxClearLine);
Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
return tetfu.encode(Collections.singletonList(tetfuElement));
}
Aggregations