Search in sources :

Example 1 with OperationHistory

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);
    }
}
Also used : Order(common.datastore.order.Order) NormalOrder(common.datastore.order.NormalOrder) Field(core.field.Field) NormalOrder(common.datastore.order.NormalOrder) Mino(core.mino.Mino) OperationHistory(common.OperationHistory) Result(common.datastore.Result)

Example 2 with OperationHistory

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();
}
Also used : Order(common.datastore.order.Order) DepthOrder(common.datastore.order.DepthOrder) Field(core.field.Field) DepthOrder(common.datastore.order.DepthOrder) OperationHistory(common.OperationHistory)

Aggregations

OperationHistory (common.OperationHistory)2 Order (common.datastore.order.Order)2 Field (core.field.Field)2 Result (common.datastore.Result)1 DepthOrder (common.datastore.order.DepthOrder)1 NormalOrder (common.datastore.order.NormalOrder)1 Mino (core.mino.Mino)1