DEV: Comment rework

This commit is contained in:
Christos Choutouridis 2020-10-24 22:37:41 +03:00
parent 5a3c8c5413
commit b1c59453c1
2 changed files with 11 additions and 10 deletions

View File

@ -270,14 +270,15 @@ class Board {
* Predicate to check if a wall creates a closed room.
*
* This algorithm has a complexity of O(N^2) where N represents the total
* number of tiles it should be used with care.
* number of tiles.
* It should be used with care.
*
* @param tileId The tileId of the wall where the wall is.
* @param direction The wall's relative direction from the tile.
* @return True if the wall creates a closed room, false otherwise.
*/
private boolean createsClosedRoom (int tileId, int direction) {
// Get a snapshot of the current walls
private boolean makesClosedRoom (int tileId, int direction) {
// Get a snapshot list of all the walls (all the walls on the board)
ArrayList<Edge> w = new ArrayList<Edge>();
for (Edge it : walls)
w.add(new Edge(it));
@ -286,13 +287,13 @@ class Board {
Graph g = new Graph(new Edge(tileId, direction));
int size;
do {
size = w.size();
size = w.size(); // mark the size (before the pass)
for (int i =0, S=w.size() ; i<S ; ++i)
if (g.attach(w.get(i))) {
w.remove(i);
--i; --S;
if (g.attach(w.get(i))) { // Can we attach the edge(wall) to the graph ?
w.remove(i); // If yes remove it from the wall list
--i; --S; // decrease iterator and size to match ArrayList's new values
}
} while (size != w.size());
} while (size != w.size()); // If the size hasn't change(no new graph leafs) exit
// Search if a vertex is attached more than once.
// This means that there is at least 2 links to the same node
@ -342,7 +343,7 @@ class Board {
if (tiles[rightTileId.apply(tileId)].hasWalls() >= Const.maxTileWalls) return false;
break;
}
if (Session.loopGuard && createsClosedRoom(tileId, direction))
if (Session.loopGuard && makesClosedRoom(tileId, direction))
return false;
return true;
}