Class: Lifelike::LifelikeCellularAutomaton::Rules

Inherits:
Object
  • Object
show all
Defined in:
lib/lifelike/lifelike_cellular_automaton/rules.rb

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Rules

Returns a new instance of Rules.



4
5
6
# File 'lib/lifelike/lifelike_cellular_automaton/rules.rb', line 4

def initialize(string)
  @rule_string = RuleString.new(string)
end

Instance Method Details

#born?(alive_neighbor_count) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/lifelike/lifelike_cellular_automaton/rules.rb', line 12

def born?(alive_neighbor_count)
  @rule_string.alive_neighbors_to_be_born.include?(alive_neighbor_count)
end

#survives?(alive_neighbor_count) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/lifelike/lifelike_cellular_automaton/rules.rb', line 8

def survives?(alive_neighbor_count)
  @rule_string.alive_neighbors_to_survive.include?(alive_neighbor_count)
end