Here is an old "guide" that I made for my current game project some years ago.

Wallset_Wall_Explanation.jpg

The tiles aren't used quite exactly the same way. It was more meant for walls instead of your typical RPG map tiling. However it shows all the checks to select a tile from a list of 47 individual case scenarios you would encounter.

The basic idea was to check your 4 cardinal directions and if a wall (or in your case tile of the same type) was detected in 2 tiles beside a corner it would check that corner too.

Not sure if this would be of any help, but it sort of relates so it might give you other ideas of just confuse. Enjoy! lol