Skip to main content
🎮 Game Logic

What you're building

The critical piece of any Connect Four implementation: detecting a win after each disc drop.

You will implement:

  • dropDisc(board, col, player) — drops player's disc (1 or 2) into the lowest empty row of col. Returns true if the drop succeeded, false if the column is full.
  • checkWin(board, row, col) — returns true if the disc just placed at (row, col) completes a run of four for that player in any direction (horizontal, vertical, either diagonal).

The board is a 6-row × 7-col 2-D array, initialised to zeros.

Requirements

  • dropDisc must place the disc in the lowest empty row (gravity).
  • checkWin checks exactly four directions: horizontal (0°), vertical (90°), and both diagonals (45°, 135°).
  • A win is any run of 4 consecutive identical non-zero values passing through (row, col).
  • Do not mutate test fixtures outside of the functions — use board[r][c] assignment only inside dropDisc.

Stretch goals

  • Detect a draw (board full, no winner).
  • Implement a minimax evaluator for the full 7-column game.

What this proves

Direction-vector scanning — a pattern that recurs in Boggle, word-search, and any "n-in-a-row" problem — plus boundary-safe grid traversal.

âš¡ 40 XP
solution.jsRuns in your browser
Loading editor…
Tests4 to pass
dropDisc places in lowest empty row
dropDisc returns false when column full
checkWin detects horizontal four
checkWin detects vertical four

Run your code to check these.