summaryrefslogtreecommitdiffhomepage
path: root/lib/rules
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rules')
-rw-r--r--lib/rules/alignment.rb4
-rw-r--r--lib/rules/bounds.rb2
-rw-r--r--lib/rules/cohesion.rb5
-rw-r--r--lib/rules/limit.rb14
-rw-r--r--lib/rules/seperation.rb50
-rw-r--r--lib/rules/target.rb23
6 files changed, 53 insertions, 45 deletions
diff --git a/lib/rules/alignment.rb b/lib/rules/alignment.rb
index 4072227..0db72f5 100644
--- a/lib/rules/alignment.rb
+++ b/lib/rules/alignment.rb
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
FF::Sys.new('Alignment', priority: 50) do
- group_velocity = [0.0,0.0]
+ group_velocity = [0.0, 0.0]
boids_count = FF::Cmp::Boids.each.to_a.count
FF::Cmp::Boids.each do |boid|
diff --git a/lib/rules/bounds.rb b/lib/rules/bounds.rb
index 5045d60..8524e02 100644
--- a/lib/rules/bounds.rb
+++ b/lib/rules/bounds.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
FF::Sys.new('Bounds', priority: 50) do
FF::Cmp::Boids.each do |boid|
if boid.x > $config.xmax
diff --git a/lib/rules/cohesion.rb b/lib/rules/cohesion.rb
index 5abefd7..3905ba5 100644
--- a/lib/rules/cohesion.rb
+++ b/lib/rules/cohesion.rb
@@ -1,6 +1,7 @@
-FF::Sys.new('Cohesion', priority: 50) do
+# frozen_string_literal: true
- center_mass = [0.0,0.0]
+FF::Sys.new('Cohesion', priority: 50) do
+ center_mass = [0.0, 0.0]
boids_count = FF::Cmp::Fish[0].entities.count
FF::Cmp::Fish[0].entities.each do |ent|
diff --git a/lib/rules/limit.rb b/lib/rules/limit.rb
index 5df8bc4..2921230 100644
--- a/lib/rules/limit.rb
+++ b/lib/rules/limit.rb
@@ -1,13 +1,15 @@
+# frozen_string_literal: true
+
# This special function is already called by apply_boid_calculations.rb
# do not add or call this function elsewhere
FF::Sys.new('Limit') do
- unless $config.limit < 0
+ unless $config.limit.negative?
FF::Cmp::Boids.each do |boid|
- if boid.entities[0].components[FF::Cmp::Piranha].nil?
- multi = 1.0
- else
- multi = 0.3
- end
+ multi = if boid.entities[0].components[FF::Cmp::Piranha].nil?
+ 1.0
+ else
+ 0.3
+ end
absolute_velocity = Math.sqrt((boid.vx**2) + (boid.vy**2))
if absolute_velocity > ($config.limit * multi)
diff --git a/lib/rules/seperation.rb b/lib/rules/seperation.rb
index 65493e8..ad5f0fd 100644
--- a/lib/rules/seperation.rb
+++ b/lib/rules/seperation.rb
@@ -1,12 +1,15 @@
+# frozen_string_literal: true
+
FF::Sys.new('Seperation', priority: 50) do
FF::Cmp::Fish[0].entities.each do |ent|
boid_update = ent.components[FF::Cmp::Boids].first
- newvec = [0.0,0.0]
+ newvec = [0.0, 0.0]
FF::Cmp::Boids.each do |boid_check|
next if boid_check == boid_update
+
if Math.sqrt(((-boid_check.x + boid_update.x)**2) + ((-boid_check.y + boid_update.y)**2)).abs < $config.seperation_distance
- newvec[0] -= boid_check.x - boid_update.x
- newvec[1] -= boid_check.y - boid_update.y
+ newvec[0] -= boid_check.x - boid_update.x
+ newvec[1] -= boid_check.y - boid_update.y
end
end
boid_update.cx += newvec[0] / $config.seperation
@@ -14,13 +17,14 @@ FF::Sys.new('Seperation', priority: 50) do
end
FF::Cmp::Piranha[0].entities.each do |ent|
boid_update = ent.components[FF::Cmp::Boids].first
- newvec = [0.0,0.0]
+ newvec = [0.0, 0.0]
FF::Cmp::Piranha[0].entities.each do |ent2|
boid_check = ent2.components[FF::Cmp::Boids].first
next if boid_check == boid_update
+
if Math.sqrt(((-boid_check.x + boid_update.x)**2) + ((-boid_check.y + boid_update.y)**2)).abs < $config.seperation_distance
- newvec[0] -= boid_check.x - boid_update.x
- newvec[1] -= boid_check.y - boid_update.y
+ newvec[0] -= boid_check.x - boid_update.x
+ newvec[1] -= boid_check.y - boid_update.y
end
end
boid_update.cx += newvec[0] / ($config.seperation / 10)
@@ -28,21 +32,19 @@ FF::Sys.new('Seperation', priority: 50) do
end
end
-=begin
-FF::Sys.new('Seperation', priority: 50) do
- FF::Cmp::Fish[0].entities.each do |ent_update|
- boid_update = ent_update.components[FF::Cmp::Boids].first
- newvec = [0.0,0.0]
- FF::Cmp::Fish[0].entities.each do |ent_check|
- boid_check = ent_update.components[FF::Cmp::Boids].first
- next if boid_check == boid_update
- if Math.sqrt(((-boid_check.x + boid_update.x)**2) + ((-boid_check.y + boid_update.y)**2)).abs < $config.seperation_distance
- newvec[0] -= boid_check.x - boid_update.x
- newvec[1] -= boid_check.y - boid_update.y
- end
- end
- boid_update.cx += newvec[0] / $config.seperation
- boid_update.cy += newvec[1] / $config.seperation
- end
-end
-=end
+# FF::Sys.new('Seperation', priority: 50) do
+# FF::Cmp::Fish[0].entities.each do |ent_update|
+# boid_update = ent_update.components[FF::Cmp::Boids].first
+# newvec = [0.0,0.0]
+# FF::Cmp::Fish[0].entities.each do |ent_check|
+# boid_check = ent_update.components[FF::Cmp::Boids].first
+# next if boid_check == boid_update
+# if Math.sqrt(((-boid_check.x + boid_update.x)**2) + ((-boid_check.y + boid_update.y)**2)).abs < $config.seperation_distance
+# newvec[0] -= boid_check.x - boid_update.x
+# newvec[1] -= boid_check.y - boid_update.y
+# end
+# end
+# boid_update.cx += newvec[0] / $config.seperation
+# boid_update.cy += newvec[1] / $config.seperation
+# end
+# end
diff --git a/lib/rules/target.rb b/lib/rules/target.rb
index c0ced5c..8bd53a5 100644
--- a/lib/rules/target.rb
+++ b/lib/rules/target.rb
@@ -1,15 +1,14 @@
-FF::Sys.new('Target', priority: 50) do
+# frozen_string_literal: true
+FF::Sys.new('Target', priority: 50) do
FF::Cmp::Piranha[0].entities.each do |ent|
closest = []
boid = ent.components[FF::Cmp::Boids].first
FF::Cmp::Fish[0].entities.each do |_fish|
fish = _fish.components[FF::Cmp::Boids].first
- unless (fish.x > $config.xmax) || (fish.x < $config.xmin) || (fish.y > $config.ymax) || (fish.y < $config.ymin)
- if closest[0].nil? || Math.sqrt(((boid.x - fish.x)**2) + ((boid.y - fish.y)**2)).abs < closest[0]
- closest[0] = Math.sqrt(((boid.x - fish.x)**2) + ((boid.y - fish.y)**2)).abs
- closest[1] = fish
- end
+ if !((fish.x > $config.xmax) || (fish.x < $config.xmin) || (fish.y > $config.ymax) || (fish.y < $config.ymin)) && (closest[0].nil? || Math.sqrt(((boid.x - fish.x)**2) + ((boid.y - fish.y)**2)).abs < closest[0])
+ closest[0] = Math.sqrt(((boid.x - fish.x)**2) + ((boid.y - fish.y)**2)).abs
+ closest[1] = fish
end
end
unless closest[0].nil?
@@ -23,12 +22,12 @@ FF::Sys.new('Target', priority: 50) do
boid = ent.components[FF::Cmp::Boids].first
FF::Cmp::Piranha[0].entities.each do |_piranha|
piranha = _piranha.components[FF::Cmp::Boids].first
- unless Math.sqrt(((boid.x - piranha.x)**2) + ((boid.y - piranha.y)**2)).abs > $config.target_fear
- #boid.cx -= ($config.target_strength / (piranha.x + boid.x))
- #boid.cy -= ($config.target_strength / (piranha.y + boid.y))
- boid.cx -= ((piranha.x - boid.x) / ($config.target_strength))
- boid.cy -= ((piranha.y - boid.y) / ($config.target_strength))
- end
+ next if Math.sqrt(((boid.x - piranha.x)**2) + ((boid.y - piranha.y)**2)).abs > $config.target_fear
+
+ #boid.cx -= ($config.target_strength / (piranha.x + boid.x))
+ #boid.cy -= ($config.target_strength / (piranha.y + boid.y))
+ boid.cx -= ((piranha.x - boid.x) / $config.target_strength)
+ boid.cy -= ((piranha.y - boid.y) / $config.target_strength)
#if closest[0].nil? || Math.sqrt(((boid.x - fish.x)**2) + ((boid.y + fish.y)**2)).abs < closest[0]
# closest[0] = Math.sqrt(((boid.x - fish.x)**2) + ((boid.y + fish.y)**2)).abs
# closest[1] = fish