Most modern Tic-Tac-Toe AIs use the . Because Tic-Tac-Toe is a "solved game," an AI using Minimax can evaluate every possible future move to ensure it never loses.
# 3. Minimizing Player (Human) else: best_score = +infinity for each empty spot on board: make_move(HUMAN) score = minimax(board, depth + 1, true) undo_move() best_score = min(score, best_score) return best_score iohorizontictactoeaix
return maxEval; else let minEval = Infinity; for (let move of getEmptyCells(board)) board[move.row][move.col] = 'X'; let eval = minimax(board, depth + 1, true); board[move.row][move.col] = ''; minEval = Math.min(minEval, eval); Most modern Tic-Tac-Toe AIs use the
Whether you’re a student, hobbyist, or teacher, implementing this game gives you a tangible artifact to share online — and maybe even dominate the .io leaderboards if you add networking later. depth + 1