Search in sources :

Example 1 with MinimalAction

use of common.datastore.action.MinimalAction in project solution-finder by knewjade.

the class MinoTransform method enumerateOthers.

List<Action> enumerateOthers(int x, int y, Rotate rotate) {
    List<Action> actions = new ArrayList<>();
    int currentRotateIndex = rotate.getNumber();
    int newX = x + this.offsetsX[currentRotateIndex];
    int newY = y + offsetsY[currentRotateIndex];
    for (Rotate prevRotate : reverseMap.get(rotate)) {
        int index = prevRotate.getNumber();
        MinimalAction action = MinimalAction.create(newX - this.offsetsX[index], newY - offsetsY[index], prevRotate);
        actions.add(action);
    }
    return actions;
}
Also used : Action(common.datastore.action.Action) MinimalAction(common.datastore.action.MinimalAction) MinimalAction(common.datastore.action.MinimalAction) Rotate(core.srs.Rotate) ArrayList(java.util.ArrayList)

Example 2 with MinimalAction

use of common.datastore.action.MinimalAction in project solution-finder by knewjade.

the class OperationHistoryTest method random.

@Test
void random() throws ExecutionException, InterruptedException {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 1000; count++) {
        int size = randoms.nextInt(1, 10);
        ArrayList<Operation> operations = new ArrayList<>();
        OperationHistory history = new OperationHistory(size);
        for (int index = 0; index < size; index++) {
            Piece piece = randoms.block();
            Rotate rotate = randoms.rotate();
            int y = randoms.nextInt(4);
            int x = randoms.nextInt(10);
            MinimalAction action = MinimalAction.create(x, y, rotate);
            history = history.recordAndReturnNew(piece, action);
            operations.add(new SimpleOperation(piece, rotate, x, y));
        }
        List<Operation> actual = history.getOperationStream().collect(Collectors.toList());
        assertThat(actual).isEqualTo(operations);
    }
}
Also used : Randoms(lib.Randoms) MinimalAction(common.datastore.action.MinimalAction) Rotate(core.srs.Rotate) Piece(core.mino.Piece) ArrayList(java.util.ArrayList) SimpleOperation(common.datastore.SimpleOperation) SimpleOperation(common.datastore.SimpleOperation) Operation(common.datastore.Operation) Test(org.junit.jupiter.api.Test)

Example 3 with MinimalAction

use of common.datastore.action.MinimalAction in project solution-finder by knewjade.

the class PassedMinoShifterTest method createTransformedAction.

@Test
void createTransformedAction() {
    Randoms randoms = new Randoms();
    PassedMinoShifter minoShifter = new PassedMinoShifter();
    for (int count = 0; count < 10000; count++) {
        Piece piece = randoms.block();
        Rotate rotate = randoms.rotate();
        int x = randoms.nextInt(10);
        int y = randoms.nextInt(0, 12);
        MinimalAction action = MinimalAction.create(x, y, rotate);
        Action actualAction = minoShifter.createTransformedAction(piece, action);
        assertThat(actualAction).isEqualTo(action);
    }
}
Also used : Randoms(lib.Randoms) Action(common.datastore.action.Action) MinimalAction(common.datastore.action.MinimalAction) MinimalAction(common.datastore.action.MinimalAction) Rotate(core.srs.Rotate) Test(org.junit.jupiter.api.Test)

Aggregations

MinimalAction (common.datastore.action.MinimalAction)3 Rotate (core.srs.Rotate)3 Action (common.datastore.action.Action)2 ArrayList (java.util.ArrayList)2 Randoms (lib.Randoms)2 Test (org.junit.jupiter.api.Test)2 Operation (common.datastore.Operation)1 SimpleOperation (common.datastore.SimpleOperation)1 Piece (core.mino.Piece)1