I'm working on a tile map where each type of tiles has 12 states with 12 different sprites associated with it, what I'm trying to say is that whenever I place a tile let's say a road tile, that tile should adjust itself automatically according to the 4 tiles surrounding it, so for example if the tile above it is a road tile and the tile below it is also a road tile, it should automatically adjust itself into a vertical road tile... there is 12 states a tile can have:
1-closed(not surrounded by any similar tile)
2-horizontal(similar tiles up and down)
3-vertical(similar tiles right and left)
4-open from up and left(similar tiles to the left and above)
5-open from left and down(...)
6-open from down and right(...)
7-open from right and up(...)
8-open from up & left & down(3 similar tiles up, left and down)
9-open from left & down & right(...)
10-open from down & right & up(...)
11-open from right & up & left(...)
12-open from all 4 directions(all surrounding tiles are similar)
the problem is that I don't know how to check for surrounding tiles and choose the right tile state without having a huge mess of if statements and performance waste, and I don't have enough experience with algorithms and data structures to figure it out myself.
how can check all 12 states the fastest way possible ?
thanks!