Intro
You like cats. Naturally, you like cat’s games in tic-tac-toe. So, you’ve come up with a little party trick.
You ask someone what square on the board they want you to make a move in. And you ask someone else on which turn they want you to make that move. You also let that person decide whether you play Xs or Os. And with that, you’re off to the races.
You play your sidekick with the side they chose for you. And sure enough, when the turn they chose comes around, you move just in the spot they chose. And from there, you're able to secure a cat's game with your sidekick. (Your sidekick could take advantage of your forced move and beat you, or God forbid they could take the square first, but they're your trusty sidekick after all.) Et voila!
You’re convinced that you can end in a cat’s game no matter what they give you, but you want to make sure. Let’s give you a hand!
Challenge
Given a move on the tic-tac-toe board and a turn to make the move on, output a tied game where that move was played. A cat's game!
Any input/output to represent the given info and the resulting game is accepted. But here is the convention I’ll use in the examples:
There are 9 squares on a tic-tac-toe boards, and there are 9 turns in a drawn game, because every square must be filled. So my input examples will take a pair of integers 1-9. The first number will represent the turn number and the second number the square on the board to move in. Whether the turn number is even or odd tells you whether you’re playing X or O. My outputs will be the numbers 1-9 printed in a 3×3, representing the placement of the nth move. And the input is marked in parentheses, for easy reading.
Again, you may change the I/O scheme. Your output can, for example, flatten the grid and just return a simple list. This is what almost everyone has chosen, maybe you have another idea! Perhaps a list of numbers indicating the nth move made. And your input can switch the turn and move numbers, or do it entirely differently.
So with this particular I/O scheme, 3 5
represents moving in the 5th square, which is the center, on your 3rd turn. And your turn is odd, so you’re playing as X who is the first/odd player.
This is code-golf, so the shortest code in bytes wins.
Equivalently
One can frame the problem equivalently: Arrange the numbers 1-9 in a square such that you have no three evens or odds in a row. (With one number’s placement given by the input.) The fact that this can be solved by playing Tic Tac Toe means that this problem can be solved with a greedy algorithm!
Test Cases
>> 3 5
8 5 7
9 (3) 2
6 4 1
>> 5 3
9 8 (5)
2 3 1
4 7 6
>> 7 4
5 4 1
(7) 6 2
8 9 3
>> 1 1
(1) 2 4
6 3 5
7 9 8
>> 9 9
4 5 1
7 6 2
3 8 (9)
P.S. For those wondering about the title, I don’t know how widespread this is, but we always called a draw “a cat’s game”: Wiktionary & Etymology