#P8069. L Chess: Finding the Mysterious Move

    ID: 21253 Type: Default 1000ms 256MiB

L Chess: Finding the Mysterious Move

L Chess: Finding the Mysterious Move

L Chess is a two‐player board game played on a 4×4 grid. There are two types of pieces:

  • L‐shaped piece of size 4, one for each player. Its shape is fixed relative to its orientation. For example, one valid L‐piece occupies cells at offsets (0,0), (1,0), (2,0) and (2,1) from its top‐left corner.
  • Neutral piece of size 1. There are two neutral pieces on the board.

At any time, each cell of the board can contain at most one piece. The players take turns. A legal move consists of two steps executed in order:

  1. Move your own L‐shaped piece to a new legal position (i.e. a placement of the fixed L shape different from its current one) such that none of its cells is occupied by an opponent’s L‐piece or a neutral piece. (Note that since your piece is removed from its current location before relocation, its former cells become available.)
  2. Optionally, move at most one neutral piece from its current cell to any empty cell.

If a player cannot make a legal move with their L‐piece, that player loses.

We define the following terms:

  • A mysterious move (妙棋) is a move by the first player that, after which a forced winning strategy exists.
  • A losing position (败局) is one in which, no matter what move the first player makes, the second player has a forced winning strategy.
  • A draw (和棋) is a position that is neither a winning position nor a losing one.

Given a board configuration, determine one mysterious move if it exists. If no mysterious move exists, output either losing if the position is a losing one, or draw otherwise. If there are multiple mysterious moves, output any one.

Notes on the board representation:

  • The board is presented as 4 lines with 4 characters each.
  • The characters are as follows: A for a cell occupied by the first player’s L‐piece, B for the second player’s L‐piece, N for a neutral piece, and . for an empty cell.
  • Each board configuration contains exactly 4 cells marked with A, exactly 4 cells marked with B, and exactly 2 cells marked with N.

Output format for a mysterious move:

If a mysterious move exists, output two lines:

  1. The first line contains 8 integers: the row and column coordinates of the 4 cells for the new placement of the first player’s L‐piece. The order of the cells is arbitrary but must correspond to the shape’s cells. Coordinates are 0-indexed.
  2. The second line either contains two integers representing the destination row and column for moving one neutral piece, or a single -1 if no neutral piece is moved.

Otherwise, output a single line with either losing or draw.

In all formulas (for example, the board size is written as \(4 \times 4\)), use LaTeX format.

inputFormat

Input consists of 4 lines, each containing exactly 4 characters without spaces. The characters can be A, B, N, or . representing the board configuration as described above.

outputFormat

If a mysterious move exists, output two lines: the first line with 8 space‐separated integers representing the coordinates of the 4 cells (row and column pairs) for the new placement of the first player’s L‐piece, and the second line with either two integers (row and column) for moving one neutral piece or -1 if no neutral piece is moved. Otherwise, output a single line containing either losing or draw.

sample

AN..
A.BB
AABB
N...
1 1 2 1 3 1 3 2

-1

</p>