Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done #1436

Open
wants to merge 504 commits into
base: master
Choose a base branch
from
Open

Done #1436

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
504 commits
Select commit Hold shift + click to select a range
8f31295
Done.
das11706 Oct 23, 2019
1884982
Done.
das11706 Oct 24, 2019
e0ae569
Done.
das11706 Oct 24, 2019
10840ab
Done.
das11706 Oct 24, 2019
51428ee
Done.
das11706 Oct 24, 2019
2c11a57
Done.
das11706 Oct 24, 2019
ee5aa06
Done.
das11706 Oct 24, 2019
59a5502
Done.
das11706 Oct 24, 2019
1899e34
Done.
das11706 Oct 25, 2019
3fa76ed
Done.
das11706 Oct 25, 2019
34d4a20
Done.
das11706 Oct 25, 2019
9224623
Done.
das11706 Oct 25, 2019
80743fd
Done.
das11706 Oct 25, 2019
1a050ca
Done.
das11706 Oct 25, 2019
5e5784c
Done.
das11706 Oct 25, 2019
9ee3f63
Done.
das11706 Oct 25, 2019
4483300
Done.
das11706 Oct 26, 2019
7fccc32
Done.
das11706 Oct 26, 2019
e4b0346
Done.
das11706 Oct 26, 2019
a6ecf5d
Done.
das11706 Oct 26, 2019
bd4799c
Done.
das11706 Oct 26, 2019
87d58b4
Done.
das11706 Oct 26, 2019
8fa76a8
Done.
das11706 Oct 26, 2019
14fce0c
Done.
das11706 Oct 26, 2019
b0ecfdf
Done.
das11706 Oct 26, 2019
77d834a
Done.
das11706 Oct 26, 2019
0cf71f0
Done.
das11706 Oct 26, 2019
f8ff336
Done.
das11706 Oct 26, 2019
5173977
Done.
das11706 Oct 26, 2019
45dc795
Done.
das11706 Oct 26, 2019
88dbce0
Done.
das11706 Oct 26, 2019
20cf33c
Done.
das11706 Oct 26, 2019
f81591a
Done.
das11706 Oct 27, 2019
7848f5a
Done.
das11706 Oct 27, 2019
3e50a10
Done.
das11706 Oct 27, 2019
34663e3
Done.
das11706 Oct 27, 2019
c9c7782
Done.
das11706 Oct 27, 2019
7d819cb
Done.
das11706 Oct 27, 2019
2192f13
Done.
das11706 Oct 27, 2019
ceb69bf
Done.
das11706 Oct 27, 2019
d7fcd28
Done.
das11706 Oct 27, 2019
b0915ac
Done.
das11706 Oct 27, 2019
8840e6a
Done.
das11706 Oct 27, 2019
ffc6725
Done.
das11706 Oct 27, 2019
03161c3
Done.
das11706 Oct 27, 2019
b0da314
Done.
das11706 Oct 27, 2019
4cd6b45
Done.
das11706 Oct 27, 2019
0ce97a9
Done.
das11706 Oct 27, 2019
1ef5b74
Done.
das11706 Oct 27, 2019
86b4fbd
Done.
das11706 Oct 27, 2019
86872f5
Done.
das11706 Oct 27, 2019
98e05ad
Done.
das11706 Oct 27, 2019
f8af35f
Done.
das11706 Oct 27, 2019
1c7f41f
Done.
das11706 Oct 27, 2019
2be1c87
Done.
das11706 Oct 27, 2019
c781eda
Done.
das11706 Oct 27, 2019
b8cab54
Done.
das11706 Oct 27, 2019
d73c864
Done.
das11706 Oct 27, 2019
d074337
Done.
das11706 Oct 27, 2019
abb0728
Done.
das11706 Oct 27, 2019
13cb81b
Done.
das11706 Oct 27, 2019
f350156
Done.
das11706 Oct 27, 2019
f5c89d4
Done.
das11706 Oct 27, 2019
0670d02
Done.
das11706 Oct 27, 2019
4f2fc02
Done.
das11706 Oct 27, 2019
944ded1
Done.
das11706 Oct 27, 2019
1b1ab22
Done.
das11706 Oct 27, 2019
8464c8a
Done.
das11706 Oct 28, 2019
86057a3
Done.
das11706 Oct 28, 2019
4fd24d6
Done.
das11706 Oct 28, 2019
0610f00
Done.
das11706 Oct 28, 2019
920c8f7
Done.
das11706 Oct 28, 2019
1ce2ad7
Done.
das11706 Oct 28, 2019
edb4fbc
Done.
das11706 Oct 28, 2019
6aad8ac
Done.
das11706 Oct 28, 2019
4f6d322
Done.
das11706 Oct 28, 2019
420436d
Done.
das11706 Oct 28, 2019
960e435
Done.
das11706 Oct 28, 2019
3dd3d48
Done.
das11706 Oct 28, 2019
c8e108b
Done.
das11706 Oct 28, 2019
342c32b
Done.
das11706 Oct 28, 2019
e682641
Done.
das11706 Oct 28, 2019
ab6971f
Done.
das11706 Oct 28, 2019
23bf439
Done.
das11706 Oct 28, 2019
fd717b8
Done.
das11706 Oct 28, 2019
fc53b9f
Done.
das11706 Oct 28, 2019
6b03528
Done.
das11706 Oct 28, 2019
d5eb69f
Done.
das11706 Oct 29, 2019
3a3d425
Done.
das11706 Oct 29, 2019
25e92ac
Done.
das11706 Oct 29, 2019
272ae9d
Done.
das11706 Oct 29, 2019
cb5c4d6
Done.
das11706 Oct 29, 2019
1d0015c
Done.
das11706 Oct 29, 2019
874fde2
Done.
das11706 Oct 29, 2019
a09721c
Done.
das11706 Oct 29, 2019
fc821e1
Done.
das11706 Oct 29, 2019
47dc607
Done.
das11706 Oct 30, 2019
7ab2c3d
Done.
das11706 Oct 30, 2019
b0da0eb
Done.
das11706 Oct 30, 2019
5f670d3
Done.
das11706 Oct 30, 2019
66187d7
Done.
das11706 Oct 30, 2019
7706963
Done.
das11706 Oct 30, 2019
dcc709e
Done.
das11706 Oct 30, 2019
c203f5c
Done.
das11706 Oct 30, 2019
af7e34e
Done.
das11706 Oct 30, 2019
3ecb647
Done.
das11706 Oct 30, 2019
35cceff
Done.
das11706 Oct 30, 2019
731b80b
Done.
das11706 Oct 30, 2019
e991e7b
Done.
das11706 Oct 30, 2019
54134be
Done.
das11706 Oct 30, 2019
36cd751
Done.
das11706 Oct 30, 2019
707cc15
Done.
das11706 Oct 30, 2019
c9e5880
Done.
das11706 Oct 30, 2019
d39f774
Done.
das11706 Oct 30, 2019
3b53e28
Done.
das11706 Oct 30, 2019
3497881
Done.
das11706 Oct 30, 2019
dbf0ac5
Done.
das11706 Oct 30, 2019
e350871
Done.
das11706 Oct 31, 2019
6e71885
Done.
das11706 Oct 31, 2019
10fa770
Done.
das11706 Oct 31, 2019
afe861c
Done.
das11706 Oct 31, 2019
51eadb6
Done.
das11706 Oct 31, 2019
358afb3
Done.
das11706 Oct 31, 2019
b4d6755
Done.
das11706 Oct 31, 2019
694e9e2
Done.
das11706 Oct 31, 2019
fa55546
Done.
das11706 Oct 31, 2019
484e7e0
Done.
das11706 Oct 31, 2019
f8789a2
Done.
das11706 Nov 1, 2019
0c30c13
Done.
das11706 Nov 1, 2019
f4a4d71
Done.
das11706 Nov 1, 2019
6386cf7
Done.
das11706 Nov 1, 2019
e3574a1
Done.
das11706 Nov 2, 2019
7c38788
Done.
das11706 Nov 2, 2019
628733b
Done.
das11706 Nov 2, 2019
e550e7b
Done.
das11706 Nov 2, 2019
1a110f2
Done.
das11706 Nov 4, 2019
4e6216c
Done.
das11706 Nov 5, 2019
a225709
Done.
das11706 Nov 6, 2019
e7de1b7
Done.
das11706 Nov 6, 2019
7b64db8
Done.
das11706 Nov 6, 2019
135acd4
Done.
das11706 Nov 6, 2019
2510fbe
Done.
das11706 Nov 6, 2019
b388601
Done.
das11706 Nov 9, 2019
9c0522e
Done.
das11706 Nov 9, 2019
112ff05
Done.
das11706 Nov 11, 2019
7435694
Done.
das11706 Nov 11, 2019
22d2afe
Done.
das11706 Nov 11, 2019
aec7a49
Done.
das11706 Nov 11, 2019
7230447
Done.
das11706 Nov 11, 2019
985268e
Done.
das11706 Nov 11, 2019
b7bbd73
Done.
das11706 Nov 11, 2019
d4bd8c9
Done.
das11706 Nov 11, 2019
564d3e8
Done.
das11706 Nov 11, 2019
b20e979
Done.
das11706 Nov 11, 2019
94dcafb
Done.
das11706 Nov 11, 2019
d7d5759
Done.
das11706 Nov 11, 2019
1ba438b
Done.
das11706 Nov 11, 2019
8113c30
Done.
das11706 Nov 11, 2019
3fb004a
Done.
das11706 Nov 11, 2019
39cd0f2
Done.
das11706 Nov 11, 2019
f53c80f
Done.
das11706 Nov 11, 2019
216bdb9
Done.
das11706 Nov 11, 2019
a2e0c76
Done.
das11706 Nov 11, 2019
771b799
Done.
das11706 Nov 11, 2019
d5f46b9
Done.
das11706 Nov 11, 2019
859bddb
Done.
das11706 Nov 11, 2019
94d69b2
Done.
das11706 Nov 11, 2019
909aaf6
Done.
das11706 Nov 11, 2019
83c40e4
Done.
das11706 Nov 11, 2019
306b255
Done.
das11706 Nov 11, 2019
86a3cba
Done.
das11706 Nov 11, 2019
fca4fdf
Done.
das11706 Nov 12, 2019
ad4e401
Done.
das11706 Nov 12, 2019
14e7ba2
Done.
das11706 Nov 12, 2019
8b2bdae
Done.
das11706 Nov 12, 2019
ae07f84
Done.
das11706 Nov 12, 2019
0bbe1e3
Done.
das11706 Nov 12, 2019
bb23bb6
Done.
das11706 Nov 12, 2019
4179efe
Done.
das11706 Nov 13, 2019
a05f878
Done.
das11706 Nov 13, 2019
77932c2
Done.
das11706 Nov 13, 2019
0033002
Done.
das11706 Nov 13, 2019
f0a60fd
Done.
das11706 Nov 13, 2019
75ddacb
Done.
das11706 Nov 13, 2019
9be1b83
Done.
das11706 Nov 13, 2019
2bc4e33
Done.
das11706 Nov 13, 2019
2c4b373
Done.
das11706 Nov 13, 2019
233a3cf
Done.
das11706 Nov 13, 2019
2495ea0
Done.
das11706 Nov 14, 2019
6453f2f
Done.
das11706 Nov 14, 2019
ff252a7
Done.
das11706 Nov 14, 2019
9ef15ce
Done.
das11706 Nov 14, 2019
1a63b7e
Done.
das11706 Nov 14, 2019
52c49c0
Done.
das11706 Nov 14, 2019
9358a23
Done.
das11706 Nov 14, 2019
0279095
Done.
das11706 Nov 14, 2019
d6a646f
Done.
das11706 Nov 14, 2019
48b4bf0
Done.
das11706 Nov 14, 2019
1681d81
Done.
das11706 Nov 14, 2019
9f9fb57
Done.
das11706 Nov 15, 2019
cdbdc78
Done.
das11706 Nov 15, 2019
0657194
Done.
das11706 Nov 15, 2019
dfea78f
Done.
das11706 Nov 15, 2019
86de3a5
Done.
das11706 Nov 15, 2019
8cfeead
Done.
das11706 Nov 15, 2019
0179b0c
Done.
das11706 Nov 15, 2019
93c92e9
Done.
das11706 Nov 18, 2019
f6d1f26
Done.
das11706 Nov 18, 2019
0e5e4ee
Done.
das11706 Nov 18, 2019
8743d91
Done.
das11706 Nov 18, 2019
d8765ce
Done.
das11706 Nov 18, 2019
470f132
Done.
das11706 Nov 19, 2019
9c67a95
Done.
das11706 Nov 24, 2019
2897269
Done.
das11706 Nov 24, 2019
0f7c4cd
Done.
das11706 Nov 24, 2019
548f385
Done.
das11706 Nov 24, 2019
37cefff
Done.
das11706 Nov 24, 2019
647e91a
Done.
das11706 Nov 24, 2019
8fc1d2d
Done.
das11706 Nov 24, 2019
b359bdc
Done.
das11706 Nov 24, 2019
3609351
Done.
das11706 Nov 24, 2019
96a9ffa
Done.
das11706 Nov 24, 2019
894dea6
Done.
das11706 Nov 24, 2019
f0ebe88
Done.
das11706 Nov 24, 2019
4b77535
Done.
das11706 Nov 24, 2019
10d687a
Done.
das11706 Nov 24, 2019
1b63bbb
Done.
das11706 Nov 25, 2019
dd99f6a
Done.
das11706 Nov 25, 2019
c0653b6
Done.
das11706 Nov 25, 2019
9ccc73f
Done.
das11706 Nov 25, 2019
9ed33b9
Done.
das11706 Nov 25, 2019
b1ebb62
Done.
das11706 Nov 25, 2019
ade822b
Done.
das11706 Nov 25, 2019
fadd8ea
Done.
das11706 Nov 25, 2019
b5020db
Done.
das11706 Nov 25, 2019
3b0348d
Done.
das11706 Nov 25, 2019
a723595
Done.
das11706 Nov 25, 2019
e6bbf46
Done.
das11706 Nov 25, 2019
39f7abe
Done.
das11706 Nov 26, 2019
87c8893
Done.
das11706 Nov 26, 2019
4646ea3
Done.
das11706 Nov 26, 2019
f36820a
Done.
das11706 Nov 26, 2019
8bb8e75
Done.
das11706 Nov 26, 2019
5f0921e
Done.
das11706 Nov 26, 2019
640ce6d
Done.
das11706 Nov 30, 2019
e4552e6
Done.
das11706 Nov 30, 2019
864421d
Done.
das11706 Nov 30, 2019
5f9f4d1
Done.
das11706 Nov 30, 2019
3d6b396
Done.
das11706 Nov 30, 2019
c346177
Done.
das11706 Dec 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions bin/tictactoe
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
#!/usr/bin/env ruby

require_relative '../config/environment'

puts "Welcome to Tic-Tac-Toe!"
puts "Enter '0', '1', or '2' player for the type of game you would like to play."
puts "To quit, type 'exit'."

input = gets.chomp
# until gets.strip == "exit"
until input == 'exit'

if input == '0'
puts "Enter '1' or '2' to choose which player will go first as X."
input = gets.chomp
if input == '1'
game = Game.new(player_1 = Players::Computer.new("X"), player_2 = Players::Computer.new("O"), board = Board.new())
game.play()
puts "To play again enter '0', '1', or '2' player for the type of game you would like to play."
puts "To quit, type 'exit'."
input = gets.chomp
elsif input == '2'
game = Game.new(player_1 = Players::Computer.new("O"), player_2 = Players::Computer.new("X"), board = Board.new())
game.play()
puts "To play again enter '0', '1', or '2' player for the type of game you would like to play."
puts "To quit, type 'exit'."
input = gets.chomp
end

elsif input == '1'
puts "Enter '1' or '2' to choose which player will go first as X."
input = gets.chomp
if input == '1'
game = Game.new(player_1 = Players::Human.new("X"), player_2 = Players::Computer.new("O"), board = Board.new())
game.play()
puts "To play again enter '0', '1', or '2' player for the type of game you would like to play."
puts "To quit, type 'exit'."
input = gets.chomp
elsif input == '2'
game = Game.new(player_2 = Players::Computer.new("X"), player_1 = Players::Human.new("O"), board = Board.new())
game.play()
puts "To play again enter '0', '1', or '2' player for the type of game you would like to play."
puts "To quit, type 'exit'."
input = gets.chomp
end

elsif input == '2'
puts "Enter '1' or '2' to choose which player will go first as X."
input = gets.chomp
if input == '1'
game = Game.new(player_1 = Players::Human.new("X"), player_2 = Players::Human.new("O"), board = Board.new())
game.play()
puts "To play again enter '0', '1', or '2' player for the type of game you would like to play."
puts "To quit, type 'exit'."
input = gets.chomp
elsif input == '2'
game = Game.new(player_1 = Players::Human.new("O"), player_2 = Players::Human.new("X"), board = Board.new())
game.play()
puts "To play again enter '0', '1', or '2' player for the type of game you would like to play."
puts "To quit, type 'exit'."
input = gets.chomp
end
end

end
81 changes: 81 additions & 0 deletions lib/board.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
require 'pry'
class Board
attr_accessor :cells, :player

def initialize
reset!
end

def reset!
@cells = Array.new(9, " ")
end

def display
puts " #{@cells[0]} | #{@cells[1]} | #{@cells[2]} "
puts "-----------"
puts " #{@cells[3]} | #{@cells[4]} | #{@cells[5]} "
puts "-----------"
puts " #{@cells[6]} | #{@cells[7]} | #{@cells[8]} "
end

def position(input)
cells[input.to_i - 1]
# binding.pry
end

def full?
cells.all? { |cell| cell != " " }
end

# def full?
# cells.all? do |cell|
# if cell == "X" || cell == "O"
# true
# else
# false
# end
# end
# end

# def turn_count
# count = 0
# @cells.each do |cell|
# if cell == "X" || cell == "O"
# count += 1
# end
# end
# count
# end

def turn_count
cells.count { |char| char == "X" || char == "O" }
end

def taken?(input)
position(input) != " "
end

# def taken?(input)
# position(input) == "X" || position(input) == "O"
# # binding.pry
# end

def valid_move?(input)
input.to_i.between?(1, 9) && !taken?(input)
# binding.pry
# input.to_i.between?(1, 9) && position(input) == " "
end

def update(input, player)
cells[input.to_i - 1] = player.token
# binding.pry
end


# Similarly, you're going to build an #update method that represents updating the board when a player makes a move.
# This method will take two arguments, the first will be the position the user wants
# to occupy in the form of 1-9 strings that you will need to convert to the board cells' array index,
# along with the player object making the move. When you update the appropriate index in the cells,
# you will set it equal to the token of the player object by calling the #token method on the player.

end
137 changes: 137 additions & 0 deletions lib/game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
require 'pry'
# require_relative "../lib/players/human.rb"
class Game
attr_accessor :player_1, :player_2, :board

WIN_COMBINATIONS = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6],
]

def initialize(player_1 = Players::Human.new("X"), player_2 = Players::Human.new("O"), board = Board.new())
@player_1 = player_1
@player_2 = player_2
@board = board
end

# def current_player
# if @board.turn_count % 2 == 0
# player_1
# else
# player_2
# end
# end

def current_player
@board.turn_count % 2 == 0 ? player_1 : player_2
end

# def won?
# WIN_COMBINATIONS.each do |win_combination|
#
# win_index_1 = win_combination[0]
# win_index_2 = win_combination[1]
# win_index_3 = win_combination[2]
#
# position_1 = board.cells[win_index_1]
# position_2 = board.cells[win_index_2]
# position_3 = board.cells[win_index_3]
#
# if position_1 == "X" && position_2 == "X" && position_3 == "X"
# return win_combination
# elsif position_1 == "O" && position_2 == "O" && position_3 == "O"
# return win_combination
# end
# end
# false
# end

def won?
WIN_COMBINATIONS.find do |winner|
@board.cells[winner[0]] == @board.cells[winner[1]] &&
@board.cells[winner[1]] == @board.cells[winner[2]] &&
(@board.cells[winner[0]] == "X" || @board.cells[winner[0]] == "O")
end
end


# def draw?
# if board.full? == false
# false
# elsif won? == false
# true
# end
# end

def draw?
board.full? && !won?
end


# def over?
# if draw?
# true
# elsif won?
# true
# else false
# end
# end

def over?
draw? || won?
end

# def winner
# WIN_COMBINATIONS.each do |win_combination|
#
# win_index_1 = win_combination[0]
# win_index_2 = win_combination[1]
# win_index_3 = win_combination[2]
#
# position_1 = board.cells[win_index_1]
# position_2 = board.cells[win_index_2]
# position_3 = board.cells[win_index_3]
#
# if position_1 == "X" && position_2 == "X" && position_3 == "X"
# return "X"
# elsif position_1 == "O" && position_2 == "O" && position_3 == "O"
# return "O"
# end
# end
# return nil
# end

def winner
if wincombo = won?
@winner = @board.cells[wincombo[0]]
end
end

def turn
input = current_player.move(@board)
if @board.valid_move?(input)
@board.update(input, current_player)
else
turn
end
board.display()
end

def play
until over?
turn
end
if won?
puts "Congratulations #{winner}!"
elsif draw?
puts "Cat's Game!"
end
end

end
7 changes: 7 additions & 0 deletions lib/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Player
attr_reader :token

def initialize(token)
@token = token
end
end
18 changes: 18 additions & 0 deletions lib/players/computer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Players
class Computer < Player
def move(board)
computer_move = rand(0..9)
until board.valid_move?(computer_move)
computer_move = rand(0..9)
end
return computer_move.to_s
end
end
end



# 1. Check to see if two of the same tokens are next to each other and if so occupy the third spot next to them.
#
# 2. Check to see if two of the same tokes are in corner spots diagonally across from
# each other and if so occupy the middle spot.
8 changes: 8 additions & 0 deletions lib/players/human.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Players
class Human < Player
def move(board)
puts "Please enter 1-9:"
gets.strip
end
end
end
1 change: 1 addition & 0 deletions spec/05_computer_player_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
computer_move = computer.move(board)

expect(valid_moves).to include(computer_move)

end
end
end