use of common.datastore.Result 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.datastore.Result in project solution-finder by knewjade.
the class ResultHelperTest method uniquify.
@Test
void uniquify() {
Result result1 = new Result(new DummyOrder(Piece.O), Piece.I, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L);
Result result2 = new Result(new DummyOrder(Piece.O), Piece.I, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L);
Result result3 = new Result(new DummyOrder(Piece.O), Piece.I, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L);
List<Result> uniquify = ResultHelper.uniquify(Arrays.asList(result1, result2, result3));
assertThat(uniquify).hasSize(1);
}
use of common.datastore.Result in project solution-finder by knewjade.
the class ResultHelperTest method uniquifyDiff.
@Test
void uniquifyDiff() {
List<Result> results = Arrays.asList(new Result(new DummyOrder(Piece.O), Piece.I, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L), new Result(new DummyOrder(Piece.O), Piece.S, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L), new Result(new DummyOrder(Piece.O), Piece.I, MinimalAction.create(1, 1, Rotate.Spawn), Piece.L), new Result(new DummyOrder(Piece.O), Piece.I, MinimalAction.create(0, 2, Rotate.Spawn), Piece.L), new Result(new DummyOrder(Piece.O), Piece.I, MinimalAction.create(0, 1, Rotate.Left), Piece.L), new Result(new DummyOrder(Piece.O), Piece.I, MinimalAction.create(0, 1, Rotate.Left), Piece.J), new Result(new DummyOrder(Piece.T), Piece.I, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L));
List<Result> uniquify = ResultHelper.uniquify(results);
// 重複チェックは最終操作に依存するため、orderの影響をうけない
assertThat(uniquify).hasSize(6);
}
use of common.datastore.Result in project solution-finder by knewjade.
the class ResultPCFComparatorTest method compareDiffLastBlock.
@Test
void compareDiffLastBlock() throws Exception {
Result result1 = new Result(DUMMY_ORDER, Piece.I, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L);
Result result2 = new Result(DUMMY_ORDER, Piece.J, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L);
ResultPCFComparator comparator = new ResultPCFComparator();
// assert is not 0 & sign reversed
assertThat(comparator.compare(result1, result2) * comparator.compare(result2, result1)).as(result1.toString()).isLessThan(0);
}
use of common.datastore.Result in project solution-finder by knewjade.
the class ResultPCFComparatorTest method compare1.
@Test
void compare1() throws Exception {
Result result1 = new Result(DUMMY_ORDER, Piece.I, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L);
Result result2 = new Result(DUMMY_ORDER, Piece.I, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L);
ResultPCFComparator comparator = new ResultPCFComparator();
assertThat(comparator.compare(result1, result2)).as(result1.toString()).isEqualTo(0);
assertThat(comparator.compare(result2, result1)).as(result1.toString()).isEqualTo(0);
}
Aggregations