FunctionRacerProblemsRace

Connect Four Referee

MediumClassesPython, JavaScript, TypeScript, Java, C++

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:

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

ConnectFour(6, 7)
drop(0) returns 0
drop(0) returns 1
drop(1) returns 0
drop(1) returns 1
drop(2) returns 0
drop(2) returns 1
drop(3) returns 0
get_winner() returns 1
whose_turn() returns 0
drop(4) returns -1
piece_at(1, 2) returns 2

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems