Connect Four Referee
Implement a class ConnectFour that referees a game on a board with rows rows and cols columns. Players 1 and 2 take turns, player 1 first. A piece dropped into a column falls to the lowest empty cell. A player wins with four of their pieces in a line: along a row, along a column, or along either diagonal. The game is over once someone wins or the board is full. Write these methods:
ConnectFour(rows, cols)starts with an empty board.drop(col)drops the piece of the player to move into columncol(0is the leftmost) and passes the turn. Returns the row it lands in, with0the bottom row. If the column is full or the game is over, nothing changes and it returns-1.get_winner()returns the winning player, or0if nobody has won.whose_turn()returns the player to move, or0if the game is over.piece_at(row, col)returns1or2for a piece in that cell, or0if it is empty.
row and col are always on the board. The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.
Example 1
Player 1 fills the bottom row from column 0 to column 3, which is four in a row, so the game ends at once. The pieces of player 2 sit above them in row 1, and later drops are refused.
Constraints
4 <= rows, cols <= 70 <= row < rowsand0 <= col < cols- Each test makes
1to50method calls after the constructor.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.