 
     for i in [0...period] by 1
       i1 = (i+1)%period
-      from_list compose3( stabilizers[i], @table, stabilizersR[i1] )
+      new Rule compose3( stabilizers[i], @table, stabilizersR[i1] )
       
   #Flashing rule is a rule that converts vacuum to its inverse and back, on each step
+  # (vacuum cycle is [0,15])
   is_flashing:  -> (@table[0] is 15) and (@table[15] is 0)
   
   #Vaccum-stable rules don't change empty field
+  # (vacuum cycle is [0])
   is_vacuum_stable: -> @table[0] is 0
 
     

  
 #Some rules from: http://psoup.math.wisc.edu/mcell/rullex_marg.html
exports.NamedRules = NamedRules = 
  tron: from_list [15,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0]
  billiardBallMachine: from_list [0,8,4,3,2,5,9,7,1,6,10,11,12,13,14,15]
  bounceGas: from_list [0,8,4,3,2,5,9,14, 1,6,10,13,12,11,7,15]
  hppGas: from_list [0,8,4,12,2,10,9, 14,1,6,5,13,3,11,7,15]
  rotations: from_list [0,2,8,12,1,10,9, 11,4,6,5,14,3,7,13,15]
  rotations2: from_list [0,2,8,12,1,10,9, 13,4,6,5,7,3,14,11,15]
  rotations3: from_list [0,4,1,10,8,3,9,11, 2,6,12,14,5,7,13,15]
  rotations4: from_list [0,4,1,12,8,10,6,14, 2,9,5,13,3,11,7,15]
  sand: from_list [0,4,8,12,4,12,12,13, 8,12,12,14,12,13,14,15]
  stringThing: from_list [0,1,2,12,4,10,9,7,8, 6,5,11,3,13,14,15]
  stringThing2: from_list [0,1,2,12,4,10,6,7,8, 9,5,11,3,13,14,15]
  swapOnDiag: from_list [0,8,4,12,2,10,6,14, 1,9,5,13,3,11,7,15]
  critters: make_rot_invariant_rule_from_samples [
      [0, 15], [15, 0], [1, 14], [14, 8], [3, 3], [6, 6]]
      
  doubleRotate: from_list [0, 2, 8, 3, 1, 5, 6, 13, 4, 9, 10, 7, 12, 14, 11, 15]
  singleRotate: make_rot_invariant_rule_from_samples [
      [0, 0], [1, 2], [3, 3], [6, 6], [7, 7], [15, 15]]
                

  (y ^ x for y in [0..15])


list2array =
  if Int8Array?
    (table) -> new Int8Array(table)
  else
    (table) -> table

exports.Rule = class Rule
  constructor: (table) ->
    @table = list2array table
    @validate()
    
  validate: ->
    if @table.length != 16
      throw new Error "Rule must have 16 components"
