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.
- You must accept input as
x y t, where
yare coordinates, and
tis the tile type (
O). Coordinates start with
0 0in the upper-left corner and increase up to
5 5(the lower-right corner).
- You must accept
qto quit, and print
INVALIDif the user enters invalid coordinates, tiles, any input not in the form of
x y t, or tries to place a tile where there already is one. (The only exception is
q, as this quits the program.)
- If Order wins, you will output
P1 WINS. If Chaos wins, you will output
- Order must go first.
- A blank space is represented by
- Tiles are
O(uppercase). You do not have to accept lowercase, but uppercase is required.
- Your board must only consist of
- 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.)