Game AI + Search Algorithms + Python
A chess application with human and AI modes. The engine uses minimax search to evaluate positions and alpha-beta pruning to play smarter, faster. Supports en passant, pawn promotion, move undo, and an AI hint system. Built entirely in Python with CMU Graphics.
01 The Application
02 Technical Approach
The AI opponent uses the minimax algorithm to search through possible future board states. It builds a game tree where each node is a board position, alternating between the maximizing player (white, trying to increase the score) and the minimizing player (black, trying to decrease it). The search evaluates every branch to a configurable depth and picks the move that leads to the best guaranteed outcome.
Alpha-beta pruning makes this practical. It tracks two values as it searches: alpha (the best score white can guarantee so far) and beta (the best score black can guarantee). When beta drops below alpha, the remaining branches in that subtree cannot produce a better result, so the algorithm skips them entirely. This cuts the effective search space dramatically, allowing the AI to think deeper in the same time.
The board evaluation function scores positions using piece material values (pawn = 1, knight = 3, bishop = 3.25, rook = 5, queen = 9), positional bonuses for advanced pawns, mobility scoring based on legal move count, pawn structure analysis, and king safety heuristics.
def minimax(app, board, depth, isMaximizingPlayer, lastMove, alpha=float('-inf'), beta=float('inf')): if depth == 0 or checkGameOver(app): return evaluateBoard(board), None bestMove = None if isMaximizingPlayer: maxEval = float('-inf') for move in generateAllMoves( board, 'white', lastMove): newBoard, newLastMove = \ applyMove(board, move) evaluation, _ = minimax( app, newBoard, depth - 1, False, newLastMove, alpha, beta) if evaluation > maxEval: maxEval = evaluation bestMove = move alpha = max(alpha, evaluation) if beta <= alpha: break # prune return maxEval, bestMove else: minEval = float('inf') for move in generateAllMoves( board, 'black', lastMove): newBoard, newLastMove = \ applyMove(board, move) evaluation, _ = minimax( app, newBoard, depth - 1, True, newLastMove, alpha, beta) if evaluation < minEval: minEval = evaluation bestMove = move beta = min(beta, evaluation) if beta <= alpha: break # prune return minEval, bestMove
03 Skills Used
04 Video Demo
Full walkthrough covering both game modes, AI difficulty selection, legal move highlighting, en passant, pawn promotion, the undo system, and AI hints.
05 Controls
Toggle the en passant rule on or off mid-game
Toggle pawn promotion on or off
Take back the last move
AI suggests the optimal move (3 per game)
Click any piece to see valid destinations highlighted
Switch between Human vs. Human and Human vs. AI