Had to deal with this earlier today actually.
Firstly, unless you specifically have to deal with diagonal walls, which I don't, forget about this:
...
...
...
and just think about these
.
...
.
So let's say our function gives us a wall to test, that wall is the middle guy:
.
.#.
.
so he's known, the unknowns are to his east, west, north, and south. This is what the algorithm starts off knowing.
First, check the spot to the right:
.
.#?
.
If it's a wall, check the spot to the left:
.
?##
.
If that's not a wall, the algorithm ends and returns that we have a corner. If it is a wall, check both above and below at the same time. If either is a wall, the algorithm returns a corner; but if neither is, it returns not a corner.
?
###
?
If, however, the spot to the east was not a wall, we have to repeat the process starting from north (only we don't have to check east on the last step):
?
.#.
.
#
.#.
?
#
?#.
#
If neither the east nor north tile is a wall, we can return corner.
The algorithm can take up to 4 steps, but as few as 2, so it's more efficient than checking the situation against every possible permutation of a corner.