I know my solution is too local but the less local a solution is, the more exponentially time consuming the algorithm is gonna be. I'm a researcher/programmer myself and I deal mainly with simulations so I have experience with slow algorithms which for the most part I can't get rid of
# : is a rock tile
a, b, c, d, e : are also rock tiles named for reference
@ : the dorf that dug this
to overall formula to calculate the stability factor would be:
S(#) = min(1.0, K * T + Q * sum(Sa))
S(#) is the current stability of the tile #.
K is the (normalized) mining skill of the dwarf that dug below it.
T is the inherent strength of the material.
Q is a constant (preferably a value between 0.0 and 1.0)
sum(Sa(#)) is the sum of the calculated stability of all adjacent cells (without taking into account those cells adjacent to them).
if no dwarf has dug below the tile then S = 1.0.
if S >= 1.0 then there's no chance that tile while crumble.
the lower S is the more chance there is that the tile will eventually crumble.
suppose tiles in the example have a material strength value if 0.5, the dwarf has a normalized skill of 0.8, and use a Q of 0.5 Then:
S(a) = 1.0 since no dwarf has dug down below it.
S(b) = min(1.0, 0.5*0.8 + 0.5*(0.5*0.8 + 0.5*0.) = 0.8.
S(c) = min(1.0, 0.5*0.8 + 0.5*(0.5*0.8 + 1.0)) = 1.0.
S(d) = min(1.0, 0.5*0.8 + 0.5*(0.0)) = 0.4.
S(e) = min(1.0, 0.5*0.8 + 0.5*(1.0 + 1.0)) = 1.0.
This value has to be calculated just once when any dwarf digs below it and needs to be recalculated when a dwarf digs below any of the adjacent cells. So the value for each cell would have to be calculated at most 5 times if there's no cave-in. Also you would have to recalculate if any of the adjacent cells crumbles. In this case you could simply multiply S(#) for a value less than 1.0 to make it more probable to crumble along with the rest of the cave-in.
If you want to make the algorithm less local you can just make the sum of the stability of adjacent cells take into account even farther cells. This way you can make the overall behavior of the cave-in be as similar as possible to the previous version when the circumstances are similar. If you make the legendary dwarves have normalized skill value above 1.0 (which would no longer be normalized) then you can create stalactite like structures (like hanging arms for statues) without fear of them crumbling down.
Edit:
Just one more thing, if you want to allow players build complex structures like big Buddha-like statues give them a slight bonus to the stability value if they do it via rewalling instead of just digging out the statue. Ancient civilizations mostly choose carefully which rocks they would choose when creating a statue or when digging them out they choose carefully the rock wall where they were going to do it. Also they choose carefully the most skilled masons for that. That's why my equation takes into account both the material strength and the skills of the dwarf.
[ August 11, 2007: Message edited by: Zemat ]