life 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,21 @@ A ruby implementation of Conway's [game of life](http://en.wikipedia.org/wiki/Co
8
8
 
9
9
  ## Usage
10
10
 
11
- TODO: Write usage instructions here
11
+ To use Life, run the `life new` command. It can be used with the following options
12
+ * `--width` or `-w` specifies how many cells wide the game will be
13
+ * `--height` or `-h` specifies how many cells high the game will be
14
+ * `--generations` or `-g` specifies how many generations the simulation will run
15
+
16
+ ```
17
+ $ life new -w 3 -h 4 -g 5
18
+ ```
19
+ This will create a 3x4 game that runs for 5 generations
20
+
21
+ When first creating a game, you will be prompted to enter which cells are initially alive.
22
+
23
+ ## TODO
24
+ * Ability to pass initial configuration as command-line option
25
+ * Animate instead of displaying all the generations
12
26
 
13
27
  ## Contributing
14
28
 
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ $:.unshift File.expand_path("../../lib", __FILE__)
5
+ require 'life/cli'
6
+ puts "run"
7
+ Life::CLI::Base.start
@@ -3,6 +3,7 @@ require 'life/cell'
3
3
  require 'life/world'
4
4
  require 'life/grid'
5
5
 
6
+ require 'life/cli'
7
+
6
8
  module Life
7
- # Your code goes here...
8
9
  end
@@ -0,0 +1,45 @@
1
+ require 'thor'
2
+ require 'life'
3
+
4
+ module Life
5
+ module CLI
6
+ class Base < Thor
7
+ include Thor::Actions
8
+
9
+ default_task :help
10
+
11
+ desc :new, "Create new game"
12
+ method_option :width, :type => :numeric, :aliases => '-w', :desc => "Width of board", :required => true
13
+ method_option :height, :type => :numeric,:aliases => '-h', :desc => "Height of board", :required => true
14
+ method_option :generations, :type => :numeric,:aliases => '-g', :desc => "How many generations to display", :required => true
15
+
16
+ def new
17
+ seed = []
18
+ while yes? "Would you like to add a live cell to the grid? [Y/n]"
19
+ x = ask "Please enter x coordinate"
20
+ y = ask "Please enter y coordinate"
21
+ seed << [(x.to_i) - 1, (y.to_i) -1]
22
+ end
23
+
24
+ world = World.new options[:width], options[:height], seed
25
+
26
+ (1..options[:generations]).each do |gen|
27
+ puts "== Generation #{gen} =="
28
+ draw(world)
29
+ puts ""
30
+ world.tick
31
+ end
32
+ end
33
+
34
+ def draw(world)
35
+ world.current.each do |row|
36
+ processed_row = row.map { |cell| cell.live? ? "@" : "_"}
37
+ print "["
38
+ print processed_row.join(' ')
39
+ puts "]"
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Life
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -15,5 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Life::VERSION
17
17
 
18
+ gem.add_runtime_dependency "thor", "~> 0.16.0"
19
+
18
20
  gem.add_development_dependency 'rspec'
19
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: life
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,6 +11,22 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.16.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.16.0
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: rspec
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -30,7 +46,8 @@ dependencies:
30
46
  description: Conway's Game of life in ruby
31
47
  email:
32
48
  - joel.quenneville@collegeplus.org
33
- executables: []
49
+ executables:
50
+ - life
34
51
  extensions: []
35
52
  extra_rdoc_files: []
36
53
  files:
@@ -40,8 +57,10 @@ files:
40
57
  - LICENSE
41
58
  - README.md
42
59
  - Rakefile
60
+ - bin/life
43
61
  - lib/life.rb
44
62
  - lib/life/cell.rb
63
+ - lib/life/cli.rb
45
64
  - lib/life/grid.rb
46
65
  - lib/life/version.rb
47
66
  - lib/life/world.rb