use of entry.searching_pieces.NormalEnumeratePieces in project solution-finder by knewjade.
the class PercentEntryPoint method run.
@Override
public void run() throws FinderException {
output("# Setup Field");
// Setup field
Field field = settings.getField();
Verify.field(field);
// Setup max clear line
int maxClearLine = settings.getMaxClearLine();
Verify.maxClearLineUnder12(maxClearLine);
// Output field
output(FieldView.toString(field, maxClearLine));
// Setup max depth
// パフェに必要なミノ数
int maxDepth = Verify.maxDepth(field, maxClearLine);
output();
// ========================================
// Output user-defined
output("# Initialize / User-defined");
output("Max clear lines: " + maxClearLine);
output("Using hold: " + (settings.isUsingHold() ? "use" : "avoid"));
output("Drop: " + settings.getDropType().name().toLowerCase());
output("Searching patterns:");
// Setup patterns
List<String> patterns = settings.getPatterns();
PatternGenerator generator = Verify.patterns(patterns, maxDepth);
// Output patterns
for (String pattern : patterns) output(" " + pattern);
output();
// ========================================
// Setup core
output("# Initialize / System");
ExecutorService executorService = createExecutorService();
output("Version = " + FinderConstant.VERSION);
output("Necessary Pieces = " + maxDepth);
output();
// ========================================
// Holdができるときは必要なミノ分(maxDepth + 1)だけを取り出す。maxDepth + 1だけないときはブロックの個数をそのまま指定
output("# Enumerate pieces");
int piecesDepth = generator.getDepth();
int popCount = settings.isUsingHold() && maxDepth < piecesDepth ? maxDepth + 1 : maxDepth;
output("Piece pop count = " + popCount);
if (popCount < piecesDepth) {
output();
output("####################################################################");
output("WARNING: Inputted pieces is more than 'necessary blocks'.");
output(" Because reduce unnecessary pieces,");
output(" there is a possibility of getting no expected percentages.");
output("####################################################################");
output();
}
// 探索パターンの列挙
NormalEnumeratePieces normalEnumeratePieces = new NormalEnumeratePieces(generator, maxDepth, settings.isUsingHold());
Set<LongPieces> searchingPieces = normalEnumeratePieces.enumerate();
output("Searching pattern size (duplicate) = " + normalEnumeratePieces.getCounter());
output("Searching pattern size ( no dup. ) = " + searchingPieces.size());
output();
// ========================================
// 探索を行う
output("# Search");
output(" -> Stopwatch start");
Stopwatch stopwatch = Stopwatch.createStartedStopwatch();
ThreadLocal<Candidate<Action>> candidateThreadLocal = createCandidateThreadLocal(settings.getDropType(), maxClearLine);
ThreadLocal<? extends Reachable> reachableThreadLocal = createReachableThreadLocal(settings.getDropType(), maxClearLine);
MinoFactory minoFactory = new MinoFactory();
PercentCore percentCore = new PercentCore(executorService, candidateThreadLocal, settings.isUsingHold(), reachableThreadLocal, minoFactory);
percentCore.run(field, searchingPieces, maxClearLine, maxDepth);
AnalyzeTree tree = percentCore.getResultTree();
List<Pair<Pieces, Boolean>> resultPairs = percentCore.getResultPairs();
stopwatch.stop();
output(" -> Stopwatch stop : " + stopwatch.toMessage(TimeUnit.MILLISECONDS));
output();
// ========================================
// Output tree
output("# Output");
output(tree.show());
output();
// Output failed patterns
int treeDepth = settings.getTreeDepth();
if (piecesDepth < treeDepth)
treeDepth = piecesDepth;
output(String.format("Success pattern tree [Head %d pieces]:", treeDepth));
output(tree.tree(treeDepth));
output("-------------------");
int failedMaxCount = settings.getFailedCount();
// skip if failedMaxCount == 0
if (0 < failedMaxCount) {
output(String.format("Fail pattern (max. %d)", failedMaxCount));
List<Pair<Pieces, Boolean>> failedPairs = resultPairs.stream().filter(pair -> !pair.getValue()).limit(failedMaxCount).collect(Collectors.toList());
outputFailedPatterns(failedPairs);
} else if (failedMaxCount < 0) {
output("Fail pattern (all)");
List<Pair<Pieces, Boolean>> failedPairs = resultPairs.stream().filter(pair -> !pair.getValue()).collect(Collectors.toList());
outputFailedPatterns(failedPairs);
}
output();
// ========================================
output("# Finalize");
if (executorService != null)
executorService.shutdown();
output("done");
}
use of entry.searching_pieces.NormalEnumeratePieces in project solution-finder by knewjade.
the class PercentCoreTest method assertPercentCore.
private void assertPercentCore(Obj obj, double successPercent) throws Exception {
PatternGenerator generator = new LoadedPatternGenerator(obj.patterns);
NormalEnumeratePieces enumeratePieces = new NormalEnumeratePieces(generator, obj.maxDepth, obj.isUsingHold);
Set<LongPieces> blocks = enumeratePieces.enumerate();
Injector injector = Guice.createInjector(new BasicModule(obj.maxClearLine));
Optional<ExecutorService> executorService = obj.isSingleThread ? Optional.empty() : Optional.of(injector.getInstance(ExecutorService.class));
LockedCandidateThreadLocal candidateThreadLocal = injector.getInstance(LockedCandidateThreadLocal.class);
LockedReachableThreadLocal reachableThreadLocal = injector.getInstance(LockedReachableThreadLocal.class);
MinoFactory minoFactory = injector.getInstance(MinoFactory.class);
PercentCore percentCore = getPercentCore(obj, executorService.orElse(null), candidateThreadLocal, reachableThreadLocal, minoFactory);
Field field = FieldFactory.createField(obj.marks);
percentCore.run(field, blocks, obj.maxClearLine, obj.maxDepth);
executorService.ifPresent(ExecutorService::shutdown);
assertThat(percentCore.getResultTree().getSuccessPercent()).isEqualTo(successPercent);
}
Aggregations