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 #607

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Done #607

Changes from all commits
Commits
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
47 changes: 46 additions & 1 deletion lib/game_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,50 @@
def position_taken?(board, index)
!(board[index].nil? || board[index] == " ")
end
WIN_COMBINATIONS = [
[0,1,2], #top row
[3,4,5], #middle row
[6,7,8], #bottom row
[0,3,6], #top left straight down to bottm left
[1,4,7], #top middle straight down to bottom middle
[2,5,8], #top right straigh down to bottom right
[0,4,8], #diagonal top left to bottom right
[2,4,6] #diagonal top right to bottom left
]

# Define your WIN_COMBINATIONS constant
def won?(board)

WIN_COMBINATIONS.detect do |win|
if board[win[0]] == "X" && board[win[1]] == "X" && board[win[2]] == "X"
return win
elsif
board[win[0]]== "O" && board[win[1]] == "O" && board[win[2]] == "O"
return win
end
end
false
end

def full?(board)
board.each do |spot|
if spot == " "
return false
end
end
end

def draw?(board)
full?(board) && !won?(board)
end

def over?(board)
won?(board) || draw?(board)
end

def winner(board)
if won?(board)
board[won?(board)[0]]
else
return nil
end
end# Define your WIN_COMBINATIONS constant