Class: Cgl::Evaluate

Inherits:
Object
  • Object
show all
Defined in:
lib/cgl/evaluate.rb

Class Method Summary collapse

Class Method Details

.evaluate(neighbors) ⇒ Object

given an array of length 9, where the first entry is the agent to update, return the agents updated value



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cgl/evaluate.rb', line 5

def self.evaluate( neighbors )
  agent = neighbors.shift.to_i
  number_of_alive_neighbors = neighbors.inject(0){|sum,item| sum.to_i + item.to_i }
  # assume the very first column is the agent we're computing the next state
  # for
  if (number_of_alive_neighbors < 2) 
    f = 0
  elsif (number_of_alive_neighbors == 2)
    if (agent==1)
      f = 1
    else
      f = 0
    end
  elsif (number_of_alive_neighbors == 3)
    f = 1
  else # number_of_alive_neighbors > 3
    f = 0
  end
  f
end