gameoflife 0.0.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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +17 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +32 -0
  7. data/Rakefile +11 -0
  8. data/bin/gameoflife +10 -0
  9. data/data/oscillators/beacon/beacon_0.txt +6 -0
  10. data/data/oscillators/beacon/beacon_1.txt +6 -0
  11. data/data/oscillators/beacon/beacon_2.txt +7 -0
  12. data/data/oscillators/beacon/beacon_3.txt +6 -0
  13. data/data/oscillators/blinker/blinker_0.txt +4 -0
  14. data/data/oscillators/blinker/blinker_1.txt +5 -0
  15. data/data/oscillators/pulsar/pulsar_0.txt +17 -0
  16. data/data/oscillators/pulsar/pulsar_1.txt +17 -0
  17. data/data/oscillators/pulsar/pulsar_2.txt +17 -0
  18. data/data/oscillators/toad/toad_0.txt +6 -0
  19. data/data/oscillators/toad/toad_1.txt +7 -0
  20. data/data/spaceships/glider/glider_0.txt +18 -0
  21. data/data/spaceships/glider/glider_1.txt +18 -0
  22. data/data/spaceships/glider/glider_2.txt +18 -0
  23. data/data/spaceships/glider/glider_3.txt +18 -0
  24. data/data/spaceships/glider/glider_4.txt +18 -0
  25. data/data/spaceships/lightware-spaceship/lwss_0.txt +17 -0
  26. data/data/spaceships/lightware-spaceship/lwss_1.txt +17 -0
  27. data/data/spaceships/lightware-spaceship/lwss_2.txt +17 -0
  28. data/data/spaceships/lightware-spaceship/lwss_3.txt +17 -0
  29. data/data/spaceships/lightware-spaceship/lwss_4.txt +17 -0
  30. data/data/stilllifes/beehive/beehive.txt +5 -0
  31. data/data/stilllifes/block/block.txt +5 -0
  32. data/data/stilllifes/boat/boat.txt +5 -0
  33. data/data/stilllifes/circle/circle.txt +6 -0
  34. data/data/stilllifes/loaf/loaf.txt +8 -0
  35. data/gameoflife.gemspec +23 -0
  36. data/lib/gameoflife.rb +5 -0
  37. data/lib/gameoflife/core.rb +61 -0
  38. data/lib/gameoflife/game.rb +63 -0
  39. data/lib/gameoflife/runner.rb +24 -0
  40. data/lib/gameoflife/version.rb +3 -0
  41. data/test/run_all.sh +2 -0
  42. data/test/test_helper.rb +62 -0
  43. data/test/test_unit_functions.rb +43 -0
  44. data/test/test_whole_flow.rb +20 -0
  45. metadata +120 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ecddbd6f44c264451512125b1ffc0f2af9a83266
4
+ data.tar.gz: 29e84553f8be3a5726262ed4865d76500b74c937
5
+ SHA512:
6
+ metadata.gz: e76a5efd82bb7762340e01057925149adc727b93c4df75738f1304cf331f6e922f2c469612c3c4f291a97b16da2e9b5556c07315b9f87440b8e4cba844466c1f
7
+ data.tar.gz: 149939d3f34c9cfb47bea67e03d466d3573b55d8c015bf2f172ae964b43018c329fa49b5ecca914c9d0bb0bd3d446851355f9cbb251f680c20ff828de15cbcd0
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /pkg/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gameoflife.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gameoflife (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.1.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.3)
16
+ gameoflife!
17
+ rake
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 athom
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Gameoflife
2
+
3
+ A demo of Conway's Game of Life
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gameoflife'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gameoflife
18
+
19
+ ## Usage
20
+
21
+ - run with random data
22
+
23
+ gameoflife
24
+
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/test*.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
11
+
data/bin/gameoflife ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/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4
+ require 'gameoflife/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gameoflife"
8
+ spec.version = Gameoflife::VERSION
9
+ spec.authors = ["athom"]
10
+ spec.email = ["athom@126.com"]
11
+ spec.description = %q{A demo of Conway's Game of Life}
12
+ spec.summary = %q{A demo of Conway's Game of Life, defination could be found on http://en.wikipedia.org/wiki/Conway's_Game_of_Life}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/lib/gameoflife.rb ADDED
@@ -0,0 +1,5 @@
1
+ $: << File.dirname(__FILE__)
2
+ require 'gameoflife/version'
3
+ require 'gameoflife/core.rb'
4
+ require 'gameoflife/game.rb'
5
+ require 'gameoflife/runner.rb'
@@ -0,0 +1,61 @@
1
+ module GameOfLife
2
+ class Core
3
+ LIVE = 1
4
+ DEAD = nil
5
+ attr_reader :world
6
+ def initialize array
7
+ @world = {}
8
+ array.each_with_index do |row, row_index|
9
+ row.each_with_index do |e, col_index|
10
+ @world[[row_index, col_index]] = e
11
+ end
12
+ end
13
+
14
+ @world.reject!{|k, v|v.nil? || v == 0}
15
+ @static_world = @world.clone
16
+ end
17
+
18
+ def neighbor_count x, y
19
+ count_map = {}
20
+ (-1..1).each do |i|
21
+ (-1..1).each do |j|
22
+ count_map[[x+i,y+j]] = @static_world[[x+i,y+j]]
23
+ end
24
+ end
25
+ count_map.reject! {|k, v| v.nil?}
26
+ count_map.count - count_map[[x,y]].to_i
27
+ end
28
+
29
+ def next_world
30
+ visited_pos = {}
31
+ @static_world.each do |k, v|
32
+ x,y = k[0], k[1]
33
+ (-1..1).each do |i|
34
+ (-1..1).each do |j|
35
+ if not visited_pos[[x+i,y+j]]
36
+ @world[[x+i,y+j]] = next_state(x+i, y+j)
37
+ visited_pos[[x+i,y+j]] = true
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ @world.reject!{|k, v|v.nil?}
44
+ @static_world = @world.clone
45
+ end
46
+
47
+ def next_state x, y
48
+ conditions = {
49
+ 1 => DEAD,
50
+ 2 => @static_world[[x,y]],
51
+ 3 => LIVE,
52
+ 4 => DEAD,
53
+ 5 => DEAD,
54
+ 6 => DEAD,
55
+ 7 => DEAD,
56
+ 8 => DEAD
57
+ }[neighbor_count x, y]
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,63 @@
1
+ module GameOfLife
2
+ MAX_WIDTH = 30
3
+ MAX_HEIGH = 25
4
+
5
+ RAND_MIN_WIDTH = 3
6
+ RAND_MAX_WIDTH = 10
7
+ RAND_MIN_HEITG = 3
8
+ RAND_MAX_HEITG = 10
9
+
10
+ class Game
11
+ def initialize
12
+ if block_given?
13
+ yield self
14
+ end
15
+
16
+ @core = load_map generate_random_array
17
+ end
18
+
19
+ def generate_random_array
20
+ rd = Random.new(Random.new_seed)
21
+ width = rd.rand(RAND_MIN_WIDTH..RAND_MAX_WIDTH)
22
+ heigth = rd.rand(RAND_MIN_HEITG..RAND_MAX_HEITG)
23
+ array = []
24
+ (0..heigth).each do
25
+ row = []
26
+ (0..width).each do
27
+ row.push rd.rand(0..1)
28
+ end
29
+ array.push row
30
+ end
31
+ array
32
+ end
33
+
34
+ def load_map array
35
+ @core = Core.new(array)
36
+ end
37
+
38
+ def display_world
39
+ (-MAX_HEIGH..MAX_HEIGH).each do |i|
40
+ (-MAX_WIDTH..MAX_WIDTH).each do |j|
41
+ if @core.world[[i,j]].nil?
42
+ print " "
43
+ else
44
+ print " 1 "
45
+ end
46
+ end
47
+ puts ""
48
+ end
49
+ end
50
+
51
+ def single_step
52
+ @core.next_world
53
+ display_world
54
+ end
55
+
56
+ def run
57
+ while true
58
+ single_step
59
+ sleep 1
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,24 @@
1
+ require 'optparse'
2
+
3
+ module GameOfLife
4
+ class Runner
5
+ def initialize(arguments, stdin, stdout)
6
+ @arguments = arguments
7
+ @game = Game.new
8
+ end
9
+
10
+ def run
11
+ parse_options
12
+ @game.run
13
+ end
14
+
15
+ private
16
+
17
+ def parse_options
18
+ options = OptionParser.new
19
+ options.banner = "Usage: gameoflife [options]"
20
+ options.on('-h', '--help', "Show this message") { puts(options); exit }
21
+ options.parse!(@arguments)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Gameoflife
2
+ VERSION = "0.0.1"
3
+ end
data/test/run_all.sh ADDED
@@ -0,0 +1,2 @@
1
+ ruby test_unit_functions.rb
2
+ ruby test_whole_flow.rb
@@ -0,0 +1,62 @@
1
+ $LOAD_PATH << '.'
2
+ $LOAD_PATH.unshift(File.join( File.dirname(__FILE__), '..', 'lib' ))
3
+
4
+ require 'test/unit'
5
+ require 'gameoflife'
6
+
7
+ $prj_path = File.expand_path( File.join( File.dirname(__FILE__), '..' ) )
8
+
9
+ include GameOfLife
10
+
11
+ def get_test_cases
12
+ test_cases = {}
13
+ path = $prj_path + "/data/"
14
+ Dir.entries(path).reject!{|f| f == '.' or f == ".."}.each do |catalog|
15
+ test_suites = {}
16
+ Dir.entries(path + catalog).reject!{|f| f == '.' or f == ".."}.each do |suite|
17
+ test_suites[suite] = Dir.entries(path+catalog+"/"+suite).reject!{|f| f == '.' or f == ".."}
18
+ end
19
+ test_cases[catalog] = test_suites
20
+ end
21
+ test_cases
22
+ end
23
+
24
+ def get_file_content filename
25
+ file = File.join($prj_path, 'data', filename)
26
+ f = File.open(file, 'r')
27
+ content = f.read
28
+ f.close
29
+ content
30
+ end
31
+
32
+ def parse_to_map filename
33
+ hash ={}
34
+ lines = get_file_content(filename).split("\n")
35
+ lines.each_with_index do |line, row_index|
36
+ cols = line.split
37
+ cols.each_with_index do |c, col_index|
38
+ if c == '1'
39
+ hash[[row_index,col_index]] = Core::LIVE
40
+ end
41
+ end
42
+ end
43
+ hash
44
+ end
45
+
46
+ def parse_to_array filename
47
+ array = []
48
+ lines = get_file_content(filename).split("\n")
49
+ lines.each_with_index do |line, row_index|
50
+ row = []
51
+ cols = line.split
52
+ cols.each_with_index do |c, col_index|
53
+ if c == '1'
54
+ row.push Core::LIVE
55
+ else
56
+ row.push Core::DEAD
57
+ end
58
+ end
59
+ array.push row
60
+ end
61
+ array
62
+ end
@@ -0,0 +1,43 @@
1
+ $: << '.'
2
+ require_relative 'test_helper'
3
+
4
+ class TestCoreOfLifeUnit < Test::Unit::TestCase
5
+ def setup
6
+ map = [
7
+ [Core::DEAD, Core::LIVE, Core::DEAD],
8
+ [Core::DEAD, Core::DEAD, Core::LIVE],
9
+ [Core::LIVE, Core::LIVE, Core::DEAD]
10
+ ]
11
+ @c = Core.new(map)
12
+ end
13
+
14
+
15
+ def test_neighbor_count
16
+ assert_equal(@c.neighbor_count(0, 0), 1)
17
+ assert_equal(@c.neighbor_count(0, 1), 1)
18
+ assert_equal(@c.neighbor_count(0, 2), 2)
19
+
20
+ assert_equal(@c.neighbor_count(1, 0), 3)
21
+ assert_equal(@c.neighbor_count(1, 1), 4)
22
+ assert_equal(@c.neighbor_count(1, 2), 2)
23
+
24
+ assert_equal(@c.neighbor_count(2, 0), 1)
25
+ assert_equal(@c.neighbor_count(2, 1), 2)
26
+ assert_equal(@c.neighbor_count(2, 2), 2)
27
+ end
28
+
29
+ def test_next_state
30
+ assert_equal(@c.next_state(0, 0), Core::DEAD)
31
+ assert_equal(@c.next_state(0, 1), Core::DEAD)
32
+ assert_equal(@c.next_state(0, 2), Core::DEAD)
33
+
34
+ assert_equal(@c.next_state(1, 0), Core::LIVE)
35
+ assert_equal(@c.next_state(1, 1), Core::DEAD)
36
+ assert_equal(@c.next_state(1, 2), Core::LIVE)
37
+
38
+ assert_equal(@c.next_state(2, 0), Core::DEAD)
39
+ assert_equal(@c.next_state(2, 1), Core::LIVE)
40
+ assert_equal(@c.next_state(2, 2), Core::DEAD)
41
+ end
42
+
43
+ end
@@ -0,0 +1,20 @@
1
+ $: << '.'
2
+ require_relative 'test_helper'
3
+
4
+ class TestGameOfLifeFlow < Test::Unit::TestCase
5
+ def test_via_data
6
+ get_test_cases().each do |catalog, suites|
7
+ suites.each do |suite, cases|
8
+ map = parse_to_array(catalog + "/" + suite + "/" + cases[0])
9
+ c = Core.new(map)
10
+ cases.each_with_index do |name, i|
11
+ index = i+1
12
+ if index == cases.length
13
+ catalog == "spaceships" ? break : index = 0
14
+ end
15
+ assert_equal(c.next_world, parse_to_map(catalog + "/" + suite + "/" + cases[index]))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gameoflife
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - athom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A demo of Conway's Game of Life
42
+ email:
43
+ - athom@126.com
44
+ executables:
45
+ - gameoflife
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/gameoflife
56
+ - data/oscillators/beacon/beacon_0.txt
57
+ - data/oscillators/beacon/beacon_1.txt
58
+ - data/oscillators/beacon/beacon_2.txt
59
+ - data/oscillators/beacon/beacon_3.txt
60
+ - data/oscillators/blinker/blinker_0.txt
61
+ - data/oscillators/blinker/blinker_1.txt
62
+ - data/oscillators/pulsar/pulsar_0.txt
63
+ - data/oscillators/pulsar/pulsar_1.txt
64
+ - data/oscillators/pulsar/pulsar_2.txt
65
+ - data/oscillators/toad/toad_0.txt
66
+ - data/oscillators/toad/toad_1.txt
67
+ - data/spaceships/glider/glider_0.txt
68
+ - data/spaceships/glider/glider_1.txt
69
+ - data/spaceships/glider/glider_2.txt
70
+ - data/spaceships/glider/glider_3.txt
71
+ - data/spaceships/glider/glider_4.txt
72
+ - data/spaceships/lightware-spaceship/lwss_0.txt
73
+ - data/spaceships/lightware-spaceship/lwss_1.txt
74
+ - data/spaceships/lightware-spaceship/lwss_2.txt
75
+ - data/spaceships/lightware-spaceship/lwss_3.txt
76
+ - data/spaceships/lightware-spaceship/lwss_4.txt
77
+ - data/stilllifes/beehive/beehive.txt
78
+ - data/stilllifes/block/block.txt
79
+ - data/stilllifes/boat/boat.txt
80
+ - data/stilllifes/circle/circle.txt
81
+ - data/stilllifes/loaf/loaf.txt
82
+ - gameoflife.gemspec
83
+ - lib/gameoflife.rb
84
+ - lib/gameoflife/core.rb
85
+ - lib/gameoflife/game.rb
86
+ - lib/gameoflife/runner.rb
87
+ - lib/gameoflife/version.rb
88
+ - test/run_all.sh
89
+ - test/test_helper.rb
90
+ - test/test_unit_functions.rb
91
+ - test/test_whole_flow.rb
92
+ homepage: ''
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.0.6
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A demo of Conway's Game of Life, defination could be found on http://en.wikipedia.org/wiki/Conway's_Game_of_Life
116
+ test_files:
117
+ - test/run_all.sh
118
+ - test/test_helper.rb
119
+ - test/test_unit_functions.rb
120
+ - test/test_whole_flow.rb