Background
Skip to "Task" if you are familiar with Tic-Tac-Toe (I think most are!)
Tic-Tac-Toe is a famous two-player game. It consists of a 3x3 board that is filled gradually by two players (clarifications below); The first player uses the character X
and the other one uses O
. The winner is the first to get 3 consecutive and identical characters (X
or O
), either horizontally, vertically or diagonally. In case the board is filled and none of the players managed to get three consecutive characters as decribed above, the game ends in a tie. Note that there might be empty spots at the end of the game, in case either of the players wins in less than 9 moves in total (this cannot happen in case of a tie).
Task
Given a Tic-Tac-Toe board at the end of a game (in the form of a string, a matrix, a flat list of 9 ordered values, any other decent format), determine who wins the game.
The input will consist of distinct and consistent values, one for
X
, one forO
and another one that represents an empty spot.Your program should be able to output 3 distinct, consistent and non-empty values: one in case
X
wins, another one in caseO
wins or another if the players are tied.Please specify these values in your answer. You can assume that the input will be a valid Tic-Tac-Toe board.
Test Cases
X
, O
, _
are the input values here; X wins
, O wins
and Tie
are for the output.
X O X
O X _
O _ X
Output: X wins
.
X _ O
X O _
X O X
Output: X wins
.
X O X
_ O X
_ O _
Output: O wins
.
X O X
O O X
X X O
Output: Tie
.
As usual, all our standard rules apply. This is code-golf, the shortest code in bytes in every language wins!