Search in sources :

Example 6 with SimpleOperation

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

the class OperationInterpreterTest method parseRandom.

@Test
void parseRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 1; size < 20; size++) {
        List<Operation> operationList = Stream.generate(() -> {
            Piece piece = randoms.block();
            Rotate rotate = randoms.rotate();
            int x = randoms.nextInt(10);
            int y = randoms.nextInt(4);
            return new SimpleOperation(piece, rotate, x, y);
        }).limit(size).collect(Collectors.toList());
        Operations operations = new Operations(operationList);
        String str = OperationInterpreter.parseToString(operations);
        Operations actual = OperationInterpreter.parseToOperations(str);
        assertThat(actual).isEqualTo(operations);
    }
}
Also used : Randoms(lib.Randoms) Rotate(core.srs.Rotate) Piece(core.mino.Piece) SimpleOperation(common.datastore.SimpleOperation) SimpleOperation(common.datastore.SimpleOperation) Operation(common.datastore.Operation) Operations(common.datastore.Operations) Test(org.junit.jupiter.api.Test)

Example 7 with SimpleOperation

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

the class OperationInterpreter method createOperation.

private static Operation createOperation(String strings) {
    String[] split = strings.split(",");
    assert split.length == 4;
    Piece piece = StringEnumTransform.toPiece(split[0].trim());
    Rotate rotate = StringEnumTransform.toRotate(split[1].trim());
    int x = Integer.valueOf(split[2].trim());
    int y = Integer.valueOf(split[3].trim());
    return new SimpleOperation(piece, rotate, x, y);
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) SimpleOperation(common.datastore.SimpleOperation)

Example 8 with SimpleOperation

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

the class ActionParserTest method parseToOperation.

@Test
void parseToOperation() throws Exception {
    for (Piece piece : Piece.values()) {
        for (Rotate rotate : Rotate.values()) {
            for (int y = 0; y < 24; y++) {
                for (int x = 0; x < 10; x++) {
                    int value = ActionParser.parseToInt(piece, rotate, x, y);
                    assertThat(ActionParser.parseToOperation(value)).isEqualTo(new SimpleOperation(piece, rotate, x, y));
                }
            }
        }
    }
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) SimpleOperation(common.datastore.SimpleOperation) Test(org.junit.jupiter.api.Test)

Example 9 with SimpleOperation

use of common.datastore.SimpleOperation 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 10 with SimpleOperation

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

the class OperationComparatorTest method compareDiffBlock.

@Test
void compareDiffBlock() throws Exception {
    SimpleOperation operation1 = new SimpleOperation(Piece.S, Rotate.Spawn, 0, 1);
    Operation operation2 = createNewOperation(Piece.J, Rotate.Spawn, 7, 1);
    // assert is not 0 & sign reversed
    OperationComparator comparator = new OperationComparator();
    assertThat(comparator.compare(operation1, operation2) * comparator.compare(operation2, operation1)).isLessThan(0);
}
Also used : SimpleOperation(common.datastore.SimpleOperation) SimpleOperation(common.datastore.SimpleOperation) Operation(common.datastore.Operation) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleOperation (common.datastore.SimpleOperation)11 Operation (common.datastore.Operation)8 Test (org.junit.jupiter.api.Test)8 Piece (core.mino.Piece)6 Rotate (core.srs.Rotate)5 Randoms (lib.Randoms)2 Operations (common.datastore.Operations)1 Action (common.datastore.action.Action)1 MinimalAction (common.datastore.action.MinimalAction)1 Order (common.datastore.order.Order)1 ArrayList (java.util.ArrayList)1