conway_deathmatch 0.4.0.3 → 0.4.1.1

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: c55f0ff917347b974ee425de2f25661dc4ee0364
4
- data.tar.gz: 326a6784a63cc061b677798fcb92d8ddc0c9b500
3
+ metadata.gz: 4c99458e1f16832079d5dec01f15b43b05d0062e
4
+ data.tar.gz: d99447fcdf8a6ef51f8078e5c9783dabd44a5649
5
5
  SHA512:
6
- metadata.gz: 6c894e1ac6f4cb133e70273b005d950569935f7f95e2078ea5ac1236f9133ce937c4d45911bedaf083de830c8d93b8a5e322fce3a8da59f027c9ce58d935fce7
7
- data.tar.gz: 5fdecf2a42232cc7e4d2dae02fa4692a4a8783a31824766643b0dc4e1f860bcc04f703555eff33fc6e2ab4e337dfda56797e859e675a347ecaf939a1c79e37bd
6
+ metadata.gz: 8528c9fcb640e4291b7d1adeb50c68fe0e555af1000f201322f0c0174ef5de4f7cb36bc49d8ffb680214d35b25e84b1b451ed56c3c22ee39e74df02528ba3fef
7
+ data.tar.gz: 8da6e47b4acd9b7fa42fa391875e642661437aceaa3d841e3fad91456de294f235abe2aeafa85145b6536d4cf2bb1ef47a5a8cfa7a572c1add1f68a92763d6e7
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0.3
1
+ 0.4.1.1
@@ -24,11 +24,11 @@ Gem::Specification.new do |s|
24
24
  'test/test_shapes.rb',
25
25
  ]
26
26
  s.executables = ['conway_deathmatch']
27
+ s.add_runtime_dependency "slop", "~> 3.0"
27
28
  s.add_development_dependency "buildar", "~> 2"
28
29
  s.add_development_dependency "minitest", "~> 5"
29
30
  s.add_development_dependency "ruby-prof", "~> 0"
30
31
  # uncomment and set ENV['CODE_COVERAGE']
31
32
  # s.add_development_dependency "simplecov", "~> 0.9.0"
32
- s.add_runtime_dependency "slop", "~> 3.0"
33
33
  s.required_ruby_version = "~> 2"
34
34
  end
@@ -1,3 +1,4 @@
1
+ #require 'lager'
1
2
  module ConwayDeathmatch; end # create namespace
2
3
 
3
4
  # data structure for the board - 2d array
@@ -5,6 +6,8 @@ module ConwayDeathmatch; end # create namespace
5
6
  # static boundaries are treated as dead
6
7
  #
7
8
  class ConwayDeathmatch::BoardState
9
+ # extend Lager
10
+ # log_to $stderr
8
11
  class BoundsError < RuntimeError; end
9
12
 
10
13
  DEAD = '.'
@@ -24,20 +27,30 @@ class ConwayDeathmatch::BoardState
24
27
  @y_len = y_len
25
28
  @state = self.class.new_state(x_len, y_len)
26
29
  @deathmatch = deathmatch
30
+ # @lager = self.class.lager
27
31
  end
28
32
 
29
33
  # Conway's Game of Life transition rules
30
34
  def next_value(x, y)
35
+ # don't bother toroidaling, only called by #tick
31
36
  n, birthright = neighbor_stats(x, y)
32
- if alive?(x, y)
37
+ if @state[x][y] != DEAD
33
38
  (n == 2 or n == 3) ? birthright : DEAD
34
39
  else
35
40
  (n == 3) ? birthright : DEAD
36
41
  end
37
42
  end
38
43
 
44
+ def value(x, y)
45
+ x = x % @x_len
46
+ y = y % @y_len
47
+ @state[x][y]
48
+ end
49
+
39
50
  # total (alive) neighbor count and birthright
40
51
  def neighbor_stats(x, y)
52
+ x = x % @x_len
53
+ y = y % @y_len
41
54
  npop = neighbor_population(x, y).tap { |h| h.delete(DEAD) }
42
55
 
43
56
  case @deathmatch
@@ -83,29 +96,15 @@ class ConwayDeathmatch::BoardState
83
96
  end
84
97
  end
85
98
 
86
- def value(x, y)
87
- in_bounds!(x,y)
88
- @state[x][y].dup
89
- end
90
-
91
- def in_bounds?(x, y)
92
- x.between?(0, @x_len - 1) and y.between?(0, @y_len - 1)
93
- end
94
-
95
- def in_bounds!(x, y)
96
- raise(BoundsError, "(#{x}, #{y})") unless in_bounds?(x, y)
97
- end
98
-
99
- # out of bounds considered dead
100
- def alive?(x, y)
101
- @state[x][y] != DEAD rescue false
102
- end
103
-
104
99
  # population of every neighboring entity, including DEAD
105
100
  def neighbor_population(x, y)
101
+ x = x % @x_len
102
+ y = y % @y_len
106
103
  neighbors = Hash.new(0)
107
- (x-1 > 0 ? x-1 : 0).upto(x+1 < @x_len ? x+1 : @x_len - 1) { |xn|
108
- (y-1 > 0 ? y-1 : 0).upto(y+1 < @y_len ? y+1 : @y_len - 1) { |yn|
104
+ (x-1).upto(x+1) { |xn|
105
+ (y-1).upto(y+1) { |yn|
106
+ xn = xn % @x_len
107
+ yn = yn % @y_len
109
108
  neighbors[@state[xn][yn]] += 1 unless (xn == x and yn == y)
110
109
  }
111
110
  }
@@ -122,18 +121,19 @@ class ConwayDeathmatch::BoardState
122
121
  self
123
122
  end
124
123
 
125
- # set a single point, raise on OOB
124
+ # set a single point
126
125
  def populate(x, y, val = ALIVE)
127
- in_bounds!(x, y)
126
+ x = x % @x_len
127
+ y = y % @y_len
128
128
  @state[x][y] = val
129
129
  end
130
130
 
131
- # set several points (2d array), ignore OOB
131
+ # set several points (2d array)
132
132
  def add_points(points, x_off = 0, y_off = 0, val = ALIVE)
133
133
  points.each { |point|
134
- x = point[0] + x_off
135
- y = point[1] + y_off
136
- @state[x][y] = val if self.in_bounds?(x, y)
134
+ x = (point[0] + x_off) % @x_len
135
+ y = (point[1] + y_off) % @y_len
136
+ @state[x][y] = val
137
137
  }
138
138
  self
139
139
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conway_deathmatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.3
4
+ version: 0.4.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-12-17 00:00:00.000000000 Z
11
+ date: 2014-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: buildar
14
+ name: slop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2'
20
- type: :development
19
+ version: '3.0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: minitest
28
+ name: buildar
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5'
33
+ version: '2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5'
40
+ version: '2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: ruby-prof
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '5'
55
55
  - !ruby/object:Gem::Dependency
56
- name: slop
56
+ name: ruby-prof
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
62
- type: :runtime
61
+ version: '0'
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
68
+ version: '0'
69
69
  description: Deathmatch
70
70
  email:
71
71
  executables:
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.4.5
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Conway's Game of Life