use of core.action.candidate.LockedCandidate 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);
}
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateUsingHoldTest method testMultiPath1.
@Test
void testMultiPath1() throws Exception {
// Field
String marks = "" + "X________X" + "XX__XX__XX" + "XX__XX__XX" + "";
Field field = FieldFactory.createField(marks);
int maxClearLine = 3;
int maxDepth = 4;
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
// Set test case
List<Piece> pieces = Arrays.asList(J, L, S, Z);
int expectedCount = 4;
// Execute
List<Result> results = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
assertThat(results).as(pieces.toString()).hasSize(expectedCount);
// Check result
for (Result result : results) assertResult(result, field, maxClearLine, reachable, pieces);
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateUsingHoldTest method testLong9.
@Test
void testLong9() throws Exception {
List<Pair<List<Piece>, Integer>> testCases = new ArrayList<Pair<List<Piece>, Integer>>() {
{
add(new Pair<>(Arrays.asList(I, S, Z, T, J, I, S, Z, S, Z), 29));
add(new Pair<>(Arrays.asList(T, S, L, I, Z, J, L, O, O, S), 49));
add(new Pair<>(Arrays.asList(L, Z, S, J, Z, Z, Z, I, T, T), 40));
// PCF: 106
add(new Pair<>(Arrays.asList(T, T, S, S, Z, Z, L, L, J, J), 107));
add(new Pair<>(Arrays.asList(O, S, O, S, Z, L, Z, L, I, I), 3));
// PCF: 112
add(new Pair<>(Arrays.asList(J, I, T, O, L, S, I, T, Z, O), 113));
add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L, L), 82));
add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L), 36));
// PCF: 16
add(new Pair<>(Arrays.asList(Z, S, T, I, O, J, L, Z, S), 17));
add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L), 36));
}
};
// Field
String marks = "" + "__________" + "X_________" + "X_________" + "XX________" + "";
Field field = FieldFactory.createField(marks);
int maxClearLine = 4;
int maxDepth = 9;
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
for (Pair<List<Piece>, Integer> testCase : testCases) {
// Set test case
List<Piece> pieces = testCase.getKey();
int expectedCount = testCase.getValue();
// Execute
List<Result> results = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
assertThat(results).as(pieces.toString()).hasSize(expectedCount);
// Check result
for (Result result : results) assertResult(result, field, maxClearLine, reachable, pieces);
}
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateUsingHoldTest method testCaseList.
@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testCaseList(Pieces pieces, int expectedCount) throws Exception {
// Field
int maxClearLine = 4;
int maxDepth = 10;
Field field = FieldFactory.createField(maxClearLine);
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
// Set test case
List<Piece> piecesList = pieces.getPieces();
// Execute
List<Result> results = checkmate.search(field, piecesList, candidate, maxClearLine, maxDepth);
assertThat(results).as(piecesList.toString()).hasSize(expectedCount);
// Check result
for (Result result : results) assertResult(result, field, maxClearLine, reachable, piecesList);
}
Aggregations