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 +4 -4
- data/README.md +7 -1
- data/lib/rsb/gol/game.rb +5 -18
- data/lib/rsb/gol/grid.rb +9 -1
- data/lib/rsb/gol/universe.rb +2 -1
- data/lib/rsb/gol/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a6d3875f41a07f9d7dd562777398579a7703041
|
4
|
+
data.tar.gz: 5b291f721c0b488572401f26fe387aeefa229226
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0826e79ad984c0bf88726454f09f6f1bbe63fe919ec9134ffb79d28c3d4cc904fed927a7227025e9c2d2a24a98725b8f2afbf6b04395fc535e99293e77ceecdf
|
7
|
+
data.tar.gz: bb99b7fc717274a83aa02aec10ff4a126bf299f031bebfc6a12934c5f1cad4de3cdb03a7ebdc3cf964342a8cc73ba73a13a9128a40360fdac40c4f48a3d59933
|
data/README.md
CHANGED
data/lib/rsb/gol/game.rb
CHANGED
@@ -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
|
-
|
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]
|
data/lib/rsb/gol/grid.rb
CHANGED
@@ -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
|
data/lib/rsb/gol/universe.rb
CHANGED
data/lib/rsb/gol/version.rb
CHANGED