Skip to content

Commit

Permalink
9章のsex, evolutionのコードに不要なuidを削除。
Browse files Browse the repository at this point in the history
  • Loading branch information
setoyama60jp committed Jan 2, 2013
1 parent f064c0c commit e54fe9a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
7 changes: 3 additions & 4 deletions Chapter9/evolution/roid.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
class Roid
attr_reader :velocity, :position, :energy, :uid, :sex, :lifespan, :age, :metabolism, :vision_range
attr_reader :velocity, :position, :energy, :sex, :lifespan, :age, :metabolism, :vision_range

def initialize(slot, p, v, id)
def initialize(slot, p, v)
@velocity = v # assume v is a Vector with X velocity and Y velocity as elements
@position = p # assume p is a Vector with X and Y as elements
@slot = slot
@energy = rand(MAX_ENERGY)
@uid = id
@sex = rand(2) == 1 ? :male : :female
@lifespan = rand(MAX_LIFESPAN)
@age = 0
Expand Down Expand Up @@ -174,7 +173,7 @@ def procreate
roids = r.first(MAGIC_NUMBER)
roids.each do |roid|
if roid.attractive and roid.male?
baby = Roid.new(@slot, @position, @velocity, 1001)
baby = Roid.new(@slot, @position, @velocity)
crossovers = [[@metabolism, @vision_range],
[@metabolism,roid.vision_range],
[roid.metabolism, @vision_range],
Expand Down
2 changes: 1 addition & 1 deletion Chapter9/evolution/utopia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def random_location
def populate
POPULATION_SIZE.times do |i|
random_velocity = Vector[rand(11)-5,rand(11)-5]
$roids << Roid.new(self, random_location, random_velocity, i)
$roids << Roid.new(self, random_location, random_velocity)
end
end

Expand Down
7 changes: 3 additions & 4 deletions Chapter9/sex/roid.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
class Roid
attr_reader :velocity, :position, :energy, :uid, :sex, :lifespan, :age
attr_reader :velocity, :position, :energy, :sex, :lifespan, :age

def initialize(slot, p, v, id)
def initialize(slot, p, v)
@velocity = v # assume v is a Vector with X velocity and Y velocity as elements
@position = p # assume p is a Vector with X and Y as elements
@slot = slot
@energy = rand(MAX_ENERGY)
@uid = id
@sex = rand(2) == 1 ? :male : :female
@lifespan = rand(MAX_LIFESPAN)
@age = 0
Expand Down Expand Up @@ -168,7 +167,7 @@ def procreate
roids = r.first(MAGIC_NUMBER)
roids.each do |roid|
if roid.attractive and roid.male?
baby = Roid.new(@slot, @position, @velocity, 1001)
baby = Roid.new(@slot, @position, @velocity)
$roids << baby
reduce_energy_from_childbirth
roid.reduce_energy_from_childbirth
Expand Down
2 changes: 1 addition & 1 deletion Chapter9/sex/utopia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def random_location
def populate
POPULATION_SIZE.times do |i|
random_velocity = Vector[rand(11)-5,rand(11)-5]
$roids << Roid.new(self, random_location, random_velocity, i)
$roids << Roid.new(self, random_location, random_velocity)
end
end

Expand Down

0 comments on commit e54fe9a

Please sign in to comment.