Auto Tic Tac Toe
Okay, so after thinking about the comment I think I thought of a way to make it more interesting.
Challenge
Given no input, write a program or function which outputs an entire game of Tic-Tac-Toe where X always wins, or the game ends in a tie.
Requirements
- X goes first
- O must make moves at random
- X must make smart moves such that it always wins the game, or the game ends in a tie
Example
Here's what I would expect a game to look like:
X--
---
---
XO-
---
---
XO-
-X-
---
XOO
-X-
---
XOO
-X-
--X
Notes:
- X does not need to win in the fewest moves, it is enough to just make it always block O from winning
- You can output the game in whatever form you like, as long as it is easily conveys every turn of the game. For example you could output a string like above, or a list of lists of ints like below, where 0 is an empty space and 1, 2 are X, O respectively:
[
[1,0,0, 0,0,0, 0,0,0],
[1,2,0, 0,0,0, 0,0,0],
[1,2,0, 0,1,0, 0,0,0],
[1,2,2, 0,1,0, 0,0,0],
[1,2,2, 0,1,0, 0,0,1]
]
This is code golf, answer in the fewest bytes wins. Standard rules apply.
Is this a better challenge? I'd love to know what people think
Working example of ungolfed code: Try it online!Try it online!