Shift Tac Toe - Code Golf Challenge

Shift Tac Toe

Shift Tac Toe is a game that combines Tic Tac Toe and Connect 4 together. In this game, you start with a 3 by 3 board, and each row is connected to a slider that you can move left and right. At the start, the sliders all start to the very right(this means that you can't move the slider to the right on the first turn). Each slider can hold a total of 5 pieces. Each turn, the player can drop an O or a X in one of the 3 columns of the Tic Tac Toe grid depending on which turn it is, or the player can move one of the sliders one spot to the left or to the right. All pieces fall to the bottom most space that is unoccupied. The pieces can also fall from one slider to another outside the 3 by 3 grid. If a piece is outside the 3 by 3 grid and doesn't fall into the bottom slider, then the piece is taken out. If it does reach the bottom slider, it will stay in play. A notable example of this is shown in the following grid:

     --- --- --- --- ---
|   |   |   |   - O -
--- --- --- --- --- ---
-   |   |   |   |   -
--- --- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- ---
In the grid above, the dashes(-) indicate the part of the sliders that are outside of the 3 by 3 grid and the vertical bars(|) indicate the 3 by 3 grid.
As you can see, this is the starting board except that the middle slider is one spot over to the left, and that there is an O at the very top right.
What happens in this scenario? There is nothing immediately underneath it, so does it go out of play?
No. This is because it still falls into the bottom slider, which means that it is still in play.

The final grid is this:
--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- --- ---
-   |   |   |   |   -
--- --- --- --- --- ---
|   |   |   |   - O -
--- --- --- --- ---


Pieces can also stack outside of the 3 by 3 grid. Players will alternate between O and X, with the O player going first.

Example game:

Start with 3 by 3 grid with sliders all the way to the right:

--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- ---

The O player places an O in the middle column of the 3 by 3 grid and it falls to the bottom:

--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- ---
|   | O |   |   -   -
--- --- --- --- ---

The X player then places an X in the middle column:

--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- ---
|   | X |   |   -   -
--- --- --- --- ---
|   | O |   |   -   -
--- --- --- --- ---

The O player then pushes the middle row slider one space to the left.
Notice that after the slider moves, there is nothing under the X anymore, so it falls down.
Also note that the slider has moved one space to the right as indicated below:

--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- --- ---
-   |   |   |   |   -
--- --- --- --- --- ---
| X | O |   |   -   -
--- --- --- --- ---

The X player places a X in the rightmost column:

--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- --- ---
-   |   |   |   |   -
--- --- --- --- --- ---
| X | O | X |   -   -
--- --- --- --- ---

The O player then moves the bottom slider one spot to the left.
Notice that all the pieces shift one place to the left, and the leftmost X is now out of the playing field:

--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- --- ---
-   |   |   |   |   -
--- --- --- --- ---
- X | O | X |   |   -
--- --- --- --- ---

The X player places a X in the leftmost column:

--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- --- ---
-   | X |   |   |   -
--- --- --- --- ---
- X | O | X |   |   -
--- --- --- --- ---

The O player places an O in the leftmost column:

--- --- --- --- ---
| O |   |   |   -   -
--- --- --- --- --- ---
-   | X |   |   |   -
--- --- --- --- ---
- X | O | X |   |   -
--- --- --- --- ---

The X player shifts the top slider one place to the left. Notice that the O falls one place down because there is nothing beneath it:

--- --- --- --- ---
-   |   |   |   |   -
--- --- --- --- ---
- O | X |   |   |   -
--- --- --- --- ---
- X | O | X |   |   -
--- --- --- --- ---

The O player is not very good at this game, so he shifts the middle slider one place to the right.
This shifts all the pieces in the middle row one place to the right:

--- --- --- --- ---
-   |   |   |   |   -
--- --- --- --- --- ---
| O | X |   |   -   -
--- --- --- --- --- ---
- X | O | X |   |   -
--- --- --- --- ---

The X player wins the game by placing a X in the middle column:

--- --- --- --- ---
-   |   | X |   |   -
--- --- --- --- --- ---
| O | X |   |   -   -
--- --- --- --- --- ---
- X | O | X |   |   -
--- --- --- --- ---


Your job is to take in a string or array of any length that only consists of 9 unique characters(you choose the characters). Three of the characters will choose which column you place the X or O(depending on whose turn it is), three of them will choose which slider to move right, and the last three will choose which slider to move left. You can assume that the input only has these 9 characters. The output should be a 3 by 3 matrix or some kind of list/string that clearly shows the final position of the grid upon following the instructions of the input. You can assume that all inputs are valid. Each character takes up a turn. Also, if any move results in a winning move(forms 3 in a row in the 3 by 3 grid like regular Tic-Tac-Toe), then ignore the rest of the input. Note that the pieces that form the winning 3 in a row all have to be in the 3 by 3 grid. The two example grids below are NOT winning positions:

Grid #1:
--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- ---
|   |   |   |   -   -
--- --- --- --- ---
|   |   | O | O - O -
--- --- --- --- ---
This is not a winning move because two of the O's are outside the playing field, despite the fact that it forms a 3 in a row.
Using the character assignment stated below, this grid pattern can be achieved with 99372467643.

Grid #2:
--- --- --- --- ---
|   |   |   |   - O -
--- --- --- --- ---
|   |   |   | O - X -
--- --- --- --- ---
|   |   | O | X - X -
--- --- --- --- ---
This is not a winning position because two of the O's are outside the playing field.
Using the character assignment below, this grid pattern can be achieved with 939318836537734654


In the examples below, 1, 2, and 3 mean drop in the leftmost, middle, and rightmost column respectively. 4, 5, and 6 mean to move the top, middle, and bottom slider to the right respectively, and 7, 8, and 9 mean to move the top, middle, and bottom slider to the left respectively.

Examples

Input will be in the form of a string
Output will be a list of lists, with each sub-list representing a row(I'm Python programmer so this list format might not be compatible with all languages).
The first, second, and third sub-list correspond to the top, middle, and bottom row of the 3 by 3 grid respectively.
The output will have 'O' for the O pieces, 'X' for the X pieces, and an empty string for empty spaces.

Input: 123332
Output:
[['','','O'],
['','X','X'],
['O','X','O']]

Input: 33387741347
Output:
[['','',''],
['','','O'],
['X','O','X']]

Input: 2283911752
Output:
[['','X',''],
['O','X',''],
['O','X','']]

Input: 228374739
Output:
[['','',''],
['','',''],
['X','X','X']]

Input: 8873334917349
Output:
[['','',''],
['','','O'],
['X','X','O']]

Input: 799333466
Output:
[['','',''],
['','',''],
['','','']]

Input: 99372467643
Output:
[['','',''],
['','',''],
['','','O']]

Input: 939318836537734654
Output:
[['','',''],
['','',''],
['','','O']]



This is , so shortest code wins!

• This looks like a nice first challenge! How flexible is the output format? May we just return a 3x3 matrix in any convenient format? (I would recommend to allow that, as the main point of the challenge is obviously to simulate the game.) – Arnauld Aug 1 at 21:41
• @Arnauld I was hoping that the code would actually print out the 3 by 3 grid like shown in the examples but I could implement your suggestion if you think that's the best thing to do. – Aiden Chow Aug 1 at 21:45
• Let's see what others have to say about that, but we usually discourage cumbersome I/O formats unless that's the very point of the challenge, or any peripheral task that may turn the challenge into a chameleon. – Arnauld Aug 1 at 21:53
• It's not a good idea to mix a challenge that's going to require some processing to get the correct answer along with ascii-art output. Usually a challenge is just one or the other, – Noodle9 Aug 1 at 22:16
• The problem you have now is that it's quite a complex challenge just to calculate the final grid and you've added error handling into the mix. Usually challenges assume only valid input unless the challenge itself is just to verify if the input is or isn't valid. – Noodle9 Aug 2 at 12:12