10
1
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.)
What if a player types in a position that is already taken? – Loovjo – 2015-05-15T19:29:08.860
@Loovjo It returns
INVALID
. I've edited that in now, thanks. – ASCIIThenANSI – 2015-05-15T19:30:26.1771Should the game exit once 5 tiles are in a row are detected? – Kyle Kanos – 2015-05-15T23:55:23.117
1Maybe I overlooked it but does it have to print the board to the screen or just check the state of the board and output which player wins? – Kodos Johnson – 2015-05-16T00:18:17.510
@Andrew I actually meant to simulate the game. You accept each player's input, one turn at a time, and then check if a player has won each turn. Is the description unclear? – ASCIIThenANSI – 2015-05-16T02:48:52.923
@KyleKanos Yes. Once 5 tiles are in a row, it quits and prints
ORDER WINS
. – ASCIIThenANSI – 2015-05-16T03:02:06.107@ASCIIThenANSI
ORDER WINS
orP1 WINS
? – xebtl – 2015-05-16T09:42:57.360@xebtl Sorry, messed that up. It prints
P1 WINS
if there are 5 tiles in a row, andP2 WINS
if the board is full with no chains of 5 tiles in a row. – ASCIIThenANSI – 2015-05-16T13:24:25.633Yes the description is unclear. The board have to be printed at each turn or not? – edc65 – 2015-05-16T13:59:56.313
@edc65 Yes, it does. I'll make sure it's clearer. – ASCIIThenANSI – 2015-05-16T14:01:00.460