conway_deathmatch 0.3.0.1 → 0.3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/conway_deathmatch/board_state.rb +20 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74cb09c10b150b79fde2d90b7ec9f19ba734ea45
|
4
|
+
data.tar.gz: afab5401c02eacf4f0fdbcba7635248d030e77ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bd27fa170687568717234356174f09cf3fc57fbb20e2516c46cdad921a81b6db4c78983a976b553afc3f496ca05091d4ccd0264187542a7b70b621ccce4d24f
|
7
|
+
data.tar.gz: dafed28ce3008911055047b5ca22aaeb3b049b5735965542f6ee156d4a22c78c03ae194546dcc48f0efcded14af0066bdafe0ded84e88de33e1e861d1bae2ff8
|
@@ -19,9 +19,8 @@ class ConwayDeathmatch::BoardState
|
|
19
19
|
attr_accessor :multiplayer
|
20
20
|
|
21
21
|
def initialize(x_len, y_len)
|
22
|
-
|
23
|
-
@
|
24
|
-
@yr = (0...y_len)
|
22
|
+
@x_len = x_len
|
23
|
+
@y_len = y_len
|
25
24
|
@state = self.class.new_state(x_len, y_len)
|
26
25
|
@multiplayer = false
|
27
26
|
end
|
@@ -42,26 +41,28 @@ class ConwayDeathmatch::BoardState
|
|
42
41
|
end
|
43
42
|
|
44
43
|
def in_bounds?(x, y)
|
45
|
-
|
44
|
+
x.between?(0, @x_len - 1) and y.between?(0, @y_len - 1)
|
46
45
|
end
|
47
46
|
|
48
47
|
def in_bounds!(x, y)
|
49
|
-
raise(BoundsError, "(#{x}, #{y})
|
48
|
+
raise(BoundsError, "(#{x}, #{y})") unless in_bounds?(x, y)
|
50
49
|
end
|
51
50
|
|
52
51
|
# out of bounds considered dead
|
53
52
|
def alive?(x, y)
|
54
|
-
|
53
|
+
@state[x][y] != DEAD rescue false
|
55
54
|
end
|
56
55
|
|
57
56
|
# population of each neighbor
|
58
57
|
def neighbor_population(x, y)
|
58
|
+
outer_ring = x == 0 or y == 0 or x == @x_len - 1 or y == @y_len - 1
|
59
59
|
neighbors = Hash.new(0)
|
60
60
|
(x-1..x+1).each { |xn|
|
61
|
+
next if outer_ring and xn < 0 or xn >= @x_len
|
61
62
|
(y-1..y+1).each { |yn|
|
62
|
-
if
|
63
|
-
|
64
|
-
|
63
|
+
next if outer_ring and yn < 0 or yn >= @y_len
|
64
|
+
next if xn == x and yn == y # don't count self
|
65
|
+
neighbors[@state[xn][yn]] += 1
|
65
66
|
}
|
66
67
|
}
|
67
68
|
neighbors
|
@@ -82,14 +83,21 @@ class ConwayDeathmatch::BoardState
|
|
82
83
|
}
|
83
84
|
[total, birthright]
|
84
85
|
else
|
85
|
-
|
86
|
+
count = 0
|
87
|
+
neighbor_population(x, y).each { |sym, cnt|
|
88
|
+
next if sym == DEAD
|
89
|
+
count += cnt
|
90
|
+
}
|
91
|
+
[count, ALIVE]
|
86
92
|
end
|
87
93
|
end
|
88
94
|
|
89
95
|
# generate the next state table
|
90
96
|
def tick
|
91
|
-
new_state = self.class.new_state(@
|
92
|
-
@
|
97
|
+
new_state = self.class.new_state(@x_len, @y_len)
|
98
|
+
@x_len.times { |x|
|
99
|
+
@y_len.times { |y| new_state[x][y] = next_value(x, y) }
|
100
|
+
}
|
93
101
|
@state = new_state
|
94
102
|
self
|
95
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conway_deathmatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Hull
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: buildar
|