In the game of Connect Four, two players take turns playing on an n x n board, which we represent as a 2d list (a list of strings). To win, a player needs to connect 4 consecutive pieces in a row or column, or diagonally (either direction is OK). The input board is guaranteed to be a square board. You will implement a function findWinner (B: List[str]) -> str that takes a board and returns the winner or if no one has won. Specifically, the given board в will be a list of n strings, where each string has length n . There are two players R and G, so each position in the board B[i][j] is either the string R or G if it has been occupied--- or (dot) for an unoccupied spot. You are to return the string R if the R player has won; the string Gif the G player has won; or the string otherwise. Notice that the size of the board can be obtained by asking for the length of B. We guarantee that if there's a winner, that player will be the only winner. Here are a few examples (keep in mind, the board size doesn't have to be 4x4): board1= ['RRRG', 'GRRG', '.R..'] board2= ['GRRG', '.GGR', 'GRGR' › 'RGRG'] In these cases, findWinner(board1)=='-' ' and findwinner(board2)=='G' . Performance Expectations: The largest input you will be tested is a 100-by-100 board, and your function must return within 2 seconds.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
In the game of Connect Four, two players take turns playing on an n x n board, which we represent as a 2d list (a list
of strings). To win, a player needs to connect 4 consecutive pieces in a row or column, or diagonally (either direction is
OK). The input board is guaranteed to be a square board.
if no
You will implement a function findWinner (B: List[str]) -> str that takes a board and returns the winner or
one has won. Specifically, the given board B will be a list of n strings, where each string has length n. There are
two players R and G, so each position in the board B[i][j] is either the string R or G if it has been occupied---
or (dot) for an unoccupied spot. You are to return the string R if the R player has won; the string G if the G
player has won; or the string otherwise.
Notice that the size of the board can be obtained by asking for the length of B. We guarantee that if there's a
winner, that player will be the only winner.
Here are a few examples (keep in mind, the board size doesn't have to be 4×4 ):
board1 = ['RRRG',
'GRRG'
'.R..']
board2= ['GRRG',
'.GGR'
'GRGR'
'RGRG']
In these cases, findWinner (board1)=='=' and findWinner (board2)=='G' .
Performance Expectations: The largest input you will be tested is a 100-by-100 board, and your function must return
within 2 seconds.
Transcribed Image Text:In the game of Connect Four, two players take turns playing on an n x n board, which we represent as a 2d list (a list of strings). To win, a player needs to connect 4 consecutive pieces in a row or column, or diagonally (either direction is OK). The input board is guaranteed to be a square board. if no You will implement a function findWinner (B: List[str]) -> str that takes a board and returns the winner or one has won. Specifically, the given board B will be a list of n strings, where each string has length n. There are two players R and G, so each position in the board B[i][j] is either the string R or G if it has been occupied--- or (dot) for an unoccupied spot. You are to return the string R if the R player has won; the string G if the G player has won; or the string otherwise. Notice that the size of the board can be obtained by asking for the length of B. We guarantee that if there's a winner, that player will be the only winner. Here are a few examples (keep in mind, the board size doesn't have to be 4×4 ): board1 = ['RRRG', 'GRRG' '.R..'] board2= ['GRRG', '.GGR' 'GRGR' 'RGRG'] In these cases, findWinner (board1)=='=' and findWinner (board2)=='G' . Performance Expectations: The largest input you will be tested is a 100-by-100 board, and your function must return within 2 seconds.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY