20 package net.sf.gridarta.model.validation.checks;
22 import java.awt.Point;
23 import java.util.ArrayList;
24 import java.util.Collection;
37 import org.jetbrains.annotations.NotNull;
45 public class BlockedSquareChecker<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> extends
AbstractValidator<G, A, R> implements
MapValidator<G, A, R> {
67 public static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> Iterable<MapSquare<G, A, R>>
findCompletelyBlockedSquares(@NotNull
final MapModel<G, A, R> mapModel) {
68 final Size2D mapSize = mapModel.getMapArchObject().getMapSize();
69 final int mapWidth = mapSize.
getWidth();
70 final int mapHeight = mapSize.
getHeight();
74 final boolean[][] blockedMatrix =
new boolean[mapWidth + 2][mapHeight + 2];
75 final Point pos =
new Point();
76 for (
int x = 0; x < mapWidth; x++) {
78 for (
int y = 0; y < mapHeight; y++) {
80 if (
isBlocked(mapModel.getMapSquare(pos))) {
81 blockedMatrix[x + 1][y + 1] =
true;
85 final Collection<MapSquare<G, A, R>> completelyBlockedSquares =
new ArrayList<>();
86 for (
int x = 0; x < mapWidth; x++) {
88 for (
int y = 0; y < mapHeight; y++) {
90 if (
and9x9(blockedMatrix, x + 1, y + 1)) {
91 completelyBlockedSquares.add(mapModel.getMapSquare(pos));
95 return completelyBlockedSquares;
109 private static boolean and9x9(
final boolean @NotNull [] @NotNull [] matrix,
final int x,
final int y) {
110 return matrix[x - 1][y - 1] && matrix[x - 1][y] && matrix[x - 1][y + 1] && matrix[x][y - 1] && matrix[x][y] && matrix[x][y + 1] && matrix[x + 1][y - 1] && matrix[x + 1][y] && matrix[x + 1][y + 1];
121 boolean noPass =
false;
122 boolean blocksView =
false;
130 if (noPass && blocksView) {