Given a maze, check if set of points is forming some-type of closed shape Let's say we have given 2-dimensional maze in form of matrix, conisting only of the letters  x and .. For example the following maze:

xxxxx 11111    .....
x...x 1...1    .xxx.
x.x.x 1.2.1    .x.x.
x...x 1...1    .x.x.
xxxxx 11111    .....


Let's group those elements, we will group x's only, such that two elements will be in one group if they share at least one of the 8 sides (4 regular and 4 diagonal). Up here is one way how to group them, now for each of those groups we want to check if they are forming closed figure (in the first maze there is closed figure and in the second there isn't because the area of x's isn't closed).

What I think for the solution

I was thinking that we should find 4 points first that are important for each figure, those are: the top right, top left, bottom left and bottom right nodes, and now check if there is path from the top right to top left and bottom right,
from the top left to bottom left and from the bottom left to the bottom right. But, it turns out that this is not working always.
Label open space in same way you label the x's, if a set of x's touches more than one label it contains a closed space.