Class: Cellula::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/cellula/rules/rule.rb

Overview

Internal: Know how to apply a rule to a single cell.

Instance Method Summary collapse

Constructor Details

#initialize(rule) ⇒ Rule

Public: Initialize a new Rule object.

rule - Currently accept only wolfram code, in the form

of a Symbol like :wolfram_code_110.


10
11
12
13
14
15
16
# File 'lib/cellula/rules/rule.rb', line 10

def initialize(rule)
  if WolframCodeRule.wolfram_code?(rule)
    @rule = WolframCodeRule.new WolframCodeRule.wolfram_code(rule)
  else
    panic "Unknown rule: #{rule.to_s}"
  end
end

Instance Method Details

#apply_rule(cell_number, grid, study) ⇒ Object

Public: Apply the rule on a single cell.

cell_number - Integer number of the cell to apply the rule on. grid - The entire grid as an Array of Integer. study - Study instance.

Returns the Integer new state of the cell for the next generation.



25
26
27
# File 'lib/cellula/rules/rule.rb', line 25

def apply_rule(cell_number, grid, study)
  @rule.apply_rule(cell_number, grid, study)
end