Search in sources :

Example 1 with ColorConverter

use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.

the class SequenceFumenParser method parse.

@Override
public String parse(List<MinoOperationWithKey> operations, Field field, int maxClearLine) {
    Operations operations2 = OperationTransform.parseToOperations(field, operations, maxClearLine);
    List<? extends Operation> operationsList = operations2.getOperations();
    // ブロック順に変換
    List<Piece> pieceList = operationsList.stream().map(Operation::getPiece).collect(Collectors.toList());
    // テト譜を作成
    String quiz = Tetfu.encodeForQuiz(pieceList);
    ArrayList<TetfuElement> tetfuElements = new ArrayList<>();
    // 最初のelement
    Operation firstKey = operationsList.get(0);
    ColorType colorType1 = colorConverter.parseToColorType(firstKey.getPiece());
    ColoredField coloredField = createInitColoredField(field, maxClearLine);
    TetfuElement firstElement = new TetfuElement(coloredField, colorType1, firstKey.getRotate(), firstKey.getX(), firstKey.getY(), quiz);
    tetfuElements.add(firstElement);
    // 2番目以降のelement
    if (1 < operationsList.size()) {
        operationsList.subList(1, operationsList.size()).stream().map(operation -> {
            ColorType colorType = colorConverter.parseToColorType(operation.getPiece());
            return new TetfuElement(colorType, operation.getRotate(), operation.getX(), operation.getY(), quiz);
        }).forEach(tetfuElements::add);
    }
    Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
    return tetfu.encode(tetfuElements);
}
Also used : Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) OperationTransform(common.parser.OperationTransform) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement) ColorConverter(common.tetfu.common.ColorConverter) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Operations(common.datastore.Operations) List(java.util.List) Field(core.field.Field) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) Operation(common.datastore.Operation) ColoredField(common.tetfu.field.ColoredField) ColoredField(common.tetfu.field.ColoredField) ArrayList(java.util.ArrayList) Operation(common.datastore.Operation) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Operations(common.datastore.Operations) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement)

Example 2 with ColorConverter

use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.

the class PercentSettingParser method encodeTetfu.

private List<TetfuPage> encodeTetfu(String encoded) throws FinderParseException {
    MinoFactory minoFactory = new MinoFactory();
    ColorConverter colorConverter = new ColorConverter();
    Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
    String data = Tetfu.removePrefixData(encoded);
    if (data == null)
        throw new FinderParseException("Unsupported tetfu: data=" + encoded);
    return tetfu.decode(data);
}
Also used : FinderParseException(exceptions.FinderParseException) ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) Tetfu(common.tetfu.Tetfu)

Example 3 with ColorConverter

use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.

the class TetfuTest method decode2.

@Test
void decode2() throws Exception {
    String value = "bhzhPexAcFAooMDEPBAAA";
    MinoFactory factory = new MinoFactory();
    ColorConverter converter = new ColorConverter();
    Tetfu tetfu = new Tetfu(factory, converter);
    List<TetfuPage> pages = tetfu.decode(value);
    assertThat(pages).hasSize(1);
    assertThat(pages.get(0)).returns(ColorType.I, TetfuPage::getColorType).returns(Rotate.Spawn, TetfuPage::getRotate).returns(5, TetfuPage::getX).returns(0, TetfuPage::getY).returns("hello", TetfuPage::getComment);
    assertField(ColoredFieldFactory.createColoredField("IIII______"), pages.get(0).getField());
}
Also used : ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 4 with ColorConverter

use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.

the class TetfuTest method encode1.

@Test
void encode1() throws Exception {
    List<TetfuElement> elements = Collections.singletonList(new TetfuElement(ColorType.T, Rotate.Spawn, 5, 0));
    MinoFactory factory = new MinoFactory();
    ColorConverter converter = new ColorConverter();
    Tetfu tetfu = new Tetfu(factory, converter);
    String encode = tetfu.encode(elements);
    assertThat(encode).isEqualTo("vhA1QJ");
}
Also used : ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 5 with ColorConverter

use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.

the class TetfuTest method encode4.

@Test
void encode4() throws Exception {
    MinoFactory factory = new MinoFactory();
    ArrayColoredField field = new ArrayColoredField(Tetfu.TETFU_MAX_HEIGHT);
    field.putMino(factory.create(Piece.I, Rotate.Spawn), 1, 0);
    List<TetfuElement> elements = Collections.singletonList(new TetfuElement(field, ColorType.I, Rotate.Spawn, 5, 0, ""));
    ColorConverter converter = new ColorConverter();
    Tetfu tetfu = new Tetfu(factory, converter);
    String encode = tetfu.encode(elements);
    assertThat(encode).isEqualTo("bhzhPexQJ");
}
Also used : ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) ArrayColoredField(common.tetfu.field.ArrayColoredField) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Aggregations

ColorConverter (common.tetfu.common.ColorConverter)38 MinoFactory (core.mino.MinoFactory)36 LongTest (module.LongTest)18 Test (org.junit.jupiter.api.Test)18 Tetfu (common.tetfu.Tetfu)13 ColoredField (common.tetfu.field.ColoredField)11 ColorType (common.tetfu.common.ColorType)10 FinderParseException (exceptions.FinderParseException)10 Field (core.field.Field)9 Piece (core.mino.Piece)8 Mino (core.mino.Mino)7 Rotate (core.srs.Rotate)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 TetfuPage (common.tetfu.TetfuPage)6 ColoredFieldFactory (common.tetfu.field.ColoredFieldFactory)6 IOException (java.io.IOException)6 Arrays (java.util.Arrays)5 Optional (java.util.Optional)5 BlockField (common.datastore.BlockField)4