# A simple CA simulation of sand - inspired by MCell's version.

@RULE Sand-Margolus

@TABLE

n_states:4
neighborhood:Margolus
symmetries:reflect_horizontal

# In the Margolus nhood, the transition a,b,c,d,e,f,g,h means:
#  a  b     -->    e  f
#  c  d            g  h

# 0 : air
# 1 : sand
# 2 : wood
# 3 : magical source of sand

var a={0,1,2,3}
var b={0,1,2,3}

1,1,0,0 : 0,0,1,1  # a pair of sand particles falls
1,a,0,b : 0,a,1,b  # otherwise, sand falls next to a static column
1,0,a,0 : 0,0,a,1  # otherwise, it can topple
3,a,0,b : 3,a,1,b  # sand can appear from the magical source