gol_chido 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4fe23da17a9a358622dfb96dbe25f4c7d62acdf
4
+ data.tar.gz: 66307ba2f736acc5e15fab80c2bb975aa82bf6a9
5
+ SHA512:
6
+ metadata.gz: c4a33df6bc23fa1af14e889f59ec658849e92a79decbdf019fb871ca93afce015b4e0652e37e7c68276b957217178c5a88bbf33e3d242d90809485bd15f54839
7
+ data.tar.gz: 0ff10717a585dd019bfbbbe1b878668a037430bb81fd359b923b96bc45edf9463dd7de8bd9a820998e6df1751b759c4b2c6bd25e36fed36e39a1b28ab7f354e8
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at saulrubio98@hotmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in gol_chido.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gol_chido (0.1.0)
5
+ colorize (~> 0.8.1)
6
+ rspec
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ colorize (0.8.1)
12
+ diff-lcs (1.3)
13
+ rake (10.5.0)
14
+ rspec (3.7.0)
15
+ rspec-core (~> 3.7.0)
16
+ rspec-expectations (~> 3.7.0)
17
+ rspec-mocks (~> 3.7.0)
18
+ rspec-core (3.7.1)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-expectations (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-mocks (3.7.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.7.0)
26
+ rspec-support (3.7.1)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ bundler (~> 1.16)
33
+ gol_chido!
34
+ rake (~> 10.0)
35
+
36
+ BUNDLED WITH
37
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Saul Rubio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # GolChido
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gol_chido`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gol_chido'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gol_chido
22
+
23
+ ## Usage
24
+
25
+ Go to irb:
26
+
27
+ require 'gol_chido
28
+
29
+ GolChido::GameOfLife.new.start
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gol_chido. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
44
+
45
+ ## Code of Conduct
46
+
47
+ Everyone interacting in the GolChido project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gol_chido/blob/master/CODE_OF_CONDUCT.md).
48
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gol_chido"
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/gol_chido.gemspec ADDED
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gol_chido/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gol_chido"
8
+ spec.version = GolChido::VERSION
9
+ spec.authors = ["Saul Rubio"]
10
+ spec.email = ["saulrubio98@hotmail.com"]
11
+
12
+ spec.summary = %q{This a gem for base of Conway's Game of Life and it's for 0 players}
13
+ spec.description = %q{You can waste time looking how all the cells moves in the matrix, it's kind a fun}
14
+ spec.homepage = "https://github.com/rubiocanino/game_of_life_chido"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] ="https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = Dir.glob("{bin,lb}**/*")
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.16"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_dependency 'colorize', '~> 0.8.1'
37
+ spec.add_dependency 'rspec'
38
+
39
+ end
data/lib/board.rb ADDED
@@ -0,0 +1,158 @@
1
+ require_relative 'cell'
2
+ require 'colorize'
3
+
4
+ class Board
5
+ attr_accessor :board, :size, :squares, :borders
6
+ attr_reader :board
7
+
8
+ def initialize
9
+ size = 0
10
+ loop do
11
+ print 'Size of the board ? nxn: '
12
+ size = gets.chomp.to_i
13
+ break if size > 0
14
+ end
15
+ @size = size
16
+ @board = createBoard
17
+ @squares = squarePos(size)
18
+ @borders = borderPos(size)
19
+ checkKindCell
20
+ end
21
+
22
+ def createBoard
23
+ j = 1
24
+ board = []
25
+ loop do
26
+ board << Cell.new(j - 1)
27
+ break if j == @size * @size
28
+ j += 1
29
+ end
30
+
31
+ puts 'Your board have been created!'.colorize(:green)
32
+ puts "\n"
33
+ display(board)
34
+ board
35
+ end
36
+
37
+ def checkKindCell
38
+ @board.each_with_index do |cell, index|
39
+ kind = 'normal' unless @squares.include?(index) && @borders.include?(index)
40
+ kind = 'square' if @squares.include?(index)
41
+ kind = 'border' if @borders[0].include?(index)
42
+ kind = 'border' if @borders[1].include?(index)
43
+ kind = 'border' if @borders[2].include?(index)
44
+ kind = 'border' if @borders[3].include?(index)
45
+ cell.kind = kind
46
+ end
47
+ end
48
+
49
+ def display(board = @board)
50
+ i = 1
51
+ cut = []
52
+ loop do
53
+ cut << @size * i
54
+ i += 1
55
+ break if i >= @size * @size
56
+ end
57
+ puts "\n"
58
+ board.each_with_index do |cell, index|
59
+ print cell.state.colorize(:red) if cell.is_alive?
60
+ print cell.state unless cell.is_alive?
61
+ puts "\n" if cut.include?(index + 1)
62
+ end
63
+ puts "\n"
64
+ end
65
+
66
+ def randomCells
67
+ cells = 0
68
+ puts "\n"
69
+ puts '-- Random alive cells -- '.colorize(:blue)
70
+ loop do
71
+ print 'How many alive you want?: '
72
+ cells = gets.chomp.to_i
73
+ if (cells <= 0) || (cells > @size * @size)
74
+ print 'Sorry try again. '.colorize(:red)
75
+ gets.chomp
76
+ puts "\n"
77
+ system('clear')
78
+ end
79
+ break if (cells > 0) && (cells < @size * @size)
80
+ end
81
+
82
+ i = 0
83
+ loop do
84
+ numberCell = rand * @board.length
85
+ unless board[numberCell].is_alive?
86
+ board[numberCell].live
87
+ i += 1
88
+ end
89
+ break if i + 1 > cells
90
+ end
91
+ self
92
+ end
93
+
94
+ def manualCells
95
+ check = 't'
96
+ puts "\n"
97
+ puts '-- Manual alive cells --'.colorize(:blue)
98
+ loop do
99
+ print 'Index of the cell: '
100
+ index = gets.chomp.to_i
101
+ if @board[index].is_alive?
102
+ puts "It's already alive!".colorize(:red)
103
+ else
104
+ @board[index].live unless @board[index].is_alive?
105
+ puts "It's alive!".colorize(:green) if @board[index].is_alive?
106
+ end
107
+ display
108
+ print 'Another cell? true/false: '
109
+ check = gets.chomp
110
+ break if check == 'false'
111
+ end
112
+ self
113
+ end
114
+
115
+ def borderPos(size)
116
+ positions = []
117
+ top = []
118
+ bottom = []
119
+ left = []
120
+ rigth = []
121
+ # Top
122
+ (1...size - 1).each { |pos| top << pos }
123
+ # Bottom
124
+ (((size - 1) * size) + 1...((size * size) - 1)).each { |pos| bottom << pos }
125
+ # Left
126
+ index = 0
127
+ i = 1
128
+ loop do
129
+ index += size
130
+ left << index
131
+ i += 1
132
+ break if i > size - 2
133
+ end
134
+ # Rigth
135
+ index = size - 1
136
+ i = 1
137
+ loop do
138
+ index += size
139
+ rigth << index
140
+ i += 1
141
+ break if i > size - 2
142
+ end
143
+ positions << top
144
+ positions << rigth
145
+ positions << bottom
146
+ positions << left
147
+ positions
148
+ end
149
+
150
+ def squarePos(size)
151
+ squares = []
152
+ squares << 0
153
+ squares << size - 1
154
+ squares << (size * size) - 1
155
+ squares << (size * (size - 1))
156
+ squares
157
+ end
158
+ end
data/lib/cell.rb ADDED
@@ -0,0 +1,22 @@
1
+ class Cell
2
+ attr_accessor :state, :index, :kind
3
+
4
+ def initialize(index=0)
5
+ @state = '[▓]'
6
+ @index = index
7
+ @kind = ''
8
+ end
9
+
10
+ def die
11
+ @state = '[▓]'
12
+ end
13
+
14
+ def live
15
+ @state = '[▒]'
16
+ end
17
+
18
+ def is_alive?
19
+ return true if @state == '[▒]'
20
+ return false if @state != '[▒]'
21
+ end
22
+ end
data/lib/game.rb ADDED
@@ -0,0 +1,54 @@
1
+ require_relative 'board'
2
+ require_relative 'new_Rules'
3
+ require 'colorize'
4
+ class Game
5
+
6
+ def start
7
+ $table = Board.new
8
+ check = false
9
+ puts '1) Random alive Cells'.colorize(:blue)
10
+ puts '2) Choose alive Cells'.colorize(:blue)
11
+ puts '3) Exit'.colorize(:blue)
12
+ puts "\n"
13
+ print 'Option:'
14
+ answer = gets.chomp.to_i
15
+ case answer
16
+ when 1
17
+ $table = $table.randomCells
18
+ gameFlow
19
+ when 2
20
+ $table = $table.manualCells
21
+ gameFlow
22
+ when 3
23
+ return true
24
+ else
25
+ print "That option it's not include | ENTER to continue ".colorize(:red)
26
+ gets.chomp
27
+ system('clear')
28
+ end
29
+ true
30
+ end
31
+
32
+ def gameFlow
33
+ $rules = NewRules.new
34
+ i = 0
35
+ check = true
36
+ loop do
37
+ system('clear')
38
+ $table.display($table.board)
39
+ lastBoard = $table.board
40
+ newBoard = $rules.checkFriends($table.board, $table.borders, $table.squares)
41
+ $table.board = newBoard if newBoard != $table.board
42
+ i += 1
43
+ if i % 25 == 0
44
+ print 'Do you want to keep going? true/false '
45
+ check = gets.chomp
46
+ puts "\n"
47
+ end
48
+ break if check == 'false'
49
+ end
50
+ print "All the cell are gonna stay like this, the game it's done | ENTER to continue".colorize(:red)
51
+ gets.chomp
52
+ true
53
+ end
54
+ end
data/lib/gol_chido.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "gol_chido/version"
2
+ require_relative 'game'
3
+
4
+ module GolChido
5
+ class GameOfLife
6
+
7
+ def start
8
+ system('clear')
9
+ loop do
10
+ puts '========== M E N U =========='
11
+ puts ' Press enter to start.'.colorize(:blue)
12
+ gets.chomp
13
+ Game.new.start
14
+ puts "\n"
15
+ puts 'Wanna play again? true/false'
16
+ break if gets.chomp.casecmp('false').zero?
17
+ end
18
+ 3.times { puts "\n" }
19
+ puts '~~~~~~~~~~~~~~~~ Thanks for playing ~~~~~~~~~~~~~~~~~'.colorize(:green)
20
+ puts '~~~~~~~~~~~~~ Gem created by rubiocanino ~~~~~~~~~~~~~'.colorize(:green)
21
+ puts ''
22
+ sleep(1)
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+
@@ -0,0 +1,3 @@
1
+ module GolChido
2
+ VERSION = "0.1.1"
3
+ end
data/lib/new_Rules.rb ADDED
@@ -0,0 +1,176 @@
1
+ class NewRules
2
+ # Die when u have 1 neighb
3
+ # Die when u have 4,5,6.7 neighb
4
+ # Live when u have 2,3 neighb
5
+ require 'colorize'
6
+
7
+ def initialize; end
8
+
9
+ def checkFriends(checkBoard, borders, squares)
10
+ $checkBoard = checkBoard
11
+ newBoard = []
12
+ size = $checkBoard.size.to_i
13
+ $size = Math.sqrt(size)
14
+ $checkBoard.each_with_index do |cell, index|
15
+ copyBoard = Marshal.load(Marshal.dump(checkBoard))
16
+ case cell.kind
17
+ when 'normal'
18
+ newCell = checkNormalFriends(copyBoard, index)
19
+ when 'border'
20
+ newCell = checkBorderFriends(copyBoard, index, borders)
21
+ when 'square'
22
+ newCell = checkSquareFriends(copyBoard, index, squares)
23
+ end
24
+ newBoard << newCell
25
+ end
26
+ newBoard
27
+ end
28
+
29
+ def checkNormalFriends(_board, index)
30
+ copy = Marshal.load(Marshal.dump($checkBoard))
31
+ matches = 0
32
+ pos1 = index - $size - 1
33
+ pos2 = pos1 + 1
34
+ pos3 = pos2 + 1
35
+ pos4 = index - 1
36
+ pos5 = index + 1
37
+ pos6 = index + $size - 1
38
+ pos7 = pos6 + 1
39
+ pos8 = pos7 + 1
40
+ matches += 1 if $checkBoard[pos1].is_alive?
41
+ matches += 1 if $checkBoard[pos2].is_alive?
42
+ matches += 1 if $checkBoard[pos3].is_alive?
43
+ matches += 1 if $checkBoard[pos4].is_alive?
44
+ matches += 1 if $checkBoard[pos5].is_alive?
45
+ matches += 1 if $checkBoard[pos6].is_alive?
46
+ matches += 1 if $checkBoard[pos7].is_alive?
47
+ matches += 1 if $checkBoard[pos8].is_alive?
48
+ case matches
49
+ when 0, 1
50
+ copy[index].die
51
+ when 2
52
+ copy[index].live if copy[index].is_alive?
53
+ when 3
54
+ copy[index].live unless copy[index].is_alive?
55
+ when 4, 5, 6
56
+ copy[index].die
57
+ end
58
+ copy[index]
59
+ end
60
+
61
+ def checkBorderFriends(_board, index, borders)
62
+ copy = Marshal.load(Marshal.dump($checkBoard))
63
+ matches = 0
64
+ # Top side
65
+ if borders[0].include?(index)
66
+ matches = 0
67
+ pos1 = index - 1
68
+ pos2 = index + 1
69
+ pos3 = pos1 + $size.to_i
70
+ pos4 = pos2 + $size.to_i
71
+ pos5 = index + $size.to_i
72
+ matches += 1 if $checkBoard[pos1].is_alive?
73
+ matches += 1 if $checkBoard[pos2].is_alive?
74
+ matches += 1 if $checkBoard[pos3].is_alive?
75
+ matches += 1 if $checkBoard[pos4].is_alive?
76
+ matches += 1 if $checkBoard[pos5].is_alive?
77
+ elsif borders[1].include?(index)
78
+ # Rigth side
79
+ matches = 0
80
+ pos1 = $size - 1
81
+ pos2 = pos1 - 1
82
+ pos3 = pos2 + $size
83
+ pos4 = pos3 + $size
84
+ pos5 = pos4 + 1
85
+ matches += 1 if $checkBoard[pos1].is_alive?
86
+ matches += 1 if $checkBoard[pos2].is_alive?
87
+ matches += 1 if $checkBoard[pos3].is_alive?
88
+ matches += 1 if $checkBoard[pos4].is_alive?
89
+ matches += 1 if $checkBoard[pos5].is_alive?
90
+ elsif borders[2].include?(index)
91
+ # Bottom side
92
+ matches = 0
93
+ pos1 = index + 1
94
+ pos2 = pos1 - $size.to_i
95
+ pos3 = pos2 - 1.to_i
96
+ pos4 = pos3 - 1.to_i
97
+ pos5 = pos4 + $size.to_i
98
+ matches += 1 if $checkBoard[pos1].is_alive?
99
+ matches += 1 if $checkBoard[pos2].is_alive?
100
+ matches += 1 if $checkBoard[pos3].is_alive?
101
+ matches += 1 if $checkBoard[pos4].is_alive?
102
+ matches += 1 if $checkBoard[pos5].is_alive?
103
+ else
104
+ # Left side
105
+ matches = 0
106
+ pos1 = index - $size
107
+ pos2 = pos1 + 1
108
+ pos3 = pos2 + $size
109
+ pos4 = pos3 + $size
110
+ pos5 = pos4 - 1
111
+ matches += 1 if $checkBoard[pos1].is_alive?
112
+ matches += 1 if $checkBoard[pos2].is_alive?
113
+ matches += 1 if $checkBoard[pos3].is_alive?
114
+ matches += 1 if $checkBoard[pos4].is_alive?
115
+ matches += 1 if $checkBoard[pos5].is_alive?
116
+ end
117
+ case matches
118
+ when 0, 1
119
+ copy[index].die
120
+ when 2
121
+ copy[index].live if copy[index].is_alive?
122
+ when 3
123
+ copy[index].live unless copy[index].is_alive?
124
+ when 4, 5, 6
125
+ copy[index].die
126
+ end
127
+ copy[index]
128
+ end
129
+
130
+ def checkSquareFriends(_board, index, squares)
131
+ copy = Marshal.load(Marshal.dump($table.board))
132
+ matches = 0
133
+ squares = squares.sort!
134
+ # First square
135
+ if squares[0] == index
136
+ pos1 = 1
137
+ pos2 = pos1 + $size.to_i
138
+ pos3 = $size.to_i
139
+ matches += 1 if $checkBoard[pos1].is_alive?
140
+ matches += 1 if $checkBoard[pos2].is_alive?
141
+ matches += 1 if $checkBoard[pos3].is_alive?
142
+ elsif squares[1] == index
143
+ pos1 = index - 1.to_i
144
+ pos2 = pos1 + $size.to_i
145
+ pos3 = pos2 + 1.to_i
146
+ matches += 1 if $checkBoard[pos1].is_alive?
147
+ matches += 1 if $checkBoard[pos2].is_alive?
148
+ matches += 1 if $checkBoard[pos3].is_alive?
149
+ elsif squares[2] == index
150
+ auxSize = $size * ($size - 1).to_i
151
+ pos1 = auxSize - $size
152
+ pos2 = pos1 + 1
153
+ pos3 = auxSize + 1
154
+ matches += 1 if $checkBoard[pos1].is_alive?
155
+ matches += 1 if $checkBoard[pos2].is_alive?
156
+ matches += 1 if $checkBoard[pos3].is_alive?
157
+ elsif squares[3] == index
158
+ auxSize = ($size * $size) - 1
159
+ pos1 = auxSize - 1
160
+ pos2 = pos1 - $size
161
+ pos3 = auxSize - $size
162
+ matches += 1 if $checkBoard[pos1].is_alive?
163
+ matches += 1 if $checkBoard[pos2].is_alive?
164
+ matches += 1 if $checkBoard[pos3].is_alive?
165
+ end
166
+ case matches
167
+ when 0, 1
168
+ copy[index].die
169
+ when 2
170
+ copy[index].live if copy[index].is_alive?
171
+ when 3
172
+ copy[index].live unless copy[index].is_alive?
173
+ end
174
+ copy[index]
175
+ end
176
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gol_chido
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Saul Rubio
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-17 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: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: You can waste time looking how all the cells moves in the matrix, it's
70
+ kind a fun
71
+ email:
72
+ - saulrubio98@hotmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - gol_chido.gemspec
88
+ - lib/board.rb
89
+ - lib/cell.rb
90
+ - lib/game.rb
91
+ - lib/gol_chido.rb
92
+ - lib/gol_chido/version.rb
93
+ - lib/new_Rules.rb
94
+ homepage: https://github.com/rubiocanino/game_of_life_chido
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ allowed_push_host: https://rubygems.org
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.5.2.1
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: This a gem for base of Conway's Game of Life and it's for 0 players
119
+ test_files: []