Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In a Connect - 4 , two players compete against each other to form a continuous set of at least 4 pieces horizontally, vertically, or
In a Connect two players compete against each other to form a continuous set of at least pieces horizontally, vertically, or diagonally in a x board. That is the winner has pieces or more formulating a line with no interruption from the pieces of the opponent. In our version of the game, a player may play times consecutively without giving the turn to the opponent. This means that you cannot rely on the number of pieces to determine the winner. When inserted, the pieces are dragged to the bottom of the board as shown below. Player pieces are marked X player pieces are marked O Empty slots are marked with a In the shown map, player wins because Os are diagonally set from the bottom left to the top right. X O X O O O X X X O X O X X
You will be given a map of a Connect game where one player wins. You are required to determine the winner. Remember that the game stops once one player wins, so there is no possibility that the two players win at the same time. However, a game may end with a draw where the board is full and none of the two players can connect pieces. If player wins, you should print If player wins, you should print If there is no winner, you should print
Input Format
A rows X columns map describing the shape of the board
Constraints
No constraints
Output Format
A single number specifiying the winner of the game: or for player or player respectively. If there is no winner, is printed
Sample Input
X O
X O O
O X X X
O X O X X
Sample Output
Sample Input
O
O O O
X X X X
Sample Output
Sample Input
X X X O X X X
O O O X O O O
X X O O O X O
O O X X O O X
X X O O X X O
X X O O X O X
Sample Output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started