Implement Connect Four Winner Detection
Connect Four Game Engine: Winner Detection
Design and implement the core logic for a Connect Four-style game engine.
Game Rules
The game is played on a board with 6 rows and 7 columns. Two players alternate turns.
Making a Move
On each turn, the current player chooses a column. Due to gravity, the player's token falls to the lowest empty cell in that column. A move is considered invalid if the chosen column is already full.
Winning Condition
After each valid move, the system must determine whether the current player has won. A player wins if they have four of their own tokens consecutively in any of the following directions:
- Horizontal
- Vertical
- Diagonal (bottom-left to top-right)
- Diagonal (top-left to bottom-right)
Implementation Focus
Your implementation should focus on:
- Placing a token on the board given a chosen column.
- Efficiently checking for a win condition after the latest move.
Follow-up Questions
- How would you support more than two players?
- How would you optimize the solution if the board were very large?
AI interview prep
Core dilemma
Balancing the simplicity and readability of board representation and win checking logic against the performance requirements, especially when considering larger boards or more complex game states. The central conflict is efficient state updates and pattern detection.
3 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement Connect Four Winner Detection
Connect Four Game Engine: Winner Detection
Design and implement the core logic for a Connect Four-style game engine.
Game Rules
The game is played on a board with 6 rows and 7 columns. Two players alternate turns.
Making a Move
On each turn, the current player chooses a column. Due to gravity, the player's token falls to the lowest empty cell in that column. A move is considered invalid if the chosen column is already full.
Winning Condition
After each valid move, the system must determine whether the current player has won. A player wins if they have four of their own tokens consecutively in any of the following directions:
- Horizontal
- Vertical
- Diagonal (bottom-left to top-right)
- Diagonal (top-left to bottom-right)
Implementation Focus
Your implementation should focus on:
- Placing a token on the board given a chosen column.
- Efficiently checking for a win condition after the latest move.
Follow-up Questions
- How would you support more than two players?
- How would you optimize the solution if the board were very large?