This is for a tic tac toe game. I have an array board with nine string elements, and a nested array WIN_COMBINATIONS with position combinations from board:
board = ["X", "X", "X", " ", " ", " ", " ", " ", " "]
WIN_COMBINATIONS = [
[0, 1, 2],
[0, 3, 6],
[0, 4, 8],
[3, 4, 5],
[6, 7, 8],
[6, 4, 2],
[1, 4, 7],
[2, 5, 8]
]
How do I choose the array combinations from board that are all "X" or all "O" using the combinations found in WIN_COMBINATIONS?
For example a different board than the one above in which X wins in the right diagonal.
board = ["X", "O", "X", "O", "X", "O", "X", "X", "O"]
# X | O | X
# ---+---+---
# O | X | O
# ---+---+---
# X | X | O
won?(board) #=> [2,4,6]