use of common.OperationHistory in project solution-finder by knewjade.
the class SimpleSearcherCore method step.
private void step(Candidate<T> candidate, Piece drawn, Piece nextHold, Order order, boolean isLast) {
Field currentField = order.getField();
int max = order.getMaxClearLine();
Set<T> candidateList = candidate.search(currentField, drawn, max);
OperationHistory history = order.getHistory();
for (T action : candidateList) {
Field field = currentField.freeze(max);
Mino mino = minoFactory.create(drawn, action.getRotate());
field.put(mino, action.getX(), action.getY());
int clearLine = field.clearLine();
int maxClearLine = max - clearLine;
if (!validator.validate(field, maxClearLine))
continue;
if (validator.satisfies(field, maxClearLine)) {
Result result = new Result(order, drawn, action, nextHold);
dataPool.addResult(result);
continue;
}
if (isLast)
continue;
OperationHistory nextHistory = history.recordAndReturnNew(drawn, action);
Order nextOrder = new NormalOrder(field, nextHold, maxClearLine, nextHistory);
dataPool.addOrder(nextOrder);
}
}
use of common.OperationHistory in project solution-finder by knewjade.
the class CheckerUsingHold method check.
@Override
public boolean check(Field initField, Piece[] pieces, Candidate<T> candidate, int maxClearLine, int maxDepth) {
Field freeze = initField.freeze(maxClearLine);
int deleteLine = freeze.clearLine();
dataPool.initFirst();
dataPool.addOrder(new DepthOrder(freeze, pieces[0], maxClearLine - deleteLine, maxDepth));
while (!dataPool.getNexts().isEmpty() && dataPool.getResults().isEmpty()) {
Order order = dataPool.getNexts().pollLast();
OperationHistory history = order.getHistory();
assert history != null;
int depth = history.getNextIndex() + 1;
boolean isLast = depth == maxDepth;
if (depth < pieces.length) {
searcherCore.stepWithNext(candidate, pieces[depth], order, isLast);
} else {
searcherCore.stepWhenNoNext(candidate, order, isLast);
}
}
return !dataPool.getResults().isEmpty();
}
Aggregations