Gol_Col 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ab0740a497c1e2cc96d4dd434ff3221fc31be930edd07a2a1da06dfd78817d72
4
+ data.tar.gz: 1b34c2fb738b23a2ae62e1ea6c05980dfc93b44fef7444e60c7dc072795e3a40
5
+ SHA512:
6
+ metadata.gz: 1bcb1f5a06b7356bdfa611c7959f1daacf9be781b61e834b42f5e60ba8dad4ec86a4a96a534c64d706e93f0df6316e2a583712120c8c6e33d879a151a4efaf44
7
+ data.tar.gz: 90edb9c3d390e5bd8e0084131f04585bf2741a35de27f075206435bfec63bac5a5318cd7a0cdcfbaf61d37bf092900bdb755eae9237aa210eecdf297d3bac001
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Gol_Col"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/GameOfLife.rb ADDED
@@ -0,0 +1,62 @@
1
+ class GameOfLife
2
+ attr_accessor :row
3
+ attr_accessor :column
4
+ attr_accessor :last_row
5
+ attr_accessor :last_column
6
+
7
+ def initialize(row,column)
8
+ @row = row
9
+ @column = column
10
+ @last_row = row.to_i-1
11
+ @last_column = column.to_i-1
12
+ end
13
+ def display_board(board)
14
+ board.each.with_index do |row, i|
15
+ row.each.with_index do |cell, j|
16
+ print board[i][j] == 1 ? "0" : " "
17
+ end
18
+ puts
19
+ end
20
+ end
21
+ def get_neighbors(board, row, column)
22
+ row_max = [row - 1, 0].max
23
+ row_min = [row + 1, @last_row.to_i].min
24
+ column_max = [column - 1, 0].max
25
+ column_min = [column + 1, @last_column].min
26
+ array_neighbors = []
27
+ (row_max..row_min).each do |i|
28
+ (column_max..column_min).each do |j|
29
+ unless i == row and j == column
30
+ array_neighbors << board[i][j]
31
+ end
32
+ end
33
+ end
34
+ return array_neighbors.inject(:+)
35
+ end
36
+ def next_board(board)
37
+ i = 1
38
+ while i <= 100
39
+ temp_board = Array.new(@row){Array.new(@column){ 0 } }
40
+ system("clear")
41
+ board.each.with_index do |row, i|
42
+ row.each.with_index do |cell, j|
43
+ neighbors = get_neighbors(board,i,j)
44
+ if board[i][j] == 1 and neighbors < 2
45
+ temp_board[i][j] = 0
46
+ elsif board[i][j] == 1 and neighbors > 3
47
+ temp_board[i][j] = 0
48
+ elsif board[i][j] == 1 and neighbors == 3 || neighbors == 2
49
+ temp_board[i][j] = 1
50
+ elsif board[i][j] == 0 and neighbors == 3
51
+ temp_board[i][j] = 1
52
+ end
53
+ end
54
+ end
55
+ board = temp_board
56
+ display_board(board)
57
+ puts "Iterations: #{i}"
58
+ sleep(0.2)
59
+ i+=1
60
+ end
61
+ end
62
+ end
data/lib/Gol_Col.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "Gol_Col/version"
2
+ require "GameOfLife"
3
+
4
+ module GolCol
5
+ def start
6
+ puts "[...The game stops after 100 iterations...]"
7
+ print "Insert row length: "
8
+ row = gets.chop.to_i
9
+ print "Insert column length: "
10
+ column = gets.chop.to_i
11
+ board = Array.new(row){Array.new(column){ rand(0..1) } }
12
+ play = GameOfLife.new(row, column)
13
+ play.display_board(board)
14
+ play.next_board(board)
15
+ end
16
+ end
17
+
18
+ class Main
19
+ def self.start_game
20
+ include GolCol
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module GolCol
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Gol_Col
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ismael Villavicencio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-16 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ description:
70
+ email:
71
+ - villavicencioismael@gmail.com
72
+ executables:
73
+ - console
74
+ - setup
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - bin/console
79
+ - bin/setup
80
+ - lib/GameOfLife.rb
81
+ - lib/Gol_Col.rb
82
+ - lib/Gol_Col/version.rb
83
+ homepage: https://github.com/IsmaelVillavicencio/Gol_Col
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.7.6
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Conway's Game of Life is awesome gem.
107
+ test_files: []