Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Build a Simple Game UI Fast

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Build a Simple Game UI Fast. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Build the game-state logic for a minimal Connect Four experience that could be rendered in the Ramp mobile app. Given a board, a player, and a selected column, place the piece using gravity and determine whether the move produces a win, a draw, or an ongoing game.

Return a new state without modifying the input board. A win occurs when the active player has four contiguous pieces horizontally, vertically, or diagonally. The UI can use the returned board and status to render the next screen.

Formal Specification

Implement connect_four_move(board, column, player).

  • board is a 6-by-7 list of lists containing 0 for empty cells, 1 for player one, and 2 for player two.
  • column is an integer from 0 through 6.
  • player is either 1 or 2.
  • The selected column is guaranteed to contain an empty cell.
  • Return a dictionary with board, status, and next_player.
  • status must be "win", "draw", or "ongoing".
  • next_player is None after a win or draw; otherwise it is the opposing player.

Constraints

  • board has exactly 6 rows and 7 columns
  • Each cell is 0, 1, or 2
  • 0 <= column < 7
  • player is either 1 or 2
  • The selected column contains at least one empty cell
  • Existing pieces obey gravity

Function Signature

def connect_four_move(board, column, player):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output