use of common.datastore.order.Order in project solution-finder by knewjade.
the class CheckmateUsingHold method search.
@Override
public List<Result> search(Field initField, Piece[] pieces, Candidate<T> candidate, int maxClearLine, int maxDepth) {
Field freeze = initField.freeze(maxClearLine);
int deleteLine = freeze.clearLine();
dataPool.initFirst(new NormalOrder(freeze, pieces[0], maxClearLine - deleteLine, maxDepth));
for (int depth = 1; depth <= maxDepth; depth++) {
TreeSet<Order> orders = dataPool.getNexts();
dataPool.initEachDepth();
boolean isLast = depth == maxDepth;
if (depth < pieces.length) {
Piece drawn = pieces[depth];
for (int count = 0, size = orders.size(); count < size; count++) {
Order order = orders.pollFirst();
searcherCore.stepWithNext(candidate, drawn, order, isLast);
}
} else {
for (int count = 0, size = orders.size(); count < size; count++) {
Order order = orders.pollFirst();
searcherCore.stepWhenNoNext(candidate, order, isLast);
}
}
}
return dataPool.getResults();
}
use of common.datastore.order.Order in project solution-finder by knewjade.
the class PutterUsingHold method first.
public TreeSet<Order> first(Field initField, Piece[] headPieces, Candidate<T> candidate, int maxClearLine, int maxDepth) {
Field freeze = initField.freeze(maxClearLine);
int deleteLine = freeze.clearLine();
dataPool.initFirst(new NormalOrder(freeze, headPieces[0], maxClearLine - deleteLine, maxDepth));
int firstMaxDepth = headPieces.length;
for (int depth = 1; depth <= firstMaxDepth; depth++) {
TreeSet<Order> orders = dataPool.getNexts();
dataPool.initEachDepth();
boolean isLast = depth == maxDepth;
if (depth < headPieces.length) {
Piece drawn = headPieces[depth];
for (int count = 0, size = orders.size(); count < size; count++) {
Order order = orders.pollFirst();
searcherCore.stepWithNext(candidate, drawn, order, isLast);
}
} else {
for (int count = 0, size = orders.size(); count < size; count++) {
Order order = orders.pollFirst();
searcherCore.stepWhenNoNext(candidate, order, isLast);
}
}
}
return dataPool.getNexts();
}
use of common.datastore.order.Order 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();
}
use of common.datastore.order.Order in project solution-finder by knewjade.
the class CheckmateNoHold method search.
@Override
public List<Result> search(Field initField, Piece[] pieces, Candidate<T> candidate, int maxClearLine, int maxDepth) {
Field freeze = initField.freeze(maxClearLine);
int deleteLine = freeze.clearLine();
dataPool.initFirst(new NormalOrder(freeze, null, maxClearLine - deleteLine, maxDepth));
for (int depth = 0; depth < maxDepth; depth++) {
TreeSet<Order> orders = dataPool.getNexts();
dataPool.initEachDepth();
assert depth < pieces.length;
boolean isLast = depth == maxDepth - 1;
for (int count = 0, size = orders.size(); count < size; count++) {
Order order = orders.pollFirst();
searcherCore.stepWithNextNoHold(candidate, pieces[depth], order, isLast);
}
}
return dataPool.getResults();
}
use of common.datastore.order.Order in project solution-finder by knewjade.
the class CheckmateNoHoldReuse method search.
@Override
public List<Result> search(Field initFieldOrigin, Piece[] pieces, Candidate<T> candidate, int maxClearLine, int maxDepth) {
Field initField = initFieldOrigin.freeze(maxClearLine);
int deleteLine = initField.clearLine();
int height = maxClearLine - deleteLine;
TreeSet<Order> orders = new TreeSet<>();
// 最初の探索開始depthとordersを調整
int startDepth;
if (!equalsField(lastField, initField) || lastPieces == null) {
// mementoの初期化
// 初めから
memento = new ArrayList<>();
orders.add(new NormalOrder(initField, null, height, maxDepth));
startDepth = 0;
memento.add(new TreeSet<>(orders));
} else {
int reuseIndex = -1;
for (int index = 0; index < maxDepth; index++) {
if (lastPieces[index] == pieces[index])
reuseIndex = index;
else
break;
}
if (reuseIndex < 0) {
memento = new ArrayList<>();
orders.add(new NormalOrder(initField, null, height, maxDepth));
startDepth = 0;
memento.add(new TreeSet<>(orders));
} else if (reuseIndex == maxDepth - 1) {
return dataPool.getResults();
} else {
orders.addAll(memento.get(reuseIndex));
startDepth = reuseIndex;
memento = memento.subList(0, reuseIndex + 1);
}
}
dataPool.resetResults();
for (int depth = startDepth; depth < maxDepth; depth++) {
dataPool.initEachDepth();
assert depth < pieces.length;
boolean isLast = depth == maxDepth - 1;
for (int count = 0, size = orders.size(); count < size; count++) {
Order order = orders.pollFirst();
searcherCore.stepWithNextNoHold(candidate, pieces[depth], order, isLast);
}
orders = dataPool.getNexts();
memento.add(new TreeSet<>(orders));
}
lastPieces = pieces;
lastField = initField;
return dataPool.getResults();
}
Aggregations