This commit is contained in:
parent
49725fe7df
commit
b18e7fba9e
3 changed files with 26 additions and 28 deletions
|
|
@ -35,18 +35,18 @@ public class Tile {
|
|||
private Tile(@NotNull final EnumSet<Direction> walls, final boolean solution) {
|
||||
for (final Direction direction : walls) {
|
||||
this.walls.set(direction);
|
||||
this.walls.harden(direction);
|
||||
this.walls.seal(direction);
|
||||
}
|
||||
this.visited = true;
|
||||
this.solution = solution;
|
||||
}
|
||||
|
||||
public void preventDiggingToOrFrom(@NotNull final Direction direction) {
|
||||
this.walls.harden(direction);
|
||||
this.walls.seal(direction);
|
||||
}
|
||||
|
||||
public void enableDiggingToOrFrom(@NotNull final Direction direction) {
|
||||
this.walls.unharden(direction);
|
||||
this.walls.unseal(direction);
|
||||
}
|
||||
|
||||
public boolean digFrom(@NotNull final Direction direction) {
|
||||
|
|
@ -66,7 +66,7 @@ public class Tile {
|
|||
}
|
||||
|
||||
public Option<Direction> getRandomAvailableDirection(@NotNull final Random random) {
|
||||
final Stream<Direction> availableDirections = this.walls.getUnhardenedSet();
|
||||
final Stream<Direction> availableDirections = this.walls.getUnsealedSet();
|
||||
if (availableDirections.isEmpty()) {
|
||||
return Option.none();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import java.util.TreeSet;
|
|||
@ToString
|
||||
public class Walls {
|
||||
private final SortedSet<Direction> directions = new TreeSet<>();
|
||||
private final Set<Direction> hardened = new HashSet<>();
|
||||
private final Set<Direction> sealed = new HashSet<>();
|
||||
|
||||
public void set(@NotNull final Direction direction) {
|
||||
this.directions.add(direction);
|
||||
|
|
@ -26,7 +26,7 @@ public class Walls {
|
|||
}
|
||||
|
||||
public boolean clear(@NotNull final Direction direction) {
|
||||
if (this.hardened.contains(direction)) {
|
||||
if (this.sealed.contains(direction)) {
|
||||
return false;
|
||||
}
|
||||
return this.directions.remove(direction);
|
||||
|
|
@ -36,19 +36,19 @@ public class Walls {
|
|||
return this.directions.contains(direction);
|
||||
}
|
||||
|
||||
public Stream<Direction> getUnhardenedSet() {
|
||||
public Stream<Direction> getUnsealedSet() {
|
||||
return Stream.ofAll(this.directions)
|
||||
.removeAll(this.hardened);
|
||||
.removeAll(this.sealed);
|
||||
}
|
||||
|
||||
public void harden(@NotNull final Direction direction) {
|
||||
public void seal(@NotNull final Direction direction) {
|
||||
if (!this.directions.contains(direction)) {
|
||||
throw new IllegalStateException("Trying to harden cleared Direction: " + direction);
|
||||
throw new IllegalStateException("Trying to seal cleared Direction: " + direction);
|
||||
}
|
||||
this.hardened.add(direction);
|
||||
this.sealed.add(direction);
|
||||
}
|
||||
|
||||
public void unharden(@NotNull final Direction direction) {
|
||||
this.hardened.remove(direction);
|
||||
public void unseal(@NotNull final Direction direction) {
|
||||
this.sealed.remove(direction);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue