Gomoku
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Problem 4: Gomoku
Gomoku (Five in a row) is a board game where two players compete against each other, with each side taking turns placing a piece in each round. In Gomoku, Black(X) player first move.
In this problem, Given a Gomoku game board, you should determine whether the next player could win in one move, you only need to check one step forward.
On a 15×15 Gomoku board, the winning rules are as follows:
Winning Condition
When Black (X) or White (O) forms five or more consecutive pieces in any straight line (horizontal, vertical, or diagonal), they immediately win, and the game ends. The specific rules are:
-
Line Directions
Five consecutive pieces must be formed in one of the following directions:- Horizontal: Five consecutive pieces in the same row (e.g.,
XXXXX
). - Vertical: Five consecutive pieces in the same column (e.g.,
O
vertically aligned in five consecutive cells). - Diagonal: Five consecutive pieces in a diagonal line, either from top-left to bottom-right (
\
) or top-right to bottom-left (/
).
- Horizontal: Five consecutive pieces in the same row (e.g.,
-
Example Board Scenarios
-
Black wins (horizontal five in a row):
..XXXXX..........
-
White wins (diagonal five in a row):
O.... .O... ..O.. ...O. ....O
-
Input format
15 Lines, each line with 15 characters consists of only X
, O
, .
, denoting the Gomoku board.
Output format
If there is already a player won the game, output AlreadyWin!
If the next move of the game could win the game, you should output two lines. The first line should output Win!
, and the second line should output two integers x
, y
, denoting the position of the next move which could win the game. If there are multiple positions could win the game, output any of them.
If the next move of the game cannot win the game, you should output one line CannotWin!
...............
...XXXX........
...OOOO........
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
Win!
2 3
XXXXOOOO.......
..OXXXXO.......
..XOOOOX.......
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
CannotWin!
...............
..OXXXXO.......
..XOOOOX.......
.....OXXXX.....
....O..........
...O...........
...............
...............
...............
...............
...............
...............
...............
...............
...............
AlreadyWin!