L Game
Time limit1sMemory limit128 MB
Given a 4x4 L-Game board, determine if the player to move has a forced win, output the lexicographically smallest winning resulting board, or report draw/loss under perfect play.
- Level
Hard9 of 10
- Topics
- Game theory, Brute force, Backtracking, Graph
- Solved
- No attempts yet
Problem
The L Game, invented by Edward de Bono, is a game of pure skill played on a 4x4 board. Each of the two players owns a single L piece — an L-shaped tetromino that covers four squares. There are also two neutral square pieces, each covering a single square. Your goal is to manoeuvre your opponent into a position where they cannot move their L piece.
On each turn the player to move acts in this fixed order:
- Move the L piece (mandatory). Lift the L piece and place it back anywhere on the board, in any orientation — it may be slid, rotated, or flipped over. Its new placement must cover four empty squares and must be different from the placement it occupied before this move.
- Move a neutral piece (optional). After the L piece has been placed, you may move at most one neutral piece to any empty square. You are never required to move a neutral piece.
A player wins as soon as their opponent, on their own turn, has no legal way to move their L piece. The board is tiny but the game is deep: in a cramped position the L piece may reach only a couple of destinations, giving for example 2 x (6 + 6 + 1) = 26 possible moves, while in the busiest positions there are as many as 195 different moves. In total there are more than 18,000 legal positions.
Both players are assumed to play perfectly.
- A winning move is a move after which the opponent, no matter how they respond, cannot avoid losing.
- A player is losing when every move available to them still leads to a loss.
- If neither player can force a win, the position is a draw (perfect play would continue forever).
You are given a position with player A to move. Decide whether A has a winning move. If so, you must produce one; otherwise you must decide whether the game is a draw or A is losing.
Input
The input consists of four lines, each containing four characters, describing a game in progress:
.— an empty square;x— a neutral square piece;#— player A's L piece;*— player B's L piece.
Player A is to move. The position is guaranteed to be legal, and player A has at least one legal move.
Output
If player A has a winning move, output the position that results from it (after A's mandatory L-piece move and optional neutral-piece move), using the same four-line format as the input.
Several winning moves may exist. To make the answer unique, output the winning move whose resulting board is lexicographically smallest, where a board is compared as its four output lines joined by newline characters.
If player A has no winning move, print a line containing exactly No winning move, and on the following line print Draw if the game is a draw under perfect play, or Losing if player A loses under perfect play.