DevSupporter
DevSupporter

Welcome back

Please enter your details to sign in to your account

Forgot password?
Sign in

Connect Four

MinimaxAlpha-Beta PruningGame TreeAdvanced

Coming Soon

Game play area will be implemented here

Click a column to drop your disc (๐Ÿ”ด Red). Connect four in a row (horizontal, vertical, or diagonal) to win. AI plays as ๐ŸŸก Yellow. On Hard mode, AI looks 6 moves ahead.

Minimax with Alpha-Beta Pruning explores the game tree up to depth 6. Heuristic evaluation scores 4-cell windows. Center column and move ordering improve pruning.

function minimax(board, depth, alpha, beta, isMax) {
  validCols.sort((a,b) => Math.abs(a-3) - Math.abs(b-3));
  for (const col of validCols) {
    dropDisc(newBoard, col, 2);
    const result = minimax(newBoard, depth-1, alpha, beta, false);
    if (result.score > best.score) best = { score: result.score, col };
    alpha = Math.max(alpha, best.score);
    if (beta <= alpha) break;
  }
  return best;
}

2026 ยฉ DevSupporter - Playground for Developers by DevSupporter