simple_life_game 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_life_game.rb +5 -5
- 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: bf1b43c9f1dc2d0d60a78a5b8d9448b3adae054e
|
4
|
+
data.tar.gz: 07fa8a19999969c0a18b91b841832dd0cefa0072
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c63cfa1c75c614fc3d827cf0d248003213e9cc70f6c8d36756ba9d91abb906ecd6e02ce950721a7fbe23b88c246db54289ba26356ed0ca7ee72d40530ade099
|
7
|
+
data.tar.gz: 18fa9a69da7c174091d1567664d7564f16e4ed714b8658bbcaada7c137d8ae530e47bdbf62abafd2e977c7d5095d3b2f89240b45dd3c24ca87cec94165ce5a39
|
data/lib/simple_life_game.rb
CHANGED
@@ -2,10 +2,10 @@ require "colorize"
|
|
2
2
|
require_relative "cell"
|
3
3
|
|
4
4
|
class LifeGame
|
5
|
-
def initialize(width = 60,
|
5
|
+
def initialize(width = 60, height = 40)
|
6
6
|
@width = width
|
7
|
-
@
|
8
|
-
@card = Array.new(
|
7
|
+
@height = height
|
8
|
+
@card = Array.new(height) { Array.new(width) { Cell.new } }
|
9
9
|
end
|
10
10
|
|
11
11
|
def next_gen!
|
@@ -23,8 +23,8 @@ class LifeGame
|
|
23
23
|
|
24
24
|
private
|
25
25
|
def alive_neighbors(y, x)
|
26
|
-
up = (y == 0) ? @
|
27
|
-
down = (y == @
|
26
|
+
up = (y == 0) ? @height - 1 : y - 1
|
27
|
+
down = (y == @height - 1) ? 0 : y + 1
|
28
28
|
left = (x == 0) ? @width - 1 : x - 1
|
29
29
|
right = (x == @width - 1) ? 0 : x + 1
|
30
30
|
|