life 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +8 -5
  2. data/lib/life/cli.rb +25 -29
  3. data/lib/life/version.rb +1 -1
  4. metadata +1 -1
data/README.md CHANGED
@@ -15,14 +15,17 @@ To use Life, run the `life new` command. It can be used with the following optio
15
15
  * '--seed' or '-s' is the initial pattern of the game. Pass coordinate pairs using the following pattern: `x:y x:y x:y ...`
16
16
 
17
17
  ```
18
- $ life new -w 3 -h 4 -g 5
18
+ $ life new -w 3 -h 4 -g 5 -s 3:2 1:1
19
19
  ```
20
- This will create a 3x4 game that runs for 5 generations
20
+ This will create a 3x4 game that runs for 5 generations. The live cells in the starting pattern are `3,2` and `1,1`
21
21
 
22
- When first creating a game, you will be prompted to add cells some live cells.
22
+ ## Pre-built configurations
23
+ ### Random
24
+ You can use a random initial pattern if you don't feel like building one yourself. Options are the same as for the new method except that no seed is passed.
23
25
 
24
- ## TODO
25
- * Add some default configurations to start the fun
26
+ ```
27
+ $ life random -w 10 -h 10 -g 5
28
+ ```
26
29
 
27
30
  ## Contributing
28
31
 
@@ -12,18 +12,25 @@ module Life
12
12
  method_option :width, :type => :numeric, :aliases => '-w', :desc => "Width of board", :required => true
13
13
  method_option :height, :type => :numeric,:aliases => '-h', :desc => "Height of board", :required => true
14
14
  method_option :generations, :type => :numeric,:aliases => '-g', :desc => "How many generations to display", :required => true
15
- method_option :seed, :type => :array, :aliases => '-s', :desc => "Initial Pattern"
15
+ method_option :seed, :type => :array, :aliases => '-s', :desc => "Initial Pattern", :required => true
16
16
 
17
17
  def new
18
18
  seed = build_seed(options[:seed])
19
19
  max_gen = options[:generations]
20
- world = build_world(options[:width], options[:height], seed)
20
+ world = World.new(options[:height], options[:width], seed)
21
+ display_simulation max_gen, options[:height], world
22
+ end
21
23
 
22
- (1..max_gen).each do |gen|
23
- print world.to_s("@", "_") + eol(options[:height], gen, max_gen)
24
- sleep(1)
25
- world.tick
26
- end
24
+ desc :random, "Create new game with random starting pattern"
25
+ method_option :width, :type => :numeric, :aliases => '-w', :desc => "Width of board", :required => true
26
+ method_option :height, :type => :numeric,:aliases => '-h', :desc => "Height of board", :required => true
27
+ method_option :generations, :type => :numeric,:aliases => '-g', :desc => "How many generations to display", :required => true
28
+
29
+ def random
30
+ seed = build_random_seed options[:width], options[:height]
31
+ max_gen = options[:generations]
32
+ world = World.new(options[:height], options[:width], seed)
33
+ display_simulation max_gen, options[:height], world
27
34
  end
28
35
 
29
36
  no_tasks do
@@ -35,33 +42,22 @@ module Life
35
42
  pattern.map {|pair| pair.split(":").map { |coord| coord.to_i - 1 } }
36
43
  end
37
44
 
38
- def build_world(width, height, seed=[])
39
- while yes? "Would you like to add a live cell to the grid? [Y/n]"
40
- x = get_x(width)
41
- y = get_y(height)
42
- seed << [(x.to_i) - 1, (y.to_i) -1]
45
+ def build_random_seed(width, height)
46
+ seed = []
47
+ seed_count = rand(1..(width*height/2))
48
+ seed_count.times do
49
+ seed << [rand(height-1), rand(width-1)]
43
50
  end
44
- World.new height, width, seed
51
+ seed
45
52
  end
46
53
 
47
- def get_x(width)
48
- x = ask("Please enter x coordinate").to_i
49
- while x > width
50
- puts "This number is too big"
51
- x = ask("Please enter x coordinate").to_i
54
+ def display_simulation(max_gen, height, world)
55
+ (1..max_gen).each do |gen|
56
+ print world.to_s("@", "_") + eol(height, gen, max_gen)
57
+ sleep(1)
58
+ world.tick
52
59
  end
53
- return x
54
60
  end
55
-
56
- def get_y(height)
57
- y = ask("Please enter y coordinate").to_i
58
- while y > height
59
- puts "This number is too big"
60
- y = ask("Please enter y coordinate").to_i
61
- end
62
- return y
63
- end
64
-
65
61
  end
66
62
 
67
63
  end
@@ -1,3 +1,3 @@
1
1
  module Life
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  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: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: