Permalink
Browse files

weighted initialization

  • Loading branch information...
1 parent 0de75de commit 2794db16ff3ab3c54cca80c0ef7d811a53be3b62 @fhinkel fhinkel committed with Nov 2, 2009
Showing with 9 additions and 2 deletions.
  1. +9 −2 test.rb
View
11 test.rb
@@ -4,6 +4,12 @@
@gc = Magick::Draw.new
+# Have red and green be twice as likely as healthy
+def weighted_rand
+ r = rand(5)
+ r < 1 ? 0 : r < 3 ? 1 : 2
+end
+
def draw_hex(x,y, code)
color = code == 0 ? "white" : code == 1 ? "green" : "red"
@gc.fill(color)
@@ -59,7 +65,7 @@ def print_hex_gif(rings, gif_file)
def simulate_infection(initialization)
bar = Grid.new(initialization)
- 100.times do
+ 50.times do
bar = bar.getIteratedGrid
end
@@ -72,7 +78,8 @@ def simulate_infection(initialization)
random_initialization= Array.new
1500.times do
- random_initialization.push(rand(3))
+ #random_initialization.push(rand(3))
+ random_initialization.push(weighted_rand)
end
initializations.push random_initialization

0 comments on commit 2794db1

Please sign in to comment.