rsb-gol 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ef22276b52a97905119dbe734de22ed401c2be8
4
- data.tar.gz: 95655cba534297d4a7161bad0ce80ea346382a60
3
+ metadata.gz: 1a6d3875f41a07f9d7dd562777398579a7703041
4
+ data.tar.gz: 5b291f721c0b488572401f26fe387aeefa229226
5
5
  SHA512:
6
- metadata.gz: 9576085d3d4eb0fe36490a34bb269660248dd4d28fb910e86b16d52d9db66f183386ad58ba16337f576f9491a9b7abb17974247488768b7eefb1e55e399880b2
7
- data.tar.gz: 22cf78a39f829303d8ba59572e5a824784a29c3bd8197b733d35f06eda9a7a32c1d5a759aae3bbf8083a474c9643082f7105d75d4155be7756e3f967442ca8d1
6
+ metadata.gz: 0826e79ad984c0bf88726454f09f6f1bbe63fe919ec9134ffb79d28c3d4cc904fed927a7227025e9c2d2a24a98725b8f2afbf6b04395fc535e99293e77ceecdf
7
+ data.tar.gz: bb99b7fc717274a83aa02aec10ff4a126bf299f031bebfc6a12934c5f1cad4de3cdb03a7ebdc3cf964342a8cc73ba73a13a9128a40360fdac40c4f48a3d59933
data/README.md CHANGED
@@ -45,7 +45,13 @@ Or install it yourself as:
45
45
 
46
46
  ## Usage
47
47
 
48
- TODO: Write usage instructions here
48
+ right now it only supports a single seed to run it
49
+
50
+ ```
51
+ gol start
52
+ ```
53
+
54
+ to stop it you have use CTRL-C
49
55
 
50
56
  ## Development
51
57
 
@@ -4,9 +4,13 @@ module Rsb
4
4
  CLEAR_SCREEN_CHAR = "\e[H\e[2J"
5
5
 
6
6
  attr_reader :universe
7
+ attr_accessor :seed
7
8
 
8
9
  def initialize(options = {})
9
- grid = Rsb::Gol::Grid.new(options[:rows] || 40, options[:cols] || 40)
10
+ random_seed = options[:random_seed] == false ? false : true
11
+ rows = options[:rows] || 40
12
+ cols = options[:cols] || 40
13
+ grid = Rsb::Gol::Grid.new(rows, cols, random_seed)
10
14
  @universe = options[:universe] || Rsb::Gol::Universe.new(grid: grid)
11
15
  end
12
16
 
@@ -14,22 +18,6 @@ module Rsb
14
18
  puts CLEAR_SCREEN_CHAR
15
19
  end
16
20
 
17
- def seed
18
- coords = [
19
- [25, 1],
20
- [23, 2], [25, 2],
21
- [13, 3], [14, 3], [21, 3], [22, 3],
22
- [12, 4], [16, 4], [21, 4], [22, 4], [35, 4], [36, 4],
23
- [1, 5], [2, 5], [11, 5], [17, 5], [21, 5], [22, 5], [35, 5], [36, 5],
24
- [1, 6], [2, 6], [11, 6], [15, 6], [17, 6], [18, 6], [23, 6], [25, 6],
25
- [11, 7], [17, 7], [25, 7],
26
- [12, 8], [16, 8],
27
- [13, 9], [14, 9]
28
- ]
29
-
30
- universe.seed(coords)
31
- end
32
-
33
21
  def status_line(data)
34
22
  "@@@ generation clock: #{data[:clock]} " +
35
23
  "deaths: #{data[:deaths]} births: #{data[:births]}"
@@ -37,7 +25,6 @@ module Rsb
37
25
 
38
26
  def start(iterations = 1000, alive='0', dead=' ', step=3)
39
27
  clear_screen
40
- seed
41
28
  iterations.times do
42
29
  data = universe.tick!
43
30
  abort('empty universe') if data[:empty_universe]
@@ -17,13 +17,15 @@ module Rsb
17
17
 
18
18
  attr_reader :rows, :columns, :top_border, :bottom_border
19
19
 
20
- def initialize(rows, columns)
20
+ def initialize(rows, columns, random_seed = false)
21
21
  @rows = rows
22
22
  @columns = columns
23
23
  @matrix = Matrix.zero(rows, columns)
24
24
  hbar = HORIZONTAL_BAR * columns
25
25
  @top_border = TOP_RIGHT_CORNER + hbar + TOP_LEFT_CORNER
26
26
  @bottom_border = BOTTOM_RIGHT_CORNER + hbar + BOTTOM_LEFT_CORNER
27
+
28
+ apply_random_seed if random_seed == true
27
29
  end
28
30
 
29
31
  def spawn(x, y)
@@ -40,6 +42,12 @@ module Rsb
40
42
  @matrix[x, y]
41
43
  end
42
44
 
45
+ def apply_random_seed
46
+ @matrix.each_with_index do |state, x, y|
47
+ spawn(x, y) if Random.rand(2) == 1
48
+ end
49
+ end
50
+
43
51
  def out_of_bounds?(x, y)
44
52
  x < 0 || y < 0 || x > rows - 1 || y > columns - 1
45
53
  end
@@ -59,7 +59,8 @@ module Rsb
59
59
  stats = populate(evolution())
60
60
  {
61
61
  empty_universe: stats[:deaths] == 0 && stats[:births] == 0,
62
- population: stats,
62
+ deaths: stats[:deaths],
63
+ births: stats[:births],
63
64
  clock: clock
64
65
  }
65
66
  end
@@ -1,5 +1,5 @@
1
1
  module Rsb
2
2
  module Gol
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsb-gol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Scott-Buccleuch