//call this method to play a game public void PlayAIMatch() { //start a new instance to play the game PlayAI aiGame = new PlayAI(); //set winner to false for while loop bool winner = false; //find out what difficulty they want to play string difficultyLevel = "easy"; Console.WriteLine("Which difficulty would you like to play on?\n1 easy\n2 hard"); int chosenDifficulty = Convert.ToInt32(Console.ReadLine()); //set the difficulty if (chosenDifficulty == 1) { difficultyLevel = "easy"; } else if (chosenDifficulty == 2) { difficultyLevel = "hard"; } Console.WriteLine("\nYou chose to play on {0}", difficultyLevel); //print instructions Program.Instructions(); PrintBoard(); //main loop for the game, regardless of the difficulty chosen do { //if someone has won, winner becomes true. the program ends. //or, if the board if full and there are no more moves left, the game ends. if (Won() || BoardFull()) { winner = true; Console.WriteLine("The game is over."); } else { //x will be human if (turn == "x") { //get the humans next move and update the board UpdateBoardHuman(GetPlayersMove()); } //o will be AI else if (turn == "o") { if (difficultyLevel == "easy") { AIEasyMove(); } else if (difficultyLevel == "hard") { // DifficultAi(); DifficultAiMove(); //temperary } } } }while (winner == false); }
static void Main(string[] args) { while (chooseInput) { //choose to play a human or ai Console.WriteLine("Welcome to tic-tac-toe!"); Console.WriteLine("\nWould like you to play againts a Friend or AI? \nEnter: 1 (for Friend)\nEnter: 2 (for AI)"); try { int choice = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(); if (choice == 1) { Console.WriteLine("You chose to play against another player on the same computer"); PlayHuman humanGame = new PlayHuman(); humanGame.PlayAHuman(); chooseInput = false; } else if (choice == 2) { Console.WriteLine("You chose to play against the AI"); PlayAI aiGame = new PlayAI(); aiGame.PlayAIMatch(); chooseInput = false; } else { Console.WriteLine("Please Enter either a 1 or a 2\n"); } //when the game is over, ask if they want to play again if (chooseInput == false) { playAgain(); } } catch { Console.WriteLine("Please Enter either a 1 or a 2\n"); } } }