Skip to content

Instantly share code, notes, and snippets.

@castillejoale
Last active January 20, 2017 03:41
Show Gist options
  • Save castillejoale/17dbe3d7f9ec2f8d61b1f7d18146b853 to your computer and use it in GitHub Desktop.
Save castillejoale/17dbe3d7f9ec2f8d61b1f7d18146b853 to your computer and use it in GitHub Desktop.
func winDetection() -> Bool {
//Check rows
for i in 0...2 {
if((board[3*i] == board[3*i + 1]) && (board[3*i] == board[3*i + 2]) && !(String(board[3*i]) == "EMPTY")){
print("Someone won at row:")
print(i)
print( board[i])
return true
}
}
//Check columns
for j in 0...2 {
if((board[j] == board[j + 3]) && (board[j] == board[j + 6]) && !(String(board[j]) == "EMPTY")){
print("Someone won at column:")
print(j)
print( board[j])
return true
}
}
//Check diagonals
if((board[0] == board[4]) && (board[0] == board[8]) && !(String(board[0]) == "EMPTY")){
print("Someone won at diagonal 1")
return true
}
if((board[2] == board[4]) && (board[2] == board[6]) && !(String(board[2]) == "EMPTY")){
print("Someone won at diagonal 2")
return true
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment