Gomoku, also called go-moku (Japanese: Gomoku Narabe, "five points") is a tic-tac-toe-like game played on a rectangular board divided into unit squares. There are two players, and each of them has an infinite supply of pieces of his color. They alternately place their pieces on the board in an attempt to place five (or more) of their own pieces in a row (horizontally, vertically, or diagonally). As soon as one of the players has reached this goal, the game ends and he is the winner. If and only if no player has reached the goal and the whole board is full, the game is a draw.
You will be given a String board containing a position in the game, with the letter 'X' used to denote pieces of one player, the letter 'O' (not zero!) the pieces of the other player and '.' (period) to denote empty spaces. (Note that you don't know whether the player that started the game used 'O's or 'X's.)
Your task is to write a function that decides:
- whether this is a valid position (i.e., one that could arise if both players played according to the rules), and
- whether a player already won.
If the position is not valid, return the string "INVALID". If the position is valid and represents a draw game, return the string "DRAW". If the position is valid and one of the players won, return "X WON" or "O WON" respectively. Otherwise, return the string "IN PROGRESS".