Hide

Problem T
Magnificent Noughts \& Crosses

Languages en is
/problems/mognudmylla/file/statement/en/img-0001.jpg
Image by Beatrice Murch, taken from commons.wikimedia.org

The judges have to pass their time in one way or another while a contest is ongoing, and the usual distraction of tic-tac-toe has gotten rather stale. Perfect tic-tac-toe, as covered in an earlier contest, has also become stale because all the judges have long figured out how to play it optimally.

Luckily Atli suddenly had a burst of inspiration and managed to improve the situation by inventing a new type of tic-tac-toe. In this version both players have both lower and upper case characters, so one player uses x and X while the other uses o and O. Each player starts with 4 lower case letters and 2 upper case letters.

If a player manages to place three of their letter in a row, lower or upper case, that player wins. The row can be diagonal, so there are $8$ possible rows to win on. If a player has no legal moves on their turn, they lose. Thus there is never a tie in this game, a great improvement over regular tic-tac-toe, which always ends in a tie between skilled players.

When a player is to move there are three options. The first one is to play a lower or upper case letter on an empty space, and then has one less of that letter left. A player can not play a letter that they have run out of. Secondly the player can play one of their upper case letters on top of a lower case letter that’s already on the board, removing the lower case letter (the corresponding player does not get that lower case letter back). Finally the third option is to move an upper case letter they have on the board on top of a lower case character that is also already on the board (the corresponding player does not get that lower case letter back either in this case). A player may only move their own upper case letters.

To get one over on the judges you have now managed to hack into the computer they are using to play against one another. You even managed to rig it so that you would always get to move first. Thus the only thing left to do is to make a program that can demolish the morale of the judges. Since you get the first move you have x and X.

Interactivity

This is an interactive problem. Your solution will be tested against an interactive judge which reads the output of your solution and prints the input your solution receives. This interaction follows certain rules:

Your program and the judge program will take turns printing the current board. The board is $3 \times 3$ squares, given as 3 letters each on 3 lines, with no whitespace aside from the 3 newline characters. An empty square is denoted by ..

Your program starts by printing the board after your first move. Then your program should read the board as it is after the judge makes its move. This then repeats. If the game is over, because someone has three in a row or someone has no moves left, the judge program will print Tap! (Icelandic for loss) or Sigur! (Icelandic for victory) depending on whether you won or lost. After this your program should exit. The judge program never prints a board and one of the strings Tap! or Sigur!.

Make sure to flush after each guess, for example using

  • print(..., flush=True) in Python,

  • cout << ... << endl; in C++,

  • System.out.flush(); in Java.

The task has a testing tool attached to help test your solution.

Scoring

Your program will be played against several opponents. It will play several games against each opponent. This will be a total of $50$ games, and for each victory you get $2$ points, getting $0$ points for a loss. If your program prints an illegal move or otherwise fails to run correctly you will get $0$ points for that game and it will be marked with Wrong Answer rather than Accepted. The final verdict is however Accepted as long as some game gets the verdict Accepted.

Read Sample Interaction 1 Write
...
.x.
...
o..
.x.
...
o.X
.x.
...
o.X
.x.
O..
X.X
.x.
O..
X.X
.x.
O.o
X..
.x.
O.X
Sigur!

Please log in to submit a solution to this problem

Log in