C语言来Interesting Maze Game

Description

The Police President has recently bought a new game -- the famous Ravensburger's aMAZEing Labyrinth. Now, he is really keen on it, he spends any free time playing this game. While we want the Police President during the Summit to perform much more important decisions, we need a program that would substitute him in playing the game.

The game is played on the field of 7 * 7 squares with equal-sized cards lying on each square. Various path patterns are drawn on the cards, these paths join arbitrary subset of the four edges of a single square. The patterns can form longer paths leading through the whole game field. When following these paths, it is possible to move from a square to its neighbouring square, if both squares contain the path pattern leading to their common edge. It is impossible to travel between squares diagonally. See the picture for a better idea about the game appearance.

In the beginning of the move, the player has one game piece on some of the square cards and his/her goal is to move the piece to some other square card (target) following the valid paths. Before the walk, the player alters the maze state by inserting one extra square card into it.
The extra card can only be inserted to the position at the field margin. The insertion causes the whole row or column of cards to be shifted one position further, which makes another card to fall out at the other end of the game field. (This card becomes a new extra card for the next move, but we will care of a single move only in this problem.)
Since the cards with both coordinates odd are stuck firmly to the playing desk, only the even rows and columns can be shifted. Thus, the extra card can be inserted into an even row or column only. If we number rows and columns with numbers 1 to 7, there are 12 possible positions where the new card can be inserted: (1,2), (1,4), (1,6), (7,2), (7,4), (7,6), (2,1), (4,1), (6,1), (2,7), (4,7), and (6,7). For instance, insertion into the position (7,6) causes the following shift:
(7,6) -> (6,6) -> (5,6) -> (4,6) -> (3,6) -> (2,6) -> (1,6)

The extra card comes to the position (7,6) and the card formerly being at the position (1,6) is removed from the game field for the rest of the move.
Before insertion, the extra card can be rotated to any of the four possible directions. No other card in the game can be rotated. This makes the total maximal number of 48 possible moves (if the extra card is asymmetric).

Another important rule considers the case when the target card or the card with the player's piece appears in the row or column being shifted. In such case, the position of the piece or the target is shifted too. This makes it possible to move the target to some more appropriate place.

Note that if the target is shifted away from the game (the target card falls out from the game), it is no more possible to reach it in the same move -- the piece cannot leave the game field. On the other hand, if the game piece is located on the card which is moved away from the game field, the piece position is "wrapped" to the opposite end of the field, i.e., to the just inserted card.

Therefore, a valid move consists of two parts: insertion of the extra card into the game (this action must always be made) and walking the path of an arbitrary length (including zero, i.e., staying on the same square). Your task is to determine, whether it is possible to reach the target in a single move. In other words, if it is possible to insert the extra card into the game and then to walk to the target position.

Input

The input consists of several game descriptions. The first line of each description contains four integer numbers R1, C1, R2, and C2separated with a space, 1 <= R1, C1, R2, C2 <= 7. (R1,C1) is the position (row and column) of the game piece, (R2,C2) is the position of the target. Note that these positions can sometimes be shifted during the move, as specified above. After these numbers, there is one blank line.

The next three lines describe the first row of the game field. Each of these lines contains 27 characters: three for the card in the first column, one space, three characters for the card in the second column, etc. Thus, every card is represented by a square of nine (3 * 3) characters. The middle one of these nine characters is always capital letter "O". The four characters in the corners are always dots ("."). The both left and right characters are either a dot (".") or a dash ("-"). Dashes mean the path pattern leading to the left or right edge. The top and bottom characters are either a dot or a pipe ("|"). The pipe means the path pattern leading to the corresponding edge.

After the first row, there is one blank line and three other lines describing the second row. Then follow one other blank line and three lines for the third row, etc. After the seventh row, there is a blank line and three other lines containing exactly three characters each. This is the description of the extra card, given in the same way as the cards in the field.

The input is terminated by a line containing four zeros instead of piece and target coordinates.
Output

For each game, output a single line. If it is possible to insert the extra card in such a way that there is a path from the game piece to the target, print the sentence "You can win in one move.". Otherwise, print the sentence "Bad luck!".
Sample Input

1 1 7 7

... ... ... .|. ... ... ...
-O- -O- -O- .O. -O- -O- -O.
... ... ... .|. ... ... .|.

... ... ... ... ... ... .|.
.O- -O- -O- -O- -O- -O- -O.
.|. ... ... ... ... ... ...

.|. ... ... ... ... ... ...
.O- -O- -O- -O- -O- -O- -O.
... ... ... ... ... ... .|.

... ... ... ... ... ... .|.
.O- -O- -O- -O- -O- -O- -O.
.|. ... ... ... ... ... ...

.|. ... ... ... ... ... ...
.O- -O- -O- -O- -O- -O- -O.
... ... ... ... ... ... .|.

... ... ... ... ... ... .|.
.O- -O- -O- -O- -O- -O- -O.
.|. ... ... ... ... ... ...

.|. ... ... ... ... ... ...
.O- -O- -O- -O- -O- -O- -O.
... ... ... ... ... ... ...

.|.
.O.
.|.

1 1 7 7

... ... ... ... ... ... ...
-O- -O- -O- -O- -O- -O- -O.
... ... ... ... ... ... .|.

... ... ... ... ... ... .|.
.O- -O- -O- -O- -O- -O- -O.
.|. ... ... ... ... ... ...

.|. ... ... ... ... ... ...
.O- -O- -O- -O- -O- -O- -O.
... ... ... ... ... ... .|.

... ... ... ... ... ... .|.
.O- -O- -O- -O- -O- -O- -O.
.|. ... ... ... ... ... ...

.|. ... ... ... ... ... ...
.O- -O- -O- -O- -O- -O- -O.
... ... ... ... ... ... .|.

... ... ... ... ... ... .|.
.O- -O- -O- -O- -O- -O- -O.
.|. ... ... ... ... ... ...

.|. ... ... ... ... ... ...
.O- -O- -O- -O- -O- -O- -O.
... ... ... ... ... ... ...

...
.O-
.|.

0 0 0 0

Sample Output

You can win in one move.
Bad luck!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

0
C语言NxM二维数组实现Map的一个算法,用C语言编程的方式解决
0
c语言,迷宫问题,救救孩子
0
使用C语言,计算骨头的重量的问题,怎么采用C程序编写的代码运行的计算呢?
1
圆圈和线段在坐标系上的计算,怎么采用C语言的程序的代码的编写的功能加以实现?
0
迷宫的寻找的路线的问题,要求使用C语言的程序的编写的设计的代码的过程的做法怎么才能实现的呢?
0
圆和直线线段的焦点和相切,怎么使用C语言的程序的代码编写的办法有效地实现的过程是什么
0
计算以最小化离开迷宫的预期步数,怎么才能采用C语言的程序的设计的代码的编写的过程的设计的实现的原理
0
迷宫的寻找的路线的问题,要求使用C语言的程序的编写的设计的代码的过程的做法的实现
0
迷宫输出要通过的最短命令序列,怎么使用C语言的程序的解决的思路去编写程序的代码的
0
算法计算球将通过一个洞或一个终点掉落的概率,怎么使用C语言的程序的编写设计的过程的
0
计算圆形和线段的切线的问题,要求是使用C语言的程序的代码设计的编写的过程如何加以实现的呢
0
计算海豚出水的时间,怎么采用C语言的代码的设计的方式加以有效正确实现的
0
C语言的选择问题的判断的计算,用程序的实现
0
Game III的一个版本的计算
0
Line & Circle Maze,程序怎么设计呢
0
Teleport Out!用C语言的代码的编写
0
Rain on your Fat brother, C语言
0
问题,Ali and Baba的求解的过程步骤
0
Line & Circle Maze问题的解答
0
C语言,Treasure of the Chimp Island