use of common.datastore.FullOperationWithKey in project solution-finder by knewjade.
the class CrossBuilder method recordResult.
private void recordResult() {
boolean isReuse = true;
for (int index = 0; index < prev.length; index++) {
if (!isReuse || fullLimitedMinos[index] != prev[index]) {
isReuse = false;
List<XField> xFields = cache.get(index);
List<XField> nextXFields = new ArrayList<>();
for (XField xField : xFields) {
Field field = xField.getField();
XHistory xHistory = xField.getxHistory();
FullLimitedMino current = fullLimitedMinos[index];
MinoMask minoMask = current.getMinoMask();
int[] xs = current.getXs();
for (int x : xs) {
Field mask = minoMask.getMinoMask(x);
if (field.canMerge(mask)) {
Field newField = field.freeze(maxClearLine);
newField.merge(mask);
if (perfectValidator.validate(newField, maxClearLine)) {
XHistory newHistory = xHistory.recordAndReturnNew(x);
nextXFields.add(new XField(newField, newHistory));
}
}
}
}
if (index < prev.length - 1) {
cache.set(index + 1, nextXFields);
} else {
for (XField nextXField : nextXFields) {
int[] history = nextXField.getxHistory().getHistory();
assert fullLimitedMinos.length == history.length;
List<MinoOperationWithKey> result = new ArrayList<>();
for (int i = 0, length = history.length; i < length; i++) {
FullLimitedMino limitedMino = fullLimitedMinos[i];
int x = history[i];
Mino mino = limitedMino.getMino();
long deleteKey = limitedMino.getDeleteKey();
long usingKey = limitedMino.getUsingKey();
int lowerY = limitedMino.getLowerY();
MinoOperationWithKey withKey = new FullOperationWithKey(mino, x, deleteKey, usingKey, lowerY);
result.add(withKey);
}
results.add(result);
}
}
prev[index] = fullLimitedMinos[index];
}
}
}
use of common.datastore.FullOperationWithKey in project solution-finder by knewjade.
the class Search method search.
private void search(Field field, int depth) {
if (depth == sets.getDepth()) {
List<OperationWithKey> result = new ArrayList<>();
for (int index = 0, length = fullLimitedMinos.length; index < length; index++) {
FullLimitedMino limitedMino = fullLimitedMinos[index];
int x = xs[index];
Mino mino = limitedMino.getMino();
long deleteKey = limitedMino.getDeleteKey();
long usingKey = limitedMino.getUsingKey();
int lowerY = limitedMino.getLowerY();
OperationWithKey withKey = new FullOperationWithKey(mino, x, deleteKey, usingKey, lowerY);
result.add(withKey);
}
results.add(result);
} else {
FullLimitedMino limitedMino = sets.get(depth);
fullLimitedMinos[depth] = limitedMino;
MinoMask minoMask = limitedMino.getMinoMask();
for (int x : limitedMino.getXs()) {
xs[depth] = x;
Field mask = minoMask.getMinoMask(x);
if (field.canMerge(mask)) {
field.merge(mask);
if (perfectValidator.validate(field, maxClearLine))
search(field, depth + 1);
field.reduce(mask);
}
}
}
}
use of common.datastore.FullOperationWithKey in project solution-finder by knewjade.
the class OperationWithKeyComparatorTest method compareDiffDeleteKey.
@Test
void compareDiffDeleteKey() throws Exception {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
int x = randoms.nextInt(10);
int y = randoms.nextInt(20);
long deleteKey = 0L;
long usingKey = 1049600L;
OperationWithKey operationWithKey1 = new FullOperationWithKey(minoFactory.create(Piece.I, Rotate.Spawn), x, y, deleteKey, usingKey);
Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
Long choose = randoms.key();
while (choose == deleteKey) choose = randoms.key();
OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, choose, usingKey);
// assert is not 0 & sign reversed
OperationWithKeyComparator comparator = new OperationWithKeyComparator();
assertThat(comparator.compare(operationWithKey1, operationWithKey2) * comparator.compare(operationWithKey2, operationWithKey1)).as(operationWithKey2.toString()).isLessThan(0);
}
use of common.datastore.FullOperationWithKey in project solution-finder by knewjade.
the class OperationWithKeyComparatorTest method compare.
@Test
void compare() throws Exception {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
int x = randoms.nextInt(10);
int y = randoms.nextInt(20);
long deleteKey = 0L;
long usingKey = 1049600L;
OperationWithKey operationWithKey1 = new FullOperationWithKey(minoFactory.create(Piece.I, Rotate.Spawn), x, y, deleteKey, usingKey);
Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, deleteKey, usingKey);
OperationWithKeyComparator comparator = new OperationWithKeyComparator();
assertThat(comparator.compare(operationWithKey1, operationWithKey2)).as(operationWithKey1.toString()).isEqualTo(0);
assertThat(comparator.compare(operationWithKey2, operationWithKey1)).as(operationWithKey2.toString()).isEqualTo(0);
}
use of common.datastore.FullOperationWithKey in project solution-finder by knewjade.
the class OperationWithKeyComparatorTest method compareDiffUsingKey.
@Test
void compareDiffUsingKey() throws Exception {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
int x = randoms.nextInt(10);
int y = randoms.nextInt(20);
long deleteKey = 0L;
long usingKey = 1049600L;
OperationWithKey operationWithKey1 = new FullOperationWithKey(minoFactory.create(Piece.I, Rotate.Spawn), x, y, deleteKey, usingKey);
Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
Long choose = randoms.key();
OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, deleteKey, choose);
// assert is 0
OperationWithKeyComparator<OperationWithKey> comparator = new OperationWithKeyComparator<>();
int compare1 = comparator.compare(operationWithKey1, operationWithKey2);
assertThat(compare1).as(operationWithKey1.toString()).isEqualTo(0);
int compare2 = comparator.compare(operationWithKey2, operationWithKey1);
assertThat(compare2).as(operationWithKey2.toString()).isEqualTo(0);
}
Aggregations