Order and Chaos is a variant of Tic-Tac-Toe played on a 6x6 board. What makes the game unique, however, is that both players can place either an X or an O! Each turn (starting with Order), a player places an X or O in any unoccupied square.
Winning is simple. Order wins if there are 5 Xs or Os (vertically, horizontally, or diagonally) in a row on the board. Chaos wins if the board is filled and there are no strings of 5 Xs or Os on the board. Your job? Well, since this is Programming Puzzles and Code Golf, you're going to program the game, and golf it.
The Rules
- You must accept input as
x y t
, wherex
andy
are coordinates, andt
is the tile type (X
orO
). Coordinates start with0 0
in the upper-left corner and increase up to5 5
(the lower-right corner). - You must accept
q
to quit, and printINVALID
if the user enters invalid coordinates, tiles, any input not in the form ofx y t
, or tries to place a tile where there already is one. (The only exception isq
, as this quits the program.) - If Order wins, you will output
P1 WINS
. If Chaos wins, you will outputP2 WINS
. - Order must go first.
- A blank space is represented by
.
. - Tiles are
X
andO
(uppercase). You do not have to accept lowercase, but uppercase is required. - Your board must only consist of
.XO
. - You're actually simulating both players playing the game, not being given a board and checking who wins. It accepts a move as input, then prints the board, accepts another move, and so on, until one player wins.
The starting board looks like this:
......
......
......
......
......
......
And after the first player (Order) inputs 1 2 X
, it should look like this:
......
......
.X....
......
......
......
Likewise, when the next player (Chaos) inputs 3 3 O
, it will look like this:
......
......
.X....
...O..
......
......
And this continues until one player wins.
As always, Standard loopholes which take the fun out of everything are forbidden.
The winner is the one with the shortest code on June 15, 00:00 UTC (about one month from when this challenge was posted.)
INVALID
. I've edited that in now, thanks. \$\endgroup\$