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

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

Done #624

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
41 changes: 41 additions & 0 deletions lib/game_status.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
# Helper Method
require "pry"

def position_taken?(board, index)
!(board[index].nil? || board[index] == " ")
end

# Define your WIN_COMBINATIONS constant
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 won?(board)
WIN_COMBINATIONS.detect do |winning_combo|
position_taken?(board, winning_combo[0]) && (board[winning_combo[0]] == board[winning_combo[1]] && board[winning_combo[1]] == board[winning_combo[2]])
end
end

def full?(board)
board.all?{|space| space == "X" || space =="O"}
end

def draw?(board)
board.all?{|space| space == "X" || space =="O"} && !won?(board)
end

def over?(board)
board.all?{|space| space == "X" || space =="O"} || won?(board)
end

def winner(board)
#check for a winner
if wins = won?(board)
board[wins[0]]
end
#if we find a winner, return value on the board of which player won
#if not, return nil
end