← Questions

Backend for a game of checkers

0
SpaceXAICodingLast asked Feb 2026

A coding interview question asked in SpaceXAI's onsite applied coding round, last asked Feb 2026. It tests object-oriented design, game and simulation.

Build the backend of a two-player checkers game in limited time: the board state, legal moves, captures, promotion to king and the end of the game. The interviewer cares more about a working core and a data model you can explain than about polish.

Interface

Unless you agree on a different interface with the interviewer, assume standard 8×8 checkers:

  • Game(): a new game. Rows and columns run 0 to 7, row 0 at the top. Pieces stand only on squares where (row + col) is odd. BLACK fills rows 0 to 2 and moves down (toward row 7); WHITE fills rows 5 to 7 and moves up. BLACK moves first.
  • board() -> list[list[str]]: "." empty, "b"/"w" a man, "B"/"W" a king.
  • current_player() -> str: "BLACK" or "WHITE".
  • legal_moves() -> list[list[tuple[int, int]]]: every legal move for the current player, each as a path of squares from the starting square. A plain move has two squares; a capture lists every landing square of its jumps.
  • move(path: list[tuple[int, int]]) -> None: plays the move, removes captured pieces, promotes a man that reaches the far row, and passes the turn. Raises ValueError for an illegal move and leaves the state unchanged.
  • winner() -> str | None: the player whose opponent has no pieces or no legal move, else None.

Rules: men move one square diagonally forward; kings move one square diagonally in any direction. A capture jumps a diagonally adjacent enemy piece onto the empty square behind it. If any capture is available, the player must capture, and must keep jumping with the same piece while it can. A man that reaches the far row becomes a king and its move ends there.

Example

g = Game()
g.current_player()      -> "BLACK"
len(g.legal_moves())    -> 7
    # (2,1)->(3,0) (2,1)->(3,2) (2,3)->(3,2) (2,3)->(3,4)
    # (2,5)->(3,4) (2,5)->(3,6) (2,7)->(3,6)
g.move([(2, 1), (3, 0)])
g.current_player()      -> "WHITE"
g.move([(5, 0), (4, 1)])
g.move([(3, 0), (5, 2)])  -> ValueError   # (5,2) is occupied, no jump here

Constraints

  • A game is short (well under 200 moves), so clarity beats micro-optimization.
  • move must validate against the same rules as legal_moves, not a separate copy of them.

Clarifying questions

  • Are captures mandatory, and must a multi-jump be completed?
  • Do kings move one square or any distance along a diagonal (flying kings)?
  • Does reaching the far row in the middle of a multi-jump end the move?
  • Is a draw needed (repetition, a move limit)?
  • Is this a library, or a service with players, game ids and an API?

What a strong answer covers

  • A board model (8×8 array or 32 playable squares) and piece encoding that make direction and king logic simple.
  • Move generation with a DFS for multi-jumps, the forced-capture rule applied across all pieces, and promotion.
  • move implemented as "is this path in legal_moves()", so rules live in one place.
  • Win detection by no pieces or no legal moves.
  • Tests for forced captures, double jumps, promotion, kings moving backward and illegal moves.

Follow-ups

  • Turn it into an online service: game creation, joining, an API for moves, and storing games.
  • Two players submit moves at the same moment or a client retries: how do you keep turns authoritative and moves idempotent?
  • Add undo or a move history that can replay a game.
  • Add a simple computer opponent with minimax.

Where it's asked

What it tests

object-oriented design · game · simulation

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding