Class: Lifelike::LifelikeCellularAutomaton::WorldStringAnalyzer

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

Instance Method Summary collapse

Constructor Details

#initialize(string, default_dead_char: ' ', default_alive_char: 'X') ⇒ WorldStringAnalyzer

Returns a new instance of WorldStringAnalyzer.



4
5
6
7
8
# File 'lib/lifelike/lifelike_cellular_automaton/world_string_analyzer.rb', line 4

def initialize(string, default_dead_char: ' ', default_alive_char: 'X')
  @world_string = string
  @default_dead_char = default_dead_char
  @default_alive_char = default_alive_char
end

Instance Method Details

#alive_charObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/lifelike/lifelike_cellular_automaton/world_string_analyzer.rb', line 21

def alive_char
  case valid_chars.size
  when 0
    fail InsufficientValidCharacterError.new(allowed_chars_by_aliveness)
  when 1
    lifelike_char || @default_alive_char
  else
    most_alive_valid_char
  end
end

#dead_charObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/lifelike/lifelike_cellular_automaton/world_string_analyzer.rb', line 10

def dead_char
  case valid_chars.size
  when 0
    fail InsufficientValidCharacterError.new(allowed_chars_by_aliveness)
  when 1
    deadlike_char || @default_dead_char
  else
    least_alive_valid_char
  end
end