Answered step by step
Verified Expert Solution
Link Copied!

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-4, two players compete against each other to form a continuous set of at least 4 pieces horizontally, vertically, or diagonally in a 6x7 board. That is, the winner has 4 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 2 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 1 pieces are marked 'X', player 2 pieces are marked 'O'. Empty slots are marked with a '.'. In the shown map, player 2 wins because 4'O's 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-4 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 4 pieces. If player 1 wins, you should print 1. If player 2 wins, you should print 2. If there is no winner, you should print 0.
Input Format
A 6 rows X 7 columns map describing the shape of the board
Constraints
No constraints
Output Format
A single number specifiying the winner of the game: 1 or 2 for player 1 or player 2, respectively. If there is no winner, 0 is printed
Sample Input 0
.......
.......
... X O ..
.. X O O ..
.. O X X . X
. O X O X . X
Sample Output 0
2
Sample Input 1
.......
.......
.......
. O .....
O O O ....
X X X X ...
Sample Output 1
1
Sample Input 2
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 2
0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions