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);
}
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);
}
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());
}
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");
}
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");
}
Aggregations