├── README.md └── Tic-Tac-Toe /README.md: -------------------------------------------------------------------------------- 1 | # Tic-Tac-Toe-Game-with-AI 2 | Create a web-based Tic-Tac-Toe game where the user plays against an AI powered by the minimax algorithm. 3 | -------------------------------------------------------------------------------- /Tic-Tac-Toe: -------------------------------------------------------------------------------- 1 | const board = ['', '', '', '', '', '', '', '', '']; 2 | const player = 'X'; 3 | const ai = 'O'; 4 | 5 | function printBoard() { 6 | console.log(`${board[0]} | ${board[1]} | ${board[2]}`); 7 | console.log('--+---+--'); 8 | console.log(`${board[3]} | ${board[4]} | ${board[5]}`); 9 | console.log('--+---+--'); 10 | console.log(`${board[6]} | ${board[7]} | ${board[8]}`); 11 | } 12 | 13 | function aiMove() { 14 | const emptyCells = board.map((cell, idx) => (cell === '' ? idx : null)).filter(x => x !== null); 15 | board[emptyCells[Math.floor(Math.random() * emptyCells.length)]] = ai; 16 | } 17 | 18 | printBoard(); 19 | --------------------------------------------------------------------------------