using System; namespace TicTacToe { class TicTacToeGame : TicTacToe_base { private bool playerTurn = true; // true for player, false for AI public override void Run() { Console.WriteLine("Welcome to Tic Tac Toe!"); while (true) { DrawBoard(); int pos; if (playerTurn) { Console.Write("Enter position (1-9): "); pos = Convert.ToInt32(Console.ReadLine()); } else { pos = FindNextPosByAI(); } if (!AddInputToBoard(pos, playerTurn ? "X" : "O")) { Console.WriteLine("Invalid input, try again!"); continue; } if (CheckWin(playerTurn ? "X" : "O")) { DrawBoard(); Console.WriteLine((playerTurn ? "Player" : "Computer") + " wins!"); break; } if (board.Count == 9) { DrawBoard(); Console.WriteLine("Tie game!"); break; } playerTurn = !playerTurn; } Console.WriteLine("Thanks for playing!"); } protected override bool CheckWin(string user) { foreach (int[] winList in WinLists) { if (board.ContainsKey(winList[0]) && board[winList[0]] == user && board.ContainsKey(winList[1]) && board[winList[1]] == user && board.ContainsKey(winList[2]) && board[winList[2]] == user) { return true; } } return false; } } }