This page is still under construction.

Parts of this page are still being built. What you see may change.

Yut Nori

Time limit1sMemory limit1024 MB

Summary
Model Yut Nori movement on four board routes and apply carrying, capturing and exit rules after each throw.
Level

Hard8 of 10

Topics
Implementation, Simulation, Graph
Solved
No attempts yet

Problem

Yut Nori is a traditional Korean game played by throwing yut sticks. One game uses 4 yut sticks, your 4 pieces and the opponent's 4 pieces, so 8 pieces in all, together with one board. The board has 29 squares laid out as below, and every square has a name. (Figure 1)

Figure 1: the yut board. Every square of the board carries its name.

Figure 2: the four possible routes.

The goal is to send four pieces out from Nalbat, the starting square, around the board, back to Nalbat, and then off the board.

A player's turn goes like this.

  • Throw the four yut sticks.
  • Read the number of squares to advance from how the sticks landed.
  • Choose a piece and advance it.

A yut stick has a front face and a back face, and a thrown stick lands showing one of them. The number of sticks showing the front face is the number of squares to advance. If all four show the back face, the piece advances 5 squares.

A piece that has not started yet counts as standing on Nalbat, and it advances along the routes below.

A piece moves along route 4 of Figure 2 by default. For example, advancing two squares from Yut moves the piece to Dwitdo. In special cases the piece moves along route 1, 2 or 3. When a piece begins its move on a corner (Dwitbat, Apbat, Bang, Jjeolbat or Nalbat), it moves toward the shorter way to Nalbat.

In detail, a piece that stood on Apbat when it began its move switches to route 3. Advancing one square from Apbat leaves the piece on Apmodo, and advancing two squares leaves it on Apmogae. Advancing one square twice from Yut leaves the piece on Apmodo, while advancing two squares once leaves it on Dwitdo.

A piece that stood on Dwitbat when it began its move follows route 2, so advancing one square from Dwitbat leaves it on Dwitmodo and advancing two squares leaves it on Dwitmogae.

A piece on route 3 that begins its move on Bang follows route 1. Advancing one square from Bang leaves the piece on Saryeo, and advancing two squares leaves it on Anjji.

Once a piece moving along the routes reaches Nalbat, one more square takes it off the board and it never appears on the board again. A move may cover the whole distance at once instead of being split in two. For example, advancing 2 squares from Nalgeol reaches Nalbat, and one more square takes the piece off the board. Advancing 3, 4 or 5 squares from Nalgeol can also take the piece off the board.

With only this, the game would come down to throwing the sticks well and getting out. So Yut Nori has extra rules that make the game fun and add competition.

The first is carrying. If two or more of your own pieces stand on the same square, moving one of them moves every one of your pieces on that square.

The second is capturing. If an opponent piece stands on the square your piece is moving to, that piece is taken off the board and put back where it started. When it starts again, it starts from Nalbat.

You are building this Yut Nori game. Given each turn of the game, print the state of the board.

Input

The first line contains NN. NN is the number of times the sticks were thrown and a piece was moved.

The ii-th of the next NN lines describes the ii-th turn. A turn is given as information about a piece and information about the sticks.

The information about the piece is one character out of ABCDabcd. The information about the sticks is four characters with no space between them, each one B for the back face or F for the front face. The two parts are separated by one space.

Uppercase letters are pieces of one team and lowercase letters are pieces of the other team, so a lowercase piece and an uppercase piece are on opposite sides.

Output

The empty yut board is the following 32×3232 \times 32 string.

..----..----..----..----..----..
..    ..    ..    ..    ..    ..
| \                          / |
|  \                        /  |
|   \                      /   |
|    ..                  ..    |
..   ..                  ..   ..
..     \                /     ..
|       \              /       |
|        \            /        |
|         ..        ..         |
|         ..        ..         |
..          \      /          ..
..           \    /           ..
|             \  /             |
|              ..              |
|              ..              |
|             /  \             |
..           /    \           ..
..          /      \          ..
|         ..        ..         |
|         ..        ..         |
|        /            \        |
|       /              \       |
..     /                \     ..
..   ..                  ..   ..
|    ..                  ..    |
|   /                      \   |
|  /                        \  |
| /                          \ |
..    ..    ..    ..    ..    ..
..----..----..----..----..----..

The string is made only of /, \, ., |, -, spaces and newlines. It stands for the yut board, and each square is drawn as a 2×22 \times 2 block of . characters. Reading the squares in row-major order from the top left gives, in order, Dwitbat, Dwityut, Dwitgeol, Dwitgae, Dwitdo, Apbat (Mo), Dwitmodo, Apmodo, Jjido, Yut, Dwitmogae, Apmogae, Jjigae, Geol, Bang, Jjigeol, Gae, Sokyut, Saryeo, Jjiyut, Do, Sokmo, Anjji, Jjeolbat, Naldo, Nalgae, Nalgeol, Nalyut and Nalbat.

Print which square each piece stands on after the NN turns. Each piece is printed on one of the . characters of the 2×22 \times 2 block that makes up its square.

Piece A or a replaces the . at the top left, B or b the one at the top right, C or c the one at the bottom left, and D or d the one at the bottom right.

Constraints

  • 1≤N≤1001 \le N \le 100
  • Every move is valid. A piece that has left the board never appears on the board again.

Examples2

  1. Example 1

    Input
    4
    A BBFB
    B BBFB
    A BFFB
    c FFFB
    
    Expected output
    ..----..----..----..----..----..
    ..    ..    ..    ..    ..    ..
    | \                          / |
    |  \                        /  |
    |   \                      /   |
    |    ..                  ..    |
    ..   ..                  ..   ..
    ..     \                /     ..
    |       \              /       |
    |        \            /        |
    |         ..        ..         |
    |         ..        ..         |
    ..          \      /          ..
    ..           \    /           c.
    |             \  /             |
    |              ..              |
    |              ..              |
    |             /  \             |
    ..           /    \           ..
    ..          /      \          ..
    |         ..        ..         |
    |         ..        ..         |
    |        /            \        |
    |       /              \       |
    ..     /                \     ..
    ..   ..                  ..   ..
    |    ..                  ..    |
    |   /                      \   |
    |  /                        \  |
    | /                          \ |
    ..    ..    ..    ..    ..    ..
    ..----..----..----..----..----..
    
  2. Example 2

    Input
    21
    A FFFB
    c FBBF
    d FBBB
    B BBFB
    C BFBF
    d FFBF
    B BFBF
    a BBBF
    C BBBB
    D FBFF
    a FFFB
    d FBFF
    b FFFF
    b BBBB
    c BFFF
    B BBFB
    b BBBF
    B FFFF
    c BBBB
    b BBBF
    A FFFF
    
    Expected output
    ..----..----..----..----..----.B
    ..    ..    cd    C.    ..    ..
    | \                          / |
    |  \                        /  |
    |   \                      /   |
    |    ab                  ..    |
    ..   ..                  ..   A.
    ..     \                /     ..
    |       \              /       |
    |        \            /        |
    |         ..        ..         |
    |         ..        ..         |
    ..          \      /          ..
    ..           \    /           ..
    |             \  /             |
    |              ..              |
    |              ..              |
    |             /  \             |
    ..           /    \           ..
    ..          /      \          ..
    |         ..        ..         |
    |         ..        ..         |
    |        /            \        |
    |       /              \       |
    ..     /                \     ..
    ..   ..                  ..   ..
    |    ..                  ..    |
    |   /                      \   |
    |  /                        \  |
    | /                          \ |
    ..    ..    ..    ..    ..    ..
    ..----..----..----..----..----..