sbcconnect 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: e1669e4ac8b6f4b78c004585a0f8c920236ec98c78d5fdf4812ee38683e3afed
4
+ data.tar.gz: c85569ede98767aa9915f11f5cd2a9079285e792f73f84250337b0315e7b19a8
5
+ SHA512:
6
+ metadata.gz: 778bd2a4fcad4903b275dd05ed55ca53fa8531be3f2c395044a30a634eb8e5e39b7c962d171715b1ab61899b0387058dfc97a6cb883dca7224c6ba65fa80e846
7
+ data.tar.gz: 6f675088836b4b5a1e1ee34439a61afd4dae9126ce003b05dbea660fd7aa2f72110f0b94ac7f739f9af29d6e575e1e85d2b6a992f1fdff02618ac9b19b139357
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-10-26
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at samc1253@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in connect.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ connect (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ json (2.6.2)
12
+ parallel (1.22.1)
13
+ parser (3.1.2.1)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
16
+ rake (13.0.6)
17
+ regexp_parser (2.6.0)
18
+ rexml (3.2.5)
19
+ rspec (3.12.0)
20
+ rspec-core (~> 3.12.0)
21
+ rspec-expectations (~> 3.12.0)
22
+ rspec-mocks (~> 3.12.0)
23
+ rspec-core (3.12.0)
24
+ rspec-support (~> 3.12.0)
25
+ rspec-expectations (3.12.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.12.0)
28
+ rspec-mocks (3.12.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.12.0)
31
+ rspec-support (3.12.0)
32
+ rubocop (1.37.1)
33
+ json (~> 2.3)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.1.2.1)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml (>= 3.2.5, < 4.0)
39
+ rubocop-ast (>= 1.23.0, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 3.0)
42
+ rubocop-ast (1.23.0)
43
+ parser (>= 3.1.1.0)
44
+ ruby-progressbar (1.11.0)
45
+ unicode-display_width (2.3.0)
46
+
47
+ PLATFORMS
48
+ x86_64-darwin-21
49
+
50
+ DEPENDENCIES
51
+ connect!
52
+ rake (~> 13.0)
53
+ rspec (~> 3.2)
54
+ rubocop (~> 1.21)
55
+
56
+ BUNDLED WITH
57
+ 2.3.24
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Connect
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/connect`. 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
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add connect
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install connect
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/connect. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/connect/blob/main/CODE_OF_CONDUCT.md).
30
+
31
+ ## Code of Conduct
32
+
33
+ Everyone interacting in the Connect project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/connect/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/connect.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/connect/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sbcconnect"
7
+ spec.version = Connect::VERSION
8
+ spec.authors = ["Samuel Cox"]
9
+ spec.email = ["samc1253@gmail.com"]
10
+
11
+ spec.summary = "The classic game Connect Four"
12
+ spec.homepage = "https://github.com/sambcox/connect_gem"
13
+ spec.required_ruby_version = ">= 2.6.0"
14
+
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(__dir__) do
19
+ `git ls-files -z`.split("\x0").reject do |f|
20
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
21
+ end
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "rspec", "~> 3.2"
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ # spec.add_dependency "example-gem", "~> 1.0"
31
+
32
+ # For more information and examples about making a new gem, check out our
33
+ # guide at: https://bundler.io/guides/creating_gem.html
34
+ end
data/exe/connect ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require './lib/connect.rb'
3
+ Connect::Run.start
data/lib/board.rb ADDED
@@ -0,0 +1,107 @@
1
+ require './lib/cell'
2
+ require './lib/game'
3
+ require './lib/turn'
4
+ require './lib/player'
5
+
6
+ class Board
7
+ attr_reader :columns
8
+ def initialize
9
+ @columns = {
10
+ "A" => [],
11
+ "B" => [],
12
+ "C" => [],
13
+ "D" => [],
14
+ "E" => [],
15
+ "F" => [],
16
+ "G" => []
17
+ }
18
+
19
+ @columns.each { |column, row| 6.times{ row << Cell.new}}
20
+ end
21
+
22
+ def print_board
23
+ puts columns.keys.join(" ")
24
+
25
+ columns.values.transpose.reverse.map do |row|
26
+ joined_row = row.map do |cell|
27
+ cell.piece
28
+ end
29
+ puts joined_row.join(" ")
30
+ end
31
+ end
32
+
33
+ def horizontal_win?
34
+ consecutive_rows = []
35
+
36
+ columns.values.transpose.reverse.map { |value| value.map { |cell| cell.piece}.each_cons(4) { |consecutive| consecutive_rows << consecutive}}
37
+
38
+ return "X" if consecutive_rows.any?(["X", "X", "X", "X"])
39
+ return "O" if consecutive_rows.any?(["O", "O", "O", "O"])
40
+ end
41
+
42
+ def vertical_win?
43
+ consecutive_rows = []
44
+
45
+ columns.values.map { |column| column.map { |cell| cell.piece}.each_cons(4) { |consecutive| consecutive_rows << consecutive}}
46
+
47
+ return "X" if consecutive_rows.any?(["X", "X", "X", "X"])
48
+ return "O" if consecutive_rows.any?(["O", "O", "O", "O"])
49
+ end
50
+
51
+ def diagonal_win?
52
+ consecutive_rows = []
53
+ diag = {}
54
+
55
+ diag[1] = columns.values.flatten.select.with_index{|cell, i| i % 7 == 0}
56
+ diag[2] = columns.values.flatten.select.with_index{|_,i| (i + 8) % 7 == 0}
57
+ diag[3] = columns.values.flatten.select.with_index{|_,i| i % 7 == 5}
58
+ diag[3].shift
59
+ diag[4] = columns.values.flatten.select.with_index{|_,i| i % 7 == 4}
60
+ diag[4].shift(2)
61
+ diag[5] = columns.values.flatten.select.with_index{|_,i| i % 7 == 1}
62
+ diag[5].pop
63
+ diag[6] = columns.values.flatten.select.with_index{|_,i| i % 7 == 2}
64
+ diag[6].pop(2)
65
+ diag[7] = columns.values.flatten.select.with_index{|_,i| i % 5 == 4}
66
+ diag[7].pop(3)
67
+ diag[8] = columns.values.flatten.select.with_index{|_,i| i % 5 == 3}
68
+ diag[8].pop(4)
69
+ diag[9] = columns.values.flatten.select.with_index{|_,i| i % 5 == 3}
70
+ diag[9].shift(4)
71
+ diag[10] = columns.values.flatten.select.with_index{|_,i| i % 5 == 2}
72
+ diag[10].shift(3)
73
+ diag[11] = columns.values.flatten.select.with_index{|_,i| i % 5 == 1}
74
+ diag[11].pop
75
+ diag[11].shift(2)
76
+ diag[12] = columns.values.flatten.select.with_index{|_,i| i % 5 == 0}
77
+ diag[12].shift
78
+ diag[12].pop(2)
79
+
80
+ diag.values.map { |value| value.map { |cell| cell.piece}.each_cons(4) { |consecutive| consecutive_rows << consecutive}}
81
+
82
+ return "X" if consecutive_rows.any?(["X", "X", "X", "X"])
83
+ return "O" if consecutive_rows.any?(["O", "O", "O", "O"])
84
+ end
85
+
86
+ def win_game?
87
+ if horizontal_win? == "X"
88
+ return "X"
89
+ elsif horizontal_win? == "O"
90
+ return "O"
91
+ elsif vertical_win? == "X"
92
+ return "X"
93
+ elsif vertical_win? == "O"
94
+ return "O"
95
+ elsif diagonal_win? == "X"
96
+ return "X"
97
+ elsif diagonal_win? == "O"
98
+ return "O"
99
+ else
100
+ return false
101
+ end
102
+ end
103
+
104
+ def endgame?
105
+ columns.map { |header, column| column.last.empty?}.find_all { |cell| cell == false}.length == 7
106
+ end
107
+ end
data/lib/cell.rb ADDED
@@ -0,0 +1,18 @@
1
+ class Cell
2
+ attr_reader :piece
3
+ def initialize
4
+ @piece = "."
5
+ end
6
+
7
+ def add_piece
8
+ @piece = "X"
9
+ end
10
+
11
+ def computer_add_piece
12
+ @piece = "O"
13
+ end
14
+
15
+ def empty?
16
+ @piece == "."
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Connect
4
+ VERSION = "0.1.0"
5
+ end
data/lib/connect.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "connect/version"
4
+ require "game"
5
+
6
+ module Connect
7
+ class Error < StandardError; end
8
+ class Run
9
+ @game = Game.new
10
+ @game.main_menu
11
+
12
+ end
13
+ end
data/lib/game.rb ADDED
@@ -0,0 +1,148 @@
1
+ require './lib/cell'
2
+ require './lib/player'
3
+ require './lib/board'
4
+ require './lib/turn'
5
+
6
+ class Game
7
+ attr_reader :board, :player1, :player2, :turn
8
+ def initialize
9
+ @player1 = nil
10
+ @player2 = nil
11
+ @board = nil
12
+ @turn = nil
13
+ end
14
+
15
+ def main_menu
16
+ puts "Welcome to Connect Four!"
17
+ puts "To play against PC, press c. To play with a friend, press p. To quit, press q."
18
+
19
+ want_to_play = gets.chomp.downcase
20
+ if want_to_play == "c"
21
+ start
22
+ elsif want_to_play == "p"
23
+ two_player_start
24
+ elsif want_to_play == "q"
25
+ quit_game
26
+ else puts "Invalid input, please press p or q"
27
+ main_menu
28
+ end
29
+ end
30
+
31
+ def two_player_start
32
+ puts "Please enter player 1 name"
33
+ @player1 = Player.new(gets.chomp)
34
+ puts "Please enter player 2 name"
35
+ @player2 = Player.new(gets.chomp)
36
+ @board = Board.new
37
+ @turn = Turn.new(board)
38
+ board.print_board
39
+ player1_take_turn
40
+ end
41
+
42
+ def test_start
43
+ @board = Board.new
44
+ @turn = Turn.new(board)
45
+ @player1 = Player.new("Mike")
46
+ @player2 = Player.new("Sam")
47
+ end
48
+
49
+ def start
50
+ @board = Board.new
51
+ @turn = Turn.new(@board)
52
+ board.print_board
53
+ game_user_take_turn
54
+ end
55
+
56
+ def game_user_take_turn
57
+ overall_win_game if board.win_game? != false
58
+ draw_game if board.endgame?
59
+ puts "--------------------------------"
60
+ puts "Please enter a letter between A and G"
61
+ puts "--------------------------------"
62
+ turn.user_take_turn
63
+ board.print_board
64
+ game_pc_take_turn
65
+ end
66
+
67
+ def game_pc_take_turn
68
+ overall_win_game if board.win_game? != false
69
+ draw_game if board.endgame?
70
+ puts "--------------------------------"
71
+ turn.computer_take_turn
72
+ board.print_board
73
+ game_user_take_turn
74
+ end
75
+
76
+ def player1_take_turn
77
+ player_win_game if board.win_game? != false
78
+ draw_game if board.endgame?
79
+ puts "--------------------------------"
80
+ puts "#{player1.name}, please enter a letter between A and G"
81
+ puts "--------------------------------"
82
+ turn.user_take_turn
83
+ board.print_board
84
+ player2_take_turn
85
+ end
86
+
87
+ def player2_take_turn
88
+ player_win_game if board.win_game? != false
89
+ draw_game if board.endgame?
90
+ puts "--------------------------------"
91
+ puts "#{player2.name}, please enter a letter between A and G"
92
+ puts "--------------------------------"
93
+ turn.two_player_take_turn
94
+ board.print_board
95
+ player1_take_turn
96
+ end
97
+
98
+ def play_again
99
+ puts "To play against PC, press c. To play with a friend, press p. To quit, press q."
100
+
101
+ want_to_play = gets.chomp.downcase
102
+ if want_to_play == "c"
103
+ start
104
+ elsif want_to_play == "p"
105
+ two_player_start
106
+ elsif want_to_play == "q"
107
+ quit_game
108
+ else puts "Invalid input, please press p or q"
109
+ play_again
110
+ end
111
+ end
112
+
113
+ def draw_game
114
+ puts "Thank you for playing! This game is a draw."
115
+ play_again
116
+ end
117
+
118
+ def overall_win_game
119
+ puts "--------------------------------"
120
+ if board.win_game? == "X"
121
+ puts "You've won!"
122
+ else
123
+ puts "You've lost!"
124
+ end
125
+ play_again
126
+ end
127
+
128
+ def player_win_game
129
+ winner = nil
130
+ loser = nil
131
+ if board.win_game? == "X"
132
+ winner = player1
133
+ loser = player2
134
+ else
135
+ winner = player2
136
+ loser = player1
137
+ end
138
+ puts "--------------------------------"
139
+ puts "Congratulations #{winner.name}, you've won! Better luck next time, #{loser.name}."
140
+ play_again
141
+ end
142
+
143
+ def quit_game
144
+ puts "--------------------------------"
145
+ puts "Goodbye!"
146
+ abort
147
+ end
148
+ end
data/lib/player.rb ADDED
@@ -0,0 +1,11 @@
1
+ require './lib/cell'
2
+ require './lib/game'
3
+ require './lib/board'
4
+ require './lib/turn'
5
+
6
+ class Player
7
+ attr_reader :name
8
+ def initialize(name = "Guest")
9
+ @name = name.capitalize
10
+ end
11
+ end
data/lib/turn.rb ADDED
@@ -0,0 +1,80 @@
1
+ require './lib/cell'
2
+ require './lib/board'
3
+ require './lib/game'
4
+ require './lib/player'
5
+
6
+ class Turn
7
+ attr_reader :board
8
+ def initialize(board)
9
+ @board = board
10
+ end
11
+
12
+ def user_take_turn
13
+ user_input = gets.chomp
14
+ if "ABCDEFG".include? user_input.upcase
15
+ place_piece(user_input)
16
+ else
17
+ puts "That is an invalid input! Please select a letter between A and G."
18
+ user_take_turn
19
+ end
20
+ end
21
+
22
+ def two_player_take_turn
23
+ user_input = gets.chomp
24
+ if "ABCDEFG".include? user_input.upcase
25
+ user_place_piece(user_input)
26
+ else
27
+ puts "That is an invalid input! Please select a letter between A and G."
28
+ two_player_take_turn
29
+ end
30
+ end
31
+
32
+ def computer_take_turn
33
+ computer_input = board.columns.keys.shuffle.shuffle.first
34
+ pc_place_piece(computer_input)
35
+ end
36
+
37
+ def user_place_piece(column_inputted)
38
+ if board.columns[column_inputted.upcase][5].empty? == false
39
+ puts "That column is full! Please select another"
40
+ user2_take_turn
41
+ else
42
+ board.columns.find do |column, row|
43
+ if column_inputted.downcase == column.downcase
44
+ row.find do |cell|
45
+ cell.computer_add_piece if cell.empty?
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ def pc_place_piece(column_inputted)
53
+ if board.columns[column_inputted.upcase][5].empty? == false
54
+ computer_take_turn
55
+ else
56
+ board.columns.find do |column, row|
57
+ if column_inputted.downcase == column.downcase
58
+ row.find do |cell|
59
+ cell.computer_add_piece if cell.empty?
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def place_piece(column_inputted)
67
+ if board.columns[column_inputted.upcase][5].empty? == false
68
+ puts "That column is full! Please select another."
69
+ place_piece(gets.chomp)
70
+ else
71
+ board.columns.find do |column, row|
72
+ if column_inputted.downcase == column.downcase
73
+ row.find do |cell|
74
+ cell.add_piece if cell.empty?
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
data/sig/connect.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Connect
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sbcconnect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Cox
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description:
28
+ email:
29
+ - samc1253@gmail.com
30
+ executables:
31
+ - connect
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rubocop.yml"
36
+ - CHANGELOG.md
37
+ - CODE_OF_CONDUCT.md
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - README.md
41
+ - Rakefile
42
+ - connect.gemspec
43
+ - exe/connect
44
+ - lib/board.rb
45
+ - lib/cell.rb
46
+ - lib/connect.rb
47
+ - lib/connect/version.rb
48
+ - lib/game.rb
49
+ - lib/player.rb
50
+ - lib/turn.rb
51
+ - sig/connect.rbs
52
+ homepage: https://github.com/sambcox/connect_gem
53
+ licenses: []
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.6.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.1.4
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: The classic game Connect Four
74
+ test_files: []