public void RunPartialGames() { int move = 0; bool validation = true; TryAgain: Console.WriteLine("Choose game table"); while (validation) { try { move = Convert.ToInt32(Console.ReadLine()); validation = !TableInputValidator(MyGame, move); } catch // validating correct input { Console.WriteLine("Incorrect input, Only numbers from 1 to 9"); Console.WriteLine("Press enter your input again"); validation = true; } } while (!WinnerStateChecker.CheckState(MyGame.MyPlayer) && !WinnerStateChecker.CheckState(MyGame.MyEngine)) { int ComputerMove; bool tableValidation = true; while (tableValidation) { NextTable = UltimateGame[move - 1].RunGame(); if (UltimateGame[NextTable - 1].Winned) // Checking if somebody won the table before and handle choosing //table until we start again with new table move { Console.WriteLine("Table closed, computer will choose another one"); // -------------- choosing next table logic move = EngineManager.ComputerChooseTable(MyGame); Console.WriteLine($"Choosed table: {move}"); WinnerStateChecker.DisplayMovesOfPartialGame(move, UltimateGame); ComputerMove = CalculateMove(MyGame, UltimateGame[move - 1].GetEngine(), UltimateGame[move - 1].GetPlayer()); Console.WriteLine($"Calculated Move: {ComputerMove}"); UltimateGame[NextTable - 1].AddToEnginemove(ComputerMove); NextTable = ComputerMove; if (WinnerStateChecker.CheckState(UltimateGame[NextTable - 1].GetEngine())) // Checking if computer won last table, if so handling logic. { Console.WriteLine($"Computer Won table {NextTable}"); WinnerStateChecker.DisplayMovesOfPartialGame(NextTable, UltimateGame); MyGame.MyEngine.Moves.Add(NextTable); if (Game9x9Checker(MyGame.MyEngine)) { Console.WriteLine("Computer WON 9x9 Game"); MyGame.Over = true; break; } UltimateGame[NextTable - 1].ChangeWinnedState(); goto TryAgain; } move = ComputerMove; tableValidation = true; } else { tableValidation = false; } if (WinnerStateChecker.CheckState(UltimateGame[move - 1].GetPlayer()) && tableValidation != true) // Checking if player won, if so handling choosing next table logic { // -------------- choosing next table logic Console.WriteLine($"Player won table: {move}"); WinnerStateChecker.DisplayMovesOfPartialGame(move, UltimateGame); MyGame.MyPlayer.Moves.Add(move); if (Game9x9Checker(MyGame.MyPlayer)) { Console.WriteLine("Player WON 9x9 Game"); MyGame.Over = true; break; } UltimateGame[move - 1].ChangeWinnedState(); move = EngineManager.ComputerChooseTable(MyGame); Console.WriteLine($"Choosed table :{move}"); WinnerStateChecker.DisplayMovesOfPartialGame(move, UltimateGame); ComputerMove = CalculateMove(MyGame, UltimateGame[move - 1].GetEngine(), UltimateGame[move - 1].GetPlayer()); Console.WriteLine($"Calculated Move: {ComputerMove} "); UltimateGame[move - 1].AddToEnginemove(ComputerMove); if (WinnerStateChecker.CheckState(UltimateGame[move - 1].GetEngine())) { Console.WriteLine($"Computer Won table {move}"); WinnerStateChecker.DisplayMovesOfPartialGame(move, UltimateGame); MyGame.MyEngine.Moves.Add(move); if (Game9x9Checker(MyGame.MyEngine)) { Console.WriteLine("Computer WON 9x9 Game"); MyGame.Over = true; break; } UltimateGame[move - 1].ChangeWinnedState(); goto TryAgain; } move = ComputerMove; tableValidation = true; } else { tableValidation = false; } } ComputerMove = CalculateMove(MyGame, UltimateGame[NextTable - 1].GetEngine(), UltimateGame[NextTable - 1].GetPlayer()); WinnerStateChecker.DisplayMovesOfPartialGame(NextTable, UltimateGame); Console.WriteLine($"Calculated Move: {ComputerMove} "); UltimateGame[NextTable - 1].AddToEnginemove(ComputerMove); if (WinnerStateChecker.CheckState(UltimateGame[NextTable - 1].GetEngine())) { Console.WriteLine($"Computer Won table: {NextTable}"); WinnerStateChecker.DisplayMovesOfPartialGame(NextTable, UltimateGame); MyGame.MyEngine.Moves.Add(NextTable); if (Game9x9Checker(MyGame.MyEngine)) { Console.WriteLine("Engine wins 9x9 Game"); MyGame.Over = true; break; } UltimateGame[NextTable - 1].ChangeWinnedState(); goto TryAgain; } move = ComputerMove; } }
private string Play() { switch (MyGame.MyPlayer.Moves.Count) { case 1: MyGame.MyEngine.Moves.Add(BlockingStrategy.FirstMove(MyGame.MyPlayer)); return($" Computer First move is: {MyGame.MyEngine.Moves[0]} "); case 2: if (EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves).Count > 0) { MyGame.MyEngine.Moves.Add(BlockingStrategy.WithAllCombinationsCalculateBlock(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves)); return($" Computer Second move is: {MyGame.MyEngine.Moves[1]} "); } MyGame.MyEngine.Moves.Add(WiningStrategy.CalculateWiningMove(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves)); return($" Computer Second move is: {MyGame.MyEngine.Moves[1]} "); case 3: if (WinnerStateChecker.CheckState(MyGame.MyPlayer)) { return("YOU WIN!"); } if (EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves).Count > 0 && EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyPlayer.Moves, MyGame.MyEngine.Moves).Count < 1) { MyGame.MyEngine.Moves.Add(BlockingStrategy.WithAllCombinationsCalculateBlock(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves)); if (WinnerStateChecker.CheckState(MyGame.MyEngine)) { return($" Computer Third move is: {MyGame.MyEngine.Moves[2]}, Haha, You loose"); } return($" Computer Third move is: {MyGame.MyEngine.Moves[2]} "); } MyGame.MyEngine.Moves.Add(WiningStrategy.CalculateWiningMove(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves)); if (WinnerStateChecker.CheckState(MyGame.MyEngine)) { return($" Computer Third move is: {MyGame.MyEngine.Moves[2]}, oh Haha, You loose"); } return($" Computer Third move is: {MyGame.MyEngine.Moves[2]} "); case 4: if (WinnerStateChecker.CheckState(MyGame.MyPlayer)) { return("YOU WIN!"); } if (EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves).Count > 0 && EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyPlayer.Moves, MyGame.MyEngine.Moves).Count < 1) { MyGame.MyEngine.Moves.Add(BlockingStrategy.WithAllCombinationsCalculateBlock(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves)); if (WinnerStateChecker.CheckState(MyGame.MyEngine)) { return($" Computer Fourth move is: {MyGame.MyEngine.Moves[3]}, Haha, You loose"); } return($" Computer Fourth move is: {MyGame.MyEngine.Moves[3]} "); } MyGame.MyEngine.Moves.Add(WiningStrategy.CalculateWiningMove(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves)); if (WinnerStateChecker.CheckState(MyGame.MyEngine)) { return($" Computer Fourth move is: {MyGame.MyEngine.Moves[3]}, Haha, You loose"); } return($" Computer Fourth move is: {MyGame.MyEngine.Moves[3]} "); case 5: if (WinnerStateChecker.CheckState(MyGame.MyPlayer)) { return("YOU WIN!"); } if (EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves).Count > 0 && EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyPlayer.Moves, MyGame.MyEngine.Moves).Count < 1) { MyGame.MyEngine.Moves.Add(BlockingStrategy.WithAllCombinationsCalculateBlock(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves)); if (WinnerStateChecker.CheckState(MyGame.MyEngine)) { return($" Computer Fifth move is: {MyGame.MyEngine.Moves[4]}, Haha, You loose"); } return($" Computer Fifth move is: {MyGame.MyEngine.Moves[4]} "); } MyGame.MyEngine.Moves.Add(WiningStrategy.CalculateWiningMove(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves)); if (WinnerStateChecker.CheckState(MyGame.MyEngine)) { return($" Computer Fifth move is: {MyGame.MyEngine.Moves[4]}, Haha, You loose"); } return($" Computer Fifth move is: {MyGame.MyEngine.Moves[4]} "); default: return("Inesperated Error"); } }
static bool Game9x9Checker(IPlayer player) { return(WinnerStateChecker.CheckState(player)); }