Search in sources :

Example 6 with TetfuElement

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);
}
Also used : Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField) ColoredField(common.tetfu.field.ColoredField) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) TetfuElement(common.tetfu.TetfuElement)

Example 7 with TetfuElement

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);
        }
    }
}
Also used : ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement)

Example 8 with TetfuElement

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));
}
Also used : java.util(java.util) Stopwatch(lib.Stopwatch) ColorType(common.tetfu.common.ColorType) OperationWithKeyComparator(common.comparator.OperationWithKeyComparator) common.datastore(common.datastore) DeltaLimitedMino(_implements.parity_based_pack.step1.DeltaLimitedMino) CrossBuilder(_implements.parity_based_pack.step3.CrossBuilder) Tetfu(common.tetfu.Tetfu) FieldView(core.field.FieldView) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) CombinationIterable(common.iterable.CombinationIterable) FieldFactory(core.field.FieldFactory) Piece(core.mino.Piece) EstimateBuilder(_implements.parity_based_pack.step1.EstimateBuilder) PositionLimitParser(_implements.parity_based_pack.step2.PositionLimitParser) Predicate(java.util.function.Predicate) BuildUp(common.buildup.BuildUp) TetfuElement(common.tetfu.TetfuElement) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) TimeUnit(java.util.concurrent.TimeUnit) Field(core.field.Field) Stream(java.util.stream.Stream) OperationWithKeyInterpreter(common.parser.OperationWithKeyInterpreter) ColumnParityLimitation(_implements.parity_based_pack.step1.ColumnParityLimitation) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) ColoredField(common.tetfu.field.ColoredField) Mino(core.mino.Mino) Stopwatch(lib.Stopwatch) Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField) CombinationIterable(common.iterable.CombinationIterable) Piece(core.mino.Piece) DeltaLimitedMino(_implements.parity_based_pack.step1.DeltaLimitedMino) FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) Mino(core.mino.Mino) ColorConverter(common.tetfu.common.ColorConverter) TetfuElement(common.tetfu.TetfuElement)

Example 9 with TetfuElement

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);
}
Also used : BlockField(common.datastore.BlockField) Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField) ColoredField(common.tetfu.field.ColoredField) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) TetfuElement(common.tetfu.TetfuElement)

Example 10 with TetfuElement

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));
}
Also used : OperationWithKey(common.datastore.OperationWithKey) MinoOperationWithKey(common.datastore.MinoOperationWithKey) BlockField(common.datastore.BlockField) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement)

Aggregations

TetfuElement (common.tetfu.TetfuElement)12 Tetfu (common.tetfu.Tetfu)8 ColoredField (common.tetfu.field.ColoredField)7 ColorType (common.tetfu.common.ColorType)6 Field (core.field.Field)6 Piece (core.mino.Piece)6 BlockField (common.datastore.BlockField)5 ColorConverter (common.tetfu.common.ColorConverter)4 MinoFactory (core.mino.MinoFactory)4 MinoOperationWithKey (common.datastore.MinoOperationWithKey)2 ColoredFieldFactory (common.tetfu.field.ColoredFieldFactory)2 Collectors (java.util.stream.Collectors)2 ColumnParityLimitation (_implements.parity_based_pack.step1.ColumnParityLimitation)1 DeltaLimitedMino (_implements.parity_based_pack.step1.DeltaLimitedMino)1 EstimateBuilder (_implements.parity_based_pack.step1.EstimateBuilder)1 FullLimitedMino (_implements.parity_based_pack.step2.FullLimitedMino)1 PositionLimitParser (_implements.parity_based_pack.step2.PositionLimitParser)1 CrossBuilder (_implements.parity_based_pack.step3.CrossBuilder)1 BuildUp (common.buildup.BuildUp)1 OperationWithKeyComparator (common.comparator.OperationWithKeyComparator)1