Elegant autotiling

I'm looking for information about how people implement autotiling in their tile-based games. So far I have always improvised it with a bunch of hardcoded "if ... else ..." statements, and now I decided that it is time to find some more elegant solution. I went searching on the Internet for examples of autotiling implementations and discussions on the topic, but I only came up with three articles:

(Especially the last one is comprehensive and very helpful.)

I have also looked at various implementations and documentation of libraries, that implement it, for example, flixel: http://www.flixel.org/features.html#tilemaps

Sadly, all the solutions that I could find are exactly as improvised and haphazard, as what I started with, and almost never cover all the possible cases.

I'm looking for an elegant example of autotiling implementation that I could learn from.

-

I've used A Bitwise Method For Applying Tilemaps and found it to be a very elegant solution. The article provides a concrete example and discusses how to extend the algorithm to handle multiple terrain types.

-
This looks like the algorithm used by the flixel "AUTO" mode of autotiling. Thank you, I'm adding it to my list. – Radomir Dopieralski Jan 2 '13 at 18:02

I read most of the links and spent some time to come up with another solution. I don't know if it's good or not, but to simulate the RPG Maker VX Ace auto-tile behavior (47 tiles) I started doing something like this:

(left 0 or 1) + (right 0 or 1) + (up 0 or 1) + (down 0 or 1) now I have 5 cases.

if 4 = Tile 46 is placed

if 3 boarders =

if 2 4 cases + 2 cases not sure about algorithm but not much branches to make.

if 1 = working on it but every direction can end up in 4 cases

if 0 = I can use the number algorithm shown in the links with 1, 2, 4, 8 and getting id from 1 to 15 I can directly use.

I am not a programmer and not the best with math algorithms and the 1, 2, 4, 8, 16, 32, 64, 128 solution I also didn't liked much.

Maybe my approach is at least better than that.

-
I'm not sure this answer fully answers the question, could you explain a bit more? If you refer to something else, could you at least link to it? – Alexandre Vaillancourt Nov 6 '15 at 23:46