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 (1or2) into the lowest empty row ofcol. Returnstrueif the drop succeeded,falseif the column is full.checkWin(board, row, col)— returnstrueif 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
dropDiscmust place the disc in the lowest empty row (gravity).checkWinchecks 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 insidedropDisc.
Stretch goals
- Detect a draw (board full, no winner).
- Implement a
minimaxevaluator 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.