connect_four_2307 0.1.0
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 +7 -0
- data/.rspec +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/Rakefile +8 -0
- data/connect_four.rb +5 -0
- data/connect_four_2307.gemspec +40 -0
- data/exe/connect_four_2307 +3 -0
- data/lib/.keep +0 -0
- data/lib/connect_four_2307/board.rb +38 -0
- data/lib/connect_four_2307/cell.rb +11 -0
- data/lib/connect_four_2307/computer.rb +9 -0
- data/lib/connect_four_2307/game_controller.rb +112 -0
- data/lib/connect_four_2307/player.rb +15 -0
- data/lib/connect_four_2307/turn.rb +134 -0
- data/lib/connect_four_2307/version.rb +5 -0
- data/lib/connect_four_2307.rb +13 -0
- data/sig/connect_four_2307.rbs +4 -0
- metadata +66 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0ced57e94e7fa7afe035b7ff6f77d801e1e7b4fda261f369a15246aeeec41171
|
|
4
|
+
data.tar.gz: 5f666da86f8234ca8b06c4bcac87417d94569691056a1cabdfb4a78ccb8a769e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 457d46850a3415c7d6f4b30244f66b438aa0e97c2abf9175916d7549b3b5f93af4692055885ccd0c569d464a97b6bebb2e59f887c79fa8509b2d10cbd84a8c40
|
|
7
|
+
data.tar.gz: 13058fbb87fdf708583c8b793170fe2c8404099a5709c4615cad0f30e7e5d164aa522644ba80d9294e895b1d3b2211696effaad924c7e56179ac935ef774efc2
|
data/.rspec
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Tyler Blackmon
|
|
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,78 @@
|
|
|
1
|
+
# **CONNECT FOUR - PAIR PROJECT - TURING - MOD1**
|
|
2
|
+

|
|
3
|
+
## **Overview:**
|
|
4
|
+
|
|
5
|
+
This project explores creating a version of the classic game Connect Four as a CLI game within your computer terminal. A specific requirement of this project was to develop all code given only written instruction without code prompts from an interaction pattern. As a pair, our team was able to design architecture for this application and implement that design in our codebase to create a functioning and interactive game. The project explores the concept of abstraction in OOP through creation of complex, logic based methods that are applied to a gameflow found in the game controller class.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## **User interaction outcome:**
|
|
9
|
+
The game in it's current state provides two game modes for the player: one player, and two player. In our one player mode, the player plays against a computer which places a random piece after a player's turn until winning conditions are met by either the computer or player. In two player mode, two human players can play on the same terminal placing one piece per turn until winning conditions are met by one player.
|
|
10
|
+
|
|
11
|
+
## **Tech Stack:**
|
|
12
|
+
- Ruby
|
|
13
|
+
- Gems: RSpec
|
|
14
|
+
|
|
15
|
+
## **Additional Documentation:**
|
|
16
|
+
[Google Doc Brainstom](https://docs.google.com/document/d/1P3wmFz5bldRx5s5Ox9hBn4K1FPc2cF2PQGabBorPTnc/edit#heading=h.h8krlvcjmayj)
|
|
17
|
+
[Defining Relationship](https://docs.google.com/document/d/1QYJ4KUGjahCnPv96DBg9BflEC1-6jwJpzyDmNIjcJL8/edit)
|
|
18
|
+
|
|
19
|
+
## **Skills Gained/Expanded:**
|
|
20
|
+
- Codebase architecture and design
|
|
21
|
+
- Pair programming - driver/navigator, general collaboration, and collective creativity in design
|
|
22
|
+
- TDD - utilizing testing in RSpec to ensure incremenental functionality of all methods; unit and integrations
|
|
23
|
+
- CLI testing - utilizing user interactive testing alongside TDD to verify application functionality
|
|
24
|
+
|
|
25
|
+
## **Reflection Points:**
|
|
26
|
+
1. This project did not provide an interaction pattern. How did you approach the design and problem solving process for this project?
|
|
27
|
+
|
|
28
|
+
*We began by putting our general thoughts on a Google Doc. We them split up our Google Doc by iteration of the project and revisited the documentation to brainstom at the beginning of each iteration. During the brainstorming sessions, we applied pseudo coding techniques as well as writing potential method and class names. During the last iteration we utilized Replit to play around with code for the check_diagonal_win method. We approached the design aspect from the get-go based on the data structure of the board. We began with a hash of hashes, and quickly reverted to an array of arrays once we began the second iteration. During each step of brainstorming, we also tried to foresee any potential roadblocks, or design flaws in order to better understand the limitations of our ideas.*
|
|
29
|
+
|
|
30
|
+
2. If you had one more day to work on this project, what would you work on?
|
|
31
|
+
|
|
32
|
+
*We would most likely try to implement the HTTP requirements in order for two players to be able to play each other across the web. We would also like to make the user interface a bit friendlier by creating better spacing in the board, making it visually easier to play the game.*
|
|
33
|
+
|
|
34
|
+
3. Describe the pairing techniques you used while working on this project.
|
|
35
|
+
|
|
36
|
+
*We utilized some driver/navigator techniques as well as divide and conquer. For some of the more complex methods (checking win conditions), we attempted to separate and come up with our solutions in order to juxtapose. For some simpler methods such as the ones found in iteration 1 and 2, we simply divided the work, and created pull requests with detailed summaries that we reviewed and commented on before merging into the main branch.**
|
|
37
|
+
|
|
38
|
+
4. Describe how feedback was shared over the course of this project.
|
|
39
|
+
|
|
40
|
+
*We gave feedback in the form of assuring mutual understanding when implementing new methods and design. When one partner did not understand the exact logic or reasoning behind method design, we took the time to explain it to one another. During driver/navigator sessions, we gave direct but polite feedback when making a correction change to the code. We showed appreciation for each others contributions along the way, and acknowledged when one partner provided a solution that was better than another.*
|
|
41
|
+
|
|
42
|
+
# GEM INSTALLATION
|
|
43
|
+
|
|
44
|
+
# ConnectFour2307
|
|
45
|
+
|
|
46
|
+
TODO: Delete this and the text below, and describe your gem
|
|
47
|
+
|
|
48
|
+
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_four_2307`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
|
53
|
+
|
|
54
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
55
|
+
|
|
56
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
|
57
|
+
|
|
58
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
59
|
+
|
|
60
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
TODO: Write usage instructions here
|
|
65
|
+
|
|
66
|
+
## Development
|
|
67
|
+
|
|
68
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
69
|
+
|
|
70
|
+
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).
|
|
71
|
+
|
|
72
|
+
## Contributing
|
|
73
|
+
|
|
74
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/connect_four_2307.
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/connect_four.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/connect_four_2307/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "connect_four_2307"
|
|
7
|
+
spec.version = ConnectFour2307::VERSION
|
|
8
|
+
spec.authors = ["Tyler Blackmon", "Antoine Aube"]
|
|
9
|
+
spec.email = ["tyler.blackmon8@gmail.com", "aaube3@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "A simple gem to play Connect 4 from a CLI."
|
|
12
|
+
spec.homepage = "https://github.com/Antoine-Aube/connect_four"
|
|
13
|
+
spec.license = "MIT"
|
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
|
15
|
+
|
|
16
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
|
17
|
+
|
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/Antoine-Aube/connect_four"
|
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/Antoine-Aube/connect_four"
|
|
21
|
+
|
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
26
|
+
(File.expand_path(f) == __FILE__) ||
|
|
27
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = "exe"
|
|
31
|
+
# spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.executables = ["connect_four_2307"]
|
|
33
|
+
spec.require_paths = ["lib"]
|
|
34
|
+
|
|
35
|
+
# Uncomment to register a new dependency of your gem
|
|
36
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
37
|
+
|
|
38
|
+
# For more information and examples about making a new gem, check out our
|
|
39
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
40
|
+
end
|
data/lib/.keep
ADDED
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require_relative 'cell'
|
|
2
|
+
|
|
3
|
+
class Board
|
|
4
|
+
attr_reader :board_grid
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@board_grid = generate_board
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def generate_board
|
|
11
|
+
board = [
|
|
12
|
+
[Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new],
|
|
13
|
+
[Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new],
|
|
14
|
+
[Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new],
|
|
15
|
+
[Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new],
|
|
16
|
+
[Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new],
|
|
17
|
+
[Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new, Cell.new]
|
|
18
|
+
]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def render_board
|
|
23
|
+
puts "ABCDEFG"
|
|
24
|
+
|
|
25
|
+
@board_grid.each do |row|
|
|
26
|
+
row.each do |cell|
|
|
27
|
+
print cell.state
|
|
28
|
+
end
|
|
29
|
+
puts "\n"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def board_is_full?
|
|
34
|
+
@board_grid[0].none? do |cell|
|
|
35
|
+
cell.state == "."
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require_relative 'board'
|
|
2
|
+
require_relative 'turn'
|
|
3
|
+
require_relative 'player'
|
|
4
|
+
require_relative 'computer'
|
|
5
|
+
|
|
6
|
+
class GameController
|
|
7
|
+
def start_game
|
|
8
|
+
puts "Welcome to Connect 4!!!"
|
|
9
|
+
puts "Enter P to start a game, or Q to quit."
|
|
10
|
+
user_input = gets.chomp.downcase
|
|
11
|
+
while user_input != "p" && user_input != "q"
|
|
12
|
+
"Please enter P to start a game, or Q to quit."
|
|
13
|
+
user_input = gets.chomp.downcase
|
|
14
|
+
end
|
|
15
|
+
if user_input == "q"
|
|
16
|
+
exit()
|
|
17
|
+
end
|
|
18
|
+
puts "Enter 1 for one player and 2 for two players"
|
|
19
|
+
user_input = gets.chomp.downcase
|
|
20
|
+
while user_input != "1" && user_input != "2"
|
|
21
|
+
puts "Invalid input! Please enter 1 for one player and 2 for two players"
|
|
22
|
+
user_input = gets.chomp.downcase
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if user_input == "1"
|
|
26
|
+
one_player_game
|
|
27
|
+
else
|
|
28
|
+
two_player_game
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def one_player_game
|
|
33
|
+
board = Board.new
|
|
34
|
+
player_1 = Player.new("X")
|
|
35
|
+
computer = Computer.new
|
|
36
|
+
puts "Enter Player 1 name"
|
|
37
|
+
player_one_name = gets.chomp
|
|
38
|
+
player_1.get_player_name(player_one_name)
|
|
39
|
+
puts
|
|
40
|
+
board.render_board
|
|
41
|
+
turn_counter = 1
|
|
42
|
+
while !board.board_is_full? && !player_1.winner && !computer.winner
|
|
43
|
+
if turn_counter % 2 == 0
|
|
44
|
+
turn = Turn.new(computer, board)
|
|
45
|
+
turn.get_move
|
|
46
|
+
turn.set_cell
|
|
47
|
+
turn.check_win_conditions
|
|
48
|
+
else
|
|
49
|
+
turn = Turn.new(player_1, board)
|
|
50
|
+
turn.get_move
|
|
51
|
+
turn.set_cell
|
|
52
|
+
turn.check_win_conditions
|
|
53
|
+
end
|
|
54
|
+
board.render_board
|
|
55
|
+
turn_counter += 1
|
|
56
|
+
end
|
|
57
|
+
if player_1.winner
|
|
58
|
+
puts "#{player_1.name} wins! \n"
|
|
59
|
+
start_game
|
|
60
|
+
elsif computer.winner
|
|
61
|
+
puts "Computer wins! \n"
|
|
62
|
+
start_game
|
|
63
|
+
elsif board.board_is_full?
|
|
64
|
+
puts "Draw! \n"
|
|
65
|
+
start_game
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def two_player_game
|
|
71
|
+
board = Board.new
|
|
72
|
+
player_1 = Player.new("X")
|
|
73
|
+
player_2 = Player.new("O")
|
|
74
|
+
puts "Enter Player 1 name"
|
|
75
|
+
player_one_name = gets.chomp
|
|
76
|
+
player_1.get_player_name(player_one_name)
|
|
77
|
+
puts
|
|
78
|
+
puts "Enter Player 2 name"
|
|
79
|
+
player_two_name = gets.chomp
|
|
80
|
+
player_2.get_player_name(player_two_name)
|
|
81
|
+
puts
|
|
82
|
+
board.render_board
|
|
83
|
+
turn_counter = 1
|
|
84
|
+
while !board.board_is_full? && !player_1.winner && !player_2.winner
|
|
85
|
+
if turn_counter % 2 == 0
|
|
86
|
+
turn = Turn.new(player_2, board)
|
|
87
|
+
turn.get_move
|
|
88
|
+
turn.set_cell
|
|
89
|
+
turn.check_win_conditions
|
|
90
|
+
board.render_board
|
|
91
|
+
turn_counter += 1
|
|
92
|
+
else
|
|
93
|
+
turn = Turn.new(player_1, board)
|
|
94
|
+
turn.get_move
|
|
95
|
+
turn.set_cell
|
|
96
|
+
turn.check_win_conditions
|
|
97
|
+
board.render_board
|
|
98
|
+
turn_counter += 1
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
if player_1.winner
|
|
102
|
+
puts "#{player_1.name} wins!\n"
|
|
103
|
+
start_game
|
|
104
|
+
elsif player_2.winner
|
|
105
|
+
puts "#{player_2.name} wins!\n"
|
|
106
|
+
start_game
|
|
107
|
+
elsif board.board_is_full?
|
|
108
|
+
puts "Draw!"
|
|
109
|
+
start_game
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
class Turn
|
|
2
|
+
attr_reader :player,
|
|
3
|
+
:board,
|
|
4
|
+
:columns
|
|
5
|
+
|
|
6
|
+
attr_accessor :move
|
|
7
|
+
|
|
8
|
+
def initialize(player, board)
|
|
9
|
+
@player = player
|
|
10
|
+
@board = board
|
|
11
|
+
@columns = ["a", "b", "c", "d", "e", "f", "g"]
|
|
12
|
+
@move = nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def get_move
|
|
16
|
+
if @player.instance_of?(Player)
|
|
17
|
+
puts "#{@player.name}'s turn: place a piece in column A-G \n"
|
|
18
|
+
move = validate_player_move(gets.chomp.downcase)
|
|
19
|
+
else
|
|
20
|
+
move = get_computer_move
|
|
21
|
+
end
|
|
22
|
+
@move = move
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def validate_player_move(move)
|
|
26
|
+
while !@columns.include?(move) || column_is_full?(move)
|
|
27
|
+
puts "Oops, that's an invalid move or a full column. Please select column A-G!"
|
|
28
|
+
move = gets.chomp.downcase
|
|
29
|
+
end
|
|
30
|
+
move
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def column_is_full?(move)
|
|
34
|
+
column_index = @columns.index(move)
|
|
35
|
+
@board.board_grid[0][column_index].state != "."
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get_computer_move
|
|
39
|
+
computer_move = @columns.sample
|
|
40
|
+
while validate_cpu_move(computer_move) == "invalid"
|
|
41
|
+
computer_move = @columns.sample
|
|
42
|
+
end
|
|
43
|
+
computer_move
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def validate_cpu_move(move)
|
|
47
|
+
if column_is_full?(move)
|
|
48
|
+
return "invalid"
|
|
49
|
+
else
|
|
50
|
+
move
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def set_cell
|
|
55
|
+
index_array = find_lowest_cell_in_column
|
|
56
|
+
@board.board_grid[index_array[0]][index_array[1]].set_state(@player.piece)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def find_lowest_cell_in_column
|
|
60
|
+
index_1 = nil
|
|
61
|
+
index_2 = nil
|
|
62
|
+
@board.board_grid.reverse.each do |row|
|
|
63
|
+
if row[(@columns.index(@move))].state == "."
|
|
64
|
+
index_1 = @board.board_grid.index(row)
|
|
65
|
+
index_2 = @columns.index(@move)
|
|
66
|
+
break
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
[index_1, index_2]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def check_win_conditions
|
|
73
|
+
check_horizontal_win
|
|
74
|
+
check_vertical_win
|
|
75
|
+
check_diagonal_win
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def get_board_as_states
|
|
79
|
+
@board.board_grid.map do |row|
|
|
80
|
+
row.map do |cell|
|
|
81
|
+
cell.state
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def check_horizontal_win
|
|
87
|
+
winning_string = ""
|
|
88
|
+
4.times { winning_string += "#{@player.piece}" }
|
|
89
|
+
board_as_states = get_board_as_states
|
|
90
|
+
board_as_states.each do |row|
|
|
91
|
+
@player.winner = true if row.join.include?(winning_string)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def check_vertical_win
|
|
96
|
+
winning_string = ""
|
|
97
|
+
4.times { winning_string += "#{@player.piece}" }
|
|
98
|
+
board_as_states = get_board_as_states
|
|
99
|
+
column_as_array = board_as_states.map { |row| row[@columns.index(@move)] }
|
|
100
|
+
@player.winner = true if column_as_array.join.include?(winning_string)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
#range is acting as way to create index positions to check index positions on our board
|
|
104
|
+
def diag_offset_columns(board, range)
|
|
105
|
+
range.map do |outer_int|
|
|
106
|
+
(outer_int..(board[0].size - 1)).collect {|inner_int| board[inner_int - outer_int][inner_int]}
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def diag_offset_rows(board, range)
|
|
111
|
+
range.map do |outer_int|
|
|
112
|
+
(outer_int..(board.size - 1)).collect {|inner_int| board[inner_int][inner_int - outer_int]}
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def check_diagonal_win
|
|
117
|
+
winning_string = ""
|
|
118
|
+
4.times { winning_string += "#{@player.piece}" }
|
|
119
|
+
board_states = get_board_as_states
|
|
120
|
+
board_rotated = board_states.transpose.reverse
|
|
121
|
+
diag_offset_columns(board_states, (1..3)).each do |array|
|
|
122
|
+
@player.winner = true if array.join.include?(winning_string)
|
|
123
|
+
end
|
|
124
|
+
diag_offset_rows(board_states, (0..2)).each do |array|
|
|
125
|
+
@player.winner = true if array.join.include?(winning_string)
|
|
126
|
+
end
|
|
127
|
+
diag_offset_columns(board_rotated, (0..2)).each do |array|
|
|
128
|
+
@player.winner = true if array.join.include?(winning_string)
|
|
129
|
+
end
|
|
130
|
+
diag_offset_rows(board_rotated, (1..3)).each do |array|
|
|
131
|
+
@player.winner = true if array.join.include?(winning_string)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "connect_four_2307/version"
|
|
4
|
+
require_relative "connect_four_2307/game_controller"
|
|
5
|
+
|
|
6
|
+
module ConnectFour2307
|
|
7
|
+
class Error < StandardError; end
|
|
8
|
+
# Your code goes here...
|
|
9
|
+
|
|
10
|
+
def self.start
|
|
11
|
+
GameController.new.start_game
|
|
12
|
+
end
|
|
13
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: connect_four_2307
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tyler Blackmon
|
|
8
|
+
- Antoine Aube
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: exe
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2023-07-26 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description:
|
|
15
|
+
email:
|
|
16
|
+
- tyler.blackmon8@gmail.com
|
|
17
|
+
- aaube3@gmail.com
|
|
18
|
+
executables:
|
|
19
|
+
- connect_four_2307
|
|
20
|
+
extensions: []
|
|
21
|
+
extra_rdoc_files: []
|
|
22
|
+
files:
|
|
23
|
+
- ".rspec"
|
|
24
|
+
- LICENSE.txt
|
|
25
|
+
- README.md
|
|
26
|
+
- Rakefile
|
|
27
|
+
- connect_four.rb
|
|
28
|
+
- connect_four_2307.gemspec
|
|
29
|
+
- exe/connect_four_2307
|
|
30
|
+
- lib/.keep
|
|
31
|
+
- lib/connect_four_2307.rb
|
|
32
|
+
- lib/connect_four_2307/board.rb
|
|
33
|
+
- lib/connect_four_2307/cell.rb
|
|
34
|
+
- lib/connect_four_2307/computer.rb
|
|
35
|
+
- lib/connect_four_2307/game_controller.rb
|
|
36
|
+
- lib/connect_four_2307/player.rb
|
|
37
|
+
- lib/connect_four_2307/turn.rb
|
|
38
|
+
- lib/connect_four_2307/version.rb
|
|
39
|
+
- sig/connect_four_2307.rbs
|
|
40
|
+
homepage: https://github.com/Antoine-Aube/connect_four
|
|
41
|
+
licenses:
|
|
42
|
+
- MIT
|
|
43
|
+
metadata:
|
|
44
|
+
homepage_uri: https://github.com/Antoine-Aube/connect_four
|
|
45
|
+
source_code_uri: https://github.com/Antoine-Aube/connect_four
|
|
46
|
+
changelog_uri: https://github.com/Antoine-Aube/connect_four
|
|
47
|
+
post_install_message:
|
|
48
|
+
rdoc_options: []
|
|
49
|
+
require_paths:
|
|
50
|
+
- lib
|
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: 2.6.0
|
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
requirements: []
|
|
62
|
+
rubygems_version: 3.3.26
|
|
63
|
+
signing_key:
|
|
64
|
+
specification_version: 4
|
|
65
|
+
summary: A simple gem to play Connect 4 from a CLI.
|
|
66
|
+
test_files: []
|