use of core.srs.MinoRotation in project solution-finder by knewjade.
the class BuildUpTest method existsValidBuildPattern1.
@Test
void existsValidBuildPattern1() throws Exception {
Field field = FieldFactory.createField("" + "_________X" + "_________X");
int maxY = 4;
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxY);
List<MinoOperationWithKey> operationWithKeys = Arrays.asList(new FullOperationWithKey(minoFactory.create(Piece.J, Rotate.Right), 5, 0L, 0L, 0), new FullOperationWithKey(minoFactory.create(Piece.J, Rotate.Reverse), 8, 0L, 0L, 2), new FullOperationWithKey(minoFactory.create(Piece.L, Rotate.Spawn), 7, 0L, 0L, 0), new FullOperationWithKey(minoFactory.create(Piece.S, Rotate.Spawn), 7, 0L, 0L, 1));
boolean exists = BuildUp.existsValidBuildPattern(field, operationWithKeys, maxY, reachable);
assertThat(exists).isTrue();
}
use of core.srs.MinoRotation in project solution-finder by knewjade.
the class BuildUpTest method cansBuild.
@Test
void cansBuild() {
Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX");
int height = 4;
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
Operations operations = OperationInterpreter.parseToOperations("J,0,1,0;S,L,1,2;O,0,2,1;J,2,2,1");
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
assertThat(BuildUp.cansBuild(field, operationWithKeys, height, reachable)).isTrue();
MinoOperationWithKey remove = operationWithKeys.remove(0);
operationWithKeys.add(1, remove);
assertThat(BuildUp.cansBuild(field, operationWithKeys, height, reachable)).isFalse();
}
use of core.srs.MinoRotation in project solution-finder by knewjade.
the class BuildUpTest method checksAllPatterns2.
@Test
void checksAllPatterns2() throws Exception {
int height = 4;
Field field = FieldFactory.createField("" + "_____XXXXX" + "____XXXXXX" + "___XXXXXXX" + "____XXXXXX");
Operations operations = new Operations(Arrays.asList(new SimpleOperation(Piece.I, Rotate.Left, 0, 1), new SimpleOperation(Piece.J, Rotate.Spawn, 2, 0), new SimpleOperation(Piece.S, Rotate.Right, 1, 1), new SimpleOperation(Piece.T, Rotate.Reverse, 3, 1)));
// OperationWithKeyに変換
MinoFactory minoFactory = new MinoFactory();
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
// reachableの準備
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
// existsValidBuildPatternのチェック
boolean exists = BuildUp.existsValidBuildPattern(field, operationWithKeys, height, reachable);
assertThat(exists).isTrue();
// 有効な手順を列挙する
BuildUpStream buildUpStream = new BuildUpStream(reachable, height);
Set<List<MinoOperationWithKey>> validPatterns = buildUpStream.existsValidBuildPattern(field, operationWithKeys).collect(Collectors.toSet());
// すべての組み合わせでチェック
Iterable<List<MinoOperationWithKey>> iterable = new PermutationIterable<>(operationWithKeys, operationWithKeys.size());
for (List<MinoOperationWithKey> withKeys : iterable) {
boolean canBuild = BuildUp.cansBuild(field, withKeys, height, reachable);
assertThat(canBuild).isEqualTo(validPatterns.contains(withKeys));
boolean checksKey = BuildUp.checksKey(withKeys, 0L, height);
assertThat(checksKey).isTrue();
}
}
use of core.srs.MinoRotation in project solution-finder by knewjade.
the class BuildUpTest method existsValidByOrder.
@Test
void existsValidByOrder() throws Exception {
Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "");
String line = "L,L,3,1,0,1049601;L,R,1,1,0,1049601;I,L,0,1,0,1074791425;T,2,2,2,1048576,1073742848";
MinoFactory minoFactory = new MinoFactory();
Stream<MinoOperationWithKey> stream = OperationWithKeyInterpreter.parseToStream(line, minoFactory);
List<MinoOperationWithKey> operations = stream.collect(Collectors.toList());
System.out.println(operations);
int height = 4;
MinoRotation minoRotation = new MinoRotation();
MinoShifter minoShifter = new MinoShifter();
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
// true
assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(L, L, I, T), height, reachable)).isTrue();
assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(L, I, L, T), height, reachable)).isTrue();
assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(I, L, L, T), height, reachable)).isTrue();
// false
assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(L, L, T, I), height, reachable)).isFalse();
assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(L, T, L, I), height, reachable)).isFalse();
assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(L, T, I, L), height, reachable)).isFalse();
assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(T, L, I, L), height, reachable)).isFalse();
assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(T, I, L, L), height, reachable)).isFalse();
}
use of core.srs.MinoRotation in project solution-finder by knewjade.
the class LimitIterationCandidateTest method testSearch2.
@Test
void testSearch2() throws Exception {
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
Candidate<Action> candidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 3);
String marks = "" + "XXXX______" + "XXXXX_____" + "X___X_____" + "XX_XX_____";
Field field = FieldFactory.createField(marks);
Set<Action> actions = candidate.search(field, Piece.T, 4);
assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Spawn)).hasSize(3);
assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Right)).hasSize(4);
assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Reverse)).hasSize(4);
assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Left)).hasSize(4);
}
Aggregations