use of core.srs.Rotate in project solution-finder by knewjade.
the class AllSeparableMinoFactory method create.
public Set<SeparableMino> create() {
HashSet<SeparableMino> pieces = new HashSet<>();
HashSet<Mino> createdCheckSet = new HashSet<>();
for (Piece piece : Piece.values()) {
for (Rotate originRotate : Rotate.values()) {
Rotate rotate = minoShifter.createTransformedRotate(piece, originRotate);
Mino mino = minoFactory.create(piece, rotate);
// 追加済みかチェック
if (createdCheckSet.contains(mino))
continue;
createdCheckSet.add(mino);
// ミノの高さを計算
int minoHeight = mino.getMaxY() - mino.getMinY() + 1;
// フィールドの高さ以上にミノを使う場合はおけない
if (fieldHeight < minoHeight)
continue;
// 行候補をリストにする
ArrayList<Integer> lineIndexes = getLineIndexes(fieldHeight);
// リストアップ
ArrayList<SeparableMino> piecesEachMino = generatePiecesEachMino(mino, lineIndexes, minoHeight);
// 追加
pieces.addAll(piecesEachMino);
}
}
return pieces;
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class ActionParser method parseToOperation.
static Operation parseToOperation(int value) {
int x = value % 10;
value /= 10;
int y = value % 24;
value /= 24;
Rotate rotate = Rotate.getRotate(value % 4);
value /= 4;
Piece piece = Piece.getBlock(value);
return new SimpleOperation(piece, rotate, x, y);
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class SlideXOperationWithKeyTest method get.
@Test
void get() {
Randoms randoms = new Randoms();
for (int count = 0; count < 10000; count++) {
Piece piece = randoms.block();
Rotate rotate = randoms.rotate();
Mino mino = new Mino(piece, rotate);
int x = randoms.nextInt(0, 10);
int y = randoms.nextInt(0, 10);
long usingKey = randoms.key();
long deleteKey = randoms.key();
FullOperationWithKey operationWithKey = new FullOperationWithKey(mino, x, y, deleteKey, usingKey);
int slide = randoms.nextInt(4);
SlideXOperationWithKey key = new SlideXOperationWithKey(operationWithKey, slide);
assertThat(key).returns(x + slide, SlideXOperationWithKey::getX).returns(y, SlideXOperationWithKey::getY).returns(deleteKey, SlideXOperationWithKey::getNeedDeletedKey).returns(usingKey, SlideXOperationWithKey::getUsingKey);
}
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class HarddropCandidateTest method testRandom.
@Test
void testRandom() throws Exception {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new PassedMinoShifter();
HarddropCandidate candidate = new HarddropCandidate(minoFactory, minoShifter);
for (int count = 0; count < 10000; count++) {
int randomHeight = randoms.nextIntClosed(2, 12);
int numOfMinos = randoms.nextIntClosed(4, randomHeight * 10 / 4 - 1);
Field field = randoms.field(randomHeight, numOfMinos);
int clearLine = field.clearLine();
int height = randomHeight - clearLine;
Piece piece = randoms.block();
Set<Action> actions = candidate.search(field, piece, height);
for (Rotate rotate : minoShifter.getUniqueRotates(piece)) {
Coordinates.walk(minoFactory.create(piece, rotate), height).map(coordinate -> MinimalAction.create(coordinate.x, coordinate.y, rotate)).forEach(action -> {
int x = action.getX();
int y = action.getY();
Mino mino = minoFactory.create(piece, action.getRotate());
boolean canPut = field.isOnGround(mino, x, y) && IntStream.range(y, height - mino.getMinY()).allMatch(up -> field.canPut(mino, x, up));
assertThat(actions.contains(action)).isEqualTo(canPut);
});
}
}
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class LockedCandidateTest method testRandom.
@Test
void testRandom() throws Exception {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new PassedMinoShifter();
MinoRotation minoRotation = new MinoRotation();
for (int count = 0; count < 10000; count++) {
int randomHeight = randoms.nextIntClosed(2, 12);
int numOfMinos = randoms.nextIntClosed(4, randomHeight * 10 / 4 - 1);
Field field = randoms.field(randomHeight, numOfMinos);
int height = randomHeight - field.clearLine();
Piece piece = randoms.block();
LockedCandidate candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
Set<Action> actions = candidate.search(field, piece, height);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
for (Rotate rotate : Rotate.values()) {
Coordinates.walk(minoFactory.create(piece, rotate), height).map(coordinate -> MinimalAction.create(coordinate.x, coordinate.y, rotate)).forEach(action -> {
int x = action.getX();
int y = action.getY();
Mino mino = minoFactory.create(piece, action.getRotate());
if (actions.contains(action)) {
// おける
assertThat(field.canPut(mino, x, y)).isTrue();
assertThat(field.isOnGround(mino, x, y)).isTrue();
assertThat(reachable.checks(field, mino, x, y, height)).isTrue();
} else {
// おけない
boolean canPut = field.canPut(mino, x, y) && field.isOnGround(mino, x, y) && reachable.checks(field, mino, x, y, height);
assertThat(canPut).isFalse();
}
});
}
}
}
Aggregations