use of common.datastore.blocks.Pieces in project solution-finder by knewjade.
the class ConcurrentVisitedTreeTest method random.
@Test
void random() throws SyntaxException {
Randoms randoms = new Randoms();
for (int size = 1; size <= 7; size++) {
PatternGenerator generator = new LoadedPatternGenerator("*p" + size);
ConcurrentVisitedTree tree = new ConcurrentVisitedTree();
Set<LongPieces> success = Collections.synchronizedSet(new HashSet<>());
Set<LongPieces> failed = Collections.synchronizedSet(new HashSet<>());
List<Pieces> piecesList = generator.blocksStream().collect(Collectors.toList());
piecesList.parallelStream().forEach(pieces -> {
boolean flag = randoms.nextBoolean();
List<Piece> blocks = pieces.getPieces();
tree.set(flag, blocks);
LongPieces longPieces = new LongPieces(blocks);
if (flag) {
success.add(longPieces);
} else {
failed.add(longPieces);
}
});
boolean isSucceed = success.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
});
assertThat(isSucceed).isTrue();
boolean isFailed = failed.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
});
assertThat(isFailed).isTrue();
}
}
use of common.datastore.blocks.Pieces in project solution-finder by knewjade.
the class CheckerNoHoldInvokerTest method runTestCase.
private AnalyzeTree runTestCase(ConcurrentCheckerInvoker invoker, Field field, List<Pieces> searchingPieces, int maxClearLine, int maxDepth) throws FinderExecuteException {
List<Pair<Pieces, Boolean>> resultPairs = invoker.search(field, searchingPieces, maxClearLine, maxDepth);
// 結果を集計する
AnalyzeTree tree = new AnalyzeTree();
for (Pair<Pieces, Boolean> resultPair : resultPairs) {
Pieces pieces = resultPair.getKey();
Boolean result = resultPair.getValue();
tree.set(result, pieces);
}
System.out.println(tree.show());
return tree;
}
use of common.datastore.blocks.Pieces in project solution-finder by knewjade.
the class CheckerNoHoldInvokerTest method runTestCase.
private AnalyzeTree runTestCase(ConcurrentCheckerInvoker invoker, String marks, PatternGenerator blocksGenerator, int maxClearLine, int maxDepth) throws FinderExecuteException {
Field field = FieldFactory.createField(marks);
List<Pieces> searchingPieces = blocksGenerator.blocksStream().collect(Collectors.toList());
return runTestCase(invoker, field, searchingPieces, maxClearLine, maxDepth);
}
use of common.datastore.blocks.Pieces 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.datastore.blocks.Pieces 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