game-of-life 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/Rakefile +0 -1
- data/lib/game-of-life/version.rb +1 -1
- data/lib/game-of-life/world.rb +0 -161
- data/lib/game_of_life.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67536893d2d077305cfd3a540499d0dc82f59e43
|
4
|
+
data.tar.gz: 0ba82c03708bc559b5d61077d937a9b6020263d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fad7965e961f82145e4f3e14fd23fb63113ad94aa6b8f8946411dfe90b136b53a659380b5953888ad11bd7e773ba6d086db0d38bcfc7351d92f881f3317b58c
|
7
|
+
data.tar.gz: f02d31e33d65d0d08d69757759e764560eabde3cb47e89f94d641ce8147d1a82bf0c07a7f74d3e14bc73815b10f7f22a4d72854c430eae22837cf876faeca515
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
The Game of Life
|
2
|
+
============
|
3
|
+
![pictureGallery](https://lh4.googleusercontent.com/-1vaiRa4FP6Y/UpOhsmoFtDI/AAAAAAAABbY/WlEbsDYOpMA/w804-h622-no/gol.png "screenshot")
|
4
|
+
|
5
|
+
This is an implementation of [Conway's Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life "Conway's Game of Life") the TDD way, with Ruby :)
|
6
|
+
|
7
|
+
I used **minitest** for testing and **gosu** to display the game on the screen.
|
8
|
+
|
9
|
+
##Installing
|
10
|
+
|
11
|
+
To install the game, run:
|
12
|
+
|
13
|
+
> `gem install game-of-life`
|
14
|
+
|
15
|
+
If you're using ruby 2.X, **gosu** may crash the installation because of some missing dependencies. To avoid that,
|
16
|
+
before installing the game, you must install the libraries **libogg** and **libvorbis**. You can install them with brew:
|
17
|
+
|
18
|
+
> `brew install libogg` and `brew install libvorbis`
|
19
|
+
|
20
|
+
##Running the game
|
21
|
+
|
22
|
+
On your terminal, run the command:
|
23
|
+
|
24
|
+
> `game-of-life`
|
25
|
+
|
26
|
+
Have fun!
|
data/Rakefile
CHANGED
data/lib/game-of-life/version.rb
CHANGED
data/lib/game-of-life/world.rb
CHANGED
@@ -122,12 +122,6 @@ module GameOfLife
|
|
122
122
|
cell.dead? and live_neighbours.count == 3
|
123
123
|
end
|
124
124
|
|
125
|
-
def rebuild_board(live_cells,dead_cells)
|
126
|
-
(live_cells+dead_cells).each do |cell|
|
127
|
-
@board.set(cell.x,cell.y,cell)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
125
|
def setup(random)
|
132
126
|
@board = Matrix.build(@width, @height) { |row,column|
|
133
127
|
if random
|
@@ -158,159 +152,4 @@ module GameOfLife
|
|
158
152
|
@board = nil
|
159
153
|
end
|
160
154
|
end
|
161
|
-
# class World
|
162
|
-
# attr_accessor :cells, :board
|
163
|
-
# attr_reader :width, :height
|
164
|
-
|
165
|
-
# def initialize(width=10, height=10, allow_negative_cells=true)
|
166
|
-
# @width, @height = width, height
|
167
|
-
# @negative = allow_negative_cells
|
168
|
-
# @cells = []
|
169
|
-
|
170
|
-
# setup_board
|
171
|
-
# end
|
172
|
-
|
173
|
-
# def dead_cells
|
174
|
-
# @cells.select { |cell| cell.dead? }
|
175
|
-
# end
|
176
|
-
|
177
|
-
# def live_cells
|
178
|
-
# @cells.select { |cell| cell.alive? }
|
179
|
-
# end
|
180
|
-
|
181
|
-
# def seed!
|
182
|
-
# for x in (0).upto(@width-1) do
|
183
|
-
# for y in (0).upto(@height-1) do
|
184
|
-
# cell = Cell.new(x,y,[true,false].sample)
|
185
|
-
# @cells << cell
|
186
|
-
# @board[x][y] = cell
|
187
|
-
# end
|
188
|
-
# end
|
189
|
-
# end
|
190
|
-
|
191
|
-
# # up_left | up | up_right
|
192
|
-
# # ----------|------|-----------
|
193
|
-
# # left | cell | right
|
194
|
-
# # ----------|------|-----------
|
195
|
-
# # down_left | down | down_right
|
196
|
-
# def live_neighbours_of(cell)
|
197
|
-
# live_neighbours = []
|
198
|
-
|
199
|
-
# up_left = Cell.new(cell.x-1,cell.y+1)
|
200
|
-
# up = Cell.new(cell.x,cell.y+1)
|
201
|
-
# up_right = Cell.new(cell.x+1,cell.y+1)
|
202
|
-
# left = Cell.new(cell.x-1,cell.y)
|
203
|
-
# right = Cell.new(cell.x+1,cell.y)
|
204
|
-
# down_left = Cell.new(cell.x-1,cell.y-1)
|
205
|
-
# down = Cell.new(cell.x,cell.y-1)
|
206
|
-
# down_right = Cell.new(cell.x+1,cell.y-1)
|
207
|
-
|
208
|
-
# neighbour_candidates = [up_left,up,up_right,left,right,down_left,down,down_right]
|
209
|
-
|
210
|
-
# neighbour_candidates.each do |neighbour|
|
211
|
-
# live_neighbours << @board[neighbour.x][neighbour.y] if not outside_of_the_world?(neighbour) and neighbour.alive?
|
212
|
-
# end
|
213
|
-
|
214
|
-
# live_neighbours
|
215
|
-
# end
|
216
|
-
|
217
|
-
# def exist?(cell)
|
218
|
-
# @cells.include? cell
|
219
|
-
# end
|
220
|
-
|
221
|
-
# def rotate!
|
222
|
-
# future_alive_cells = []
|
223
|
-
# future_dead_cells = []
|
224
|
-
|
225
|
-
# @cells.each do |cell|
|
226
|
-
# num_live_neighbours = live_neighbours_of(cell).count
|
227
|
-
|
228
|
-
# # Rule #1
|
229
|
-
# if cell.alive? and num_live_neighbours < 2
|
230
|
-
# future_dead_cells << cell
|
231
|
-
# end
|
232
|
-
|
233
|
-
# # Rule #2
|
234
|
-
# if live_neighbours_of(cell).count == 2 or live_neighbours_of(cell).count == 3
|
235
|
-
# future_alive_cells << cell
|
236
|
-
# end
|
237
|
-
|
238
|
-
# # Rule #3
|
239
|
-
# if cell.alive? and num_live_neighbours > 3
|
240
|
-
# future_dead_cells << cell
|
241
|
-
# end
|
242
|
-
|
243
|
-
# # Rule #4
|
244
|
-
# if cell.dead? and num_live_neighbours == 3
|
245
|
-
# future_alive_cells << cell
|
246
|
-
# end
|
247
|
-
|
248
|
-
# update_cells(future_alive_cells,future_dead_cells)
|
249
|
-
# end
|
250
|
-
# end
|
251
|
-
|
252
|
-
# def create(cell)
|
253
|
-
# # raise CellAlreadyExistsInTheWorldException if exist?(cell)
|
254
|
-
# raise CellInvalidCoordinatesException if outside_of_the_world?(cell) or negative_coordinates?(cell)
|
255
|
-
# @cells << cell
|
256
|
-
# end
|
257
|
-
|
258
|
-
# def revive(cell)
|
259
|
-
# raise CellIsAlreadyAliveException if exist?(cell) and cell.alive?
|
260
|
-
# cell.reborn!
|
261
|
-
# end
|
262
|
-
|
263
|
-
# def kill(cell)
|
264
|
-
# raise CellIsAlreadyDeadException if exist?(cell) and cell.dead?
|
265
|
-
# cell.die!
|
266
|
-
# end
|
267
|
-
|
268
|
-
# private
|
269
|
-
# def setup_board
|
270
|
-
# @board = Array.new(@width) do |row|
|
271
|
-
# Array.new(@height) do |column|
|
272
|
-
# Cell.new(row,column)
|
273
|
-
# end
|
274
|
-
# end
|
275
|
-
|
276
|
-
# @board.each do |row|
|
277
|
-
# row.each do |column|
|
278
|
-
# @cells << column
|
279
|
-
# end
|
280
|
-
# end
|
281
|
-
# end
|
282
|
-
|
283
|
-
# def update_cells(alives,deads)
|
284
|
-
# alives.each do |cell|
|
285
|
-
# cell.reborn!
|
286
|
-
# end
|
287
|
-
# deads.each do |cell|
|
288
|
-
# cell.die!
|
289
|
-
# end
|
290
|
-
# end
|
291
|
-
|
292
|
-
# def apply_rule_1(cell,number_of_live_neighbours)
|
293
|
-
# kill(cell) if cell.alive? and number_of_live_neighbours < 2
|
294
|
-
# end
|
295
|
-
|
296
|
-
# def apply_rule_2(cell)
|
297
|
-
# # revive(cell) if live_neighbours_of(cell).count == 2 or live_neighbours_of(cell).count == 3
|
298
|
-
# end
|
299
|
-
|
300
|
-
# def apply_rule_3(cell,number_of_live_neighbours)
|
301
|
-
# kill(cell) if cell.alive? and number_of_live_neighbours > 3
|
302
|
-
# end
|
303
|
-
|
304
|
-
# def apply_rule_4(cell,number_of_live_neighbours)
|
305
|
-
# revive(cell) if cell.dead? and number_of_live_neighbours == 3
|
306
|
-
# end
|
307
|
-
|
308
|
-
# def outside_of_the_world?(cell)
|
309
|
-
# (cell.x > @width) or (cell.y > @height)
|
310
|
-
# end
|
311
|
-
|
312
|
-
# def negative_coordinates?(cell)
|
313
|
-
# (cell.x < 0) or (cell.y < 0) and not @negative
|
314
|
-
# end
|
315
|
-
# end
|
316
155
|
end
|
data/lib/game_of_life.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: game-of-life
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago Rocha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -48,6 +48,7 @@ extra_rdoc_files: []
|
|
48
48
|
files:
|
49
49
|
- Gemfile
|
50
50
|
- Gemfile.lock
|
51
|
+
- README.md
|
51
52
|
- Rakefile
|
52
53
|
- bin/game-of-life
|
53
54
|
- game-of-life.gemspec
|