use of common.pattern.PatternGenerator in project solution-finder by knewjade.
the class CheckerUsingHoldInvokerTest method testSearch11.
@ParameterizedTest
@ArgumentsSource(InvokerTestCase.class)
void testSearch11(IntFunction<ConcurrentCheckerInvoker> invokerGenerator) throws Exception {
PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p5");
int maxClearLine = 4;
int maxDepth = 4;
String marks = "" + "XXXX______" + "XXXXXXXXXX" + "XXXXX_____" + "XXXX_____X" + "";
ConcurrentCheckerInvoker invoker = invokerGenerator.apply(maxClearLine);
AnalyzeTree tree = runTestCase(invoker, marks, blocksGenerator, maxClearLine, maxDepth);
// Source: myself 20170707
assertThat(tree.getSuccessPercent()).isEqualTo(1758 / 2520.0);
}
use of common.pattern.PatternGenerator in project solution-finder by knewjade.
the class CheckerUsingHoldInvokerTest method testSearch2BT4_5.
@ParameterizedTest
@ArgumentsSource(InvokerTestCase.class)
void testSearch2BT4_5(IntFunction<ConcurrentCheckerInvoker> invokerGenerator) throws Exception {
PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p7");
int maxClearLine = 6;
int maxDepth = 7;
String marks = "" + "XX________" + "XX________" + "XXX______X" + "XXXXXXX__X" + "XXXXXX___X" + "XXXXXXX_XX" + "";
ConcurrentCheckerInvoker invoker = invokerGenerator.apply(maxClearLine);
AnalyzeTree tree = runTestCase(invoker, marks, blocksGenerator, maxClearLine, maxDepth);
// Source: myself 20170415
assertThat(tree.getSuccessPercent()).isEqualTo(5038 / 5040.0);
}
use of common.pattern.PatternGenerator in project solution-finder by knewjade.
the class Verify method patterns.
public static PatternGenerator patterns(List<String> patterns, int depth) throws FinderInitializeException {
PatternGenerator generator = patterns(patterns);
int piecesDepth = generator.getDepth();
if (piecesDepth < depth)
throw new FinderInitializeException(String.format("Should specify equal to or more than %d pieces: CurrentPieces=%d", depth, piecesDepth));
return generator;
}
use of common.pattern.PatternGenerator in project solution-finder by knewjade.
the class DevRandomEntryPoint method run.
@Override
public void run() throws FinderException {
PatternGenerator generator = createBlockGenerator(pattern);
List<Pieces> blocks = generator.blocksStream().collect(Collectors.toList());
int index = new Random().nextInt(blocks.size());
Pieces selected = blocks.get(index);
String quiz = Tetfu.encodeForQuiz(selected.getPieces());
MinoFactory minoFactory = new MinoFactory();
ColorConverter converter = new ColorConverter();
ColoredField coloredField = getTetfu(minoFactory, converter);
Tetfu tetfu = new Tetfu(minoFactory, converter);
TetfuElement element = new TetfuElement(coloredField, quiz);
String encode = tetfu.encode(Collections.singletonList(element));
System.out.println("v115@" + encode);
}
use of common.pattern.PatternGenerator in project solution-finder by knewjade.
the class MoveEntryPoint method run.
@Override
public void run() throws FinderException {
output("# Setup Field");
// Setup field
Field field = settings.getField();
Verify.field(field);
int maxClearLine = settings.getMaxClearLine();
output(FieldView.toString(field, maxClearLine));
// Setup max depth
// パフェに必要なミノ数
int maxDepth = Verify.maxDepth(field, maxClearLine);
output();
// ========================================
output("Searching patterns:");
// Setup patterns
List<String> patterns = settings.getPatterns();
PatternGenerator generator = Verify.patterns(patterns);
// Output patterns
for (String pattern : patterns) output(" " + pattern);
output();
// ========================================
// baseファイル
MyFile base = new MyFile(settings.getOutputBaseFilePath());
base.mkdirs();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
ColorConverter colorConverter = new ColorConverter();
PerfectValidator perfectValidator = new PerfectValidator();
PutterNoHold<Action> putter = new PutterNoHold<>(minoFactory, perfectValidator);
output("# Calculate");
try (BufferedWriter bw = base.newBufferedWriter()) {
List<Pieces> pieces = generator.blocksStream().collect(Collectors.toList());
for (Pieces piece : pieces) {
String using = piece.blockStream().map(Piece::getName).collect(Collectors.joining());
output(" -> " + using);
TreeSet<Order> first = putter.first(field, piece.getPieceArray(), new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine), maxClearLine, maxDepth);
for (Order order : first) {
Stream<Operation> operationStream = order.getHistory().getOperationStream();
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, new Operations(operationStream), minoFactory, maxClearLine);
BlockField blockField = OperationTransform.parseToBlockField(operationWithKeys, minoFactory, maxClearLine);
String encodeColor = encodeColor(field, minoFactory, colorConverter, blockField);
String encodeGray = encodeGray(order.getField(), minoFactory, colorConverter);
bw.write(String.format("%s,%s,%s", using, encodeColor, encodeGray));
bw.newLine();
}
}
bw.flush();
} catch (IOException e) {
throw new FinderExecuteException("Failed to output file", e);
}
}
Aggregations