use of common.tetfu.common.ColorConverter 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.common.ColorConverter in project solution-finder by knewjade.
the class PathSettingParser method loadTetfu.
private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, PathSettings settings) throws FinderParseException {
// テト譜面のエンコード
List<TetfuPage> decoded = encodeTetfu(data);
// 指定されたページを抽出
int page = wrapper.getIntegerOption("page").orElse(1);
TetfuPage tetfuPage = extractTetfuPage(decoded, page);
// コメントの抽出
// 先頭が数字ではない(--clear-line -p *p7のようになる)場合でも、parserはエラーにならない
// データ取得時にOptional.emptyがかえるだけ
String comment = "--clear-line " + tetfuPage.getComment();
List<String> splitComment = Arrays.stream(comment.split(" ")).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
// コマンド引数を配列に変換
String[] commentArgs = new String[splitComment.size()];
splitComment.toArray(commentArgs);
// オプションとして読み込む
try {
CommandLine commandLineTetfu = parseToCommandLine(options, parser, commentArgs);
CommandLineWrapper newWrapper = new NormalCommandLineWrapper(commandLineTetfu);
// 削除ラインが読み取れればOK
newWrapper.getIntegerOption("clear-line");
wrapper = new PriorityCommandLineWrapper(Arrays.asList(wrapper, newWrapper));
} catch (FinderParseException ignore) {
}
// 固定ピースの指定があるか
Optional<Boolean> reservedOption = wrapper.getBoolOption("reserved");
reservedOption.ifPresent(settings::setReserved);
// 最大削除ラインの設定
Optional<Integer> maxClearLineOption = wrapper.getIntegerOption("clear-line");
maxClearLineOption.ifPresent(settings::setMaxClearLine);
// フィールドを設定
ColoredField coloredField = tetfuPage.getField();
if (tetfuPage.isPutMino()) {
ColorType colorType = tetfuPage.getColorType();
Rotate rotate = tetfuPage.getRotate();
int x = tetfuPage.getX();
int y = tetfuPage.getY();
ColorConverter colorConverter = new ColorConverter();
Mino mino = new Mino(colorConverter.parseToBlock(colorType), rotate);
coloredField.putMino(mino, x, y);
}
if (settings.isReserved())
settings.setFieldWithReserved(coloredField, settings.getMaxClearLine());
else
settings.setField(coloredField, settings.getMaxClearLine());
return wrapper;
}
use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.
the class PercentSettingParser method loadTetfu.
private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, PercentSettings settings) throws FinderParseException {
// テト譜面のエンコード
List<TetfuPage> decoded = encodeTetfu(data);
// 指定されたページを抽出
int page = wrapper.getIntegerOption("page").orElse(1);
TetfuPage tetfuPage = extractTetfuPage(decoded, page);
// コメントの抽出
// 先頭が数字ではない(--clear-line -p *p7のようになる)場合でも、parserはエラーにならない
// データ取得時にOptional.emptyがかえるだけ
String comment = "--clear-line " + tetfuPage.getComment();
List<String> splitComment = Arrays.stream(comment.split(" ")).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
// コマンド引数を配列に変換
String[] commentArgs = new String[splitComment.size()];
splitComment.toArray(commentArgs);
// オプションとして読み込む
try {
CommandLine commandLineTetfu = parseToCommandLine(options, parser, commentArgs);
CommandLineWrapper newWrapper = new NormalCommandLineWrapper(commandLineTetfu);
// 削除ラインが読み取れればOK
newWrapper.getIntegerOption("clear-line");
wrapper = new PriorityCommandLineWrapper(Arrays.asList(wrapper, newWrapper));
} catch (FinderParseException ignore) {
}
// 最大削除ラインの設定
Optional<Integer> maxClearLineOption = wrapper.getIntegerOption("clear-line");
maxClearLineOption.ifPresent(settings::setMaxClearLine);
// フィールドを設定
ColoredField coloredField = tetfuPage.getField();
if (tetfuPage.isPutMino()) {
ColorType colorType = tetfuPage.getColorType();
Rotate rotate = tetfuPage.getRotate();
int x = tetfuPage.getX();
int y = tetfuPage.getY();
ColorConverter colorConverter = new ColorConverter();
Mino mino = new Mino(colorConverter.parseToBlock(colorType), rotate);
coloredField.putMino(mino, x, y);
}
settings.setField(coloredField, settings.getMaxClearLine());
return wrapper;
}
use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.
the class TetfuTest method encode7.
@Test
void encode7() throws Exception {
List<TetfuElement> elements = Arrays.asList(TetfuElement.createFieldOnly(ColoredFieldFactory.createColoredField("XXXXLLXXXX")), TetfuElement.createFieldOnly(ColoredFieldFactory.createColoredField("XXXXJJXXXX")));
MinoFactory factory = new MinoFactory();
ColorConverter converter = new ColorConverter();
Tetfu tetfu = new Tetfu(factory, converter);
String encode = tetfu.encode(elements);
assertThat(encode).isEqualTo("bhD8hlD8JeAgHbhD8h0D8JeAAA");
}
use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.
the class TetfuTest method encode5.
@Test
void encode5() 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.Reverse, 6, 0));
ColorConverter converter = new ColorConverter();
Tetfu tetfu = new Tetfu(factory, converter);
String encode = tetfu.encode(elements);
assertThat(encode).isEqualTo("bhzhPehQJ");
}
Aggregations