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 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 4x4): board1 = ['RRRG', board2 = ['GRRG', '....', '.GGR', 'GRRG', 'GRGR', '.R..'] '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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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. 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 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 4x4):

board1 = ['RRRG', board2 = ['GRRG', '....', '.GGR', 'GRRG', 'GRGR', '.R..'] '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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Topological Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education