public void Turn() { var board = new Board(_boardSize); var currentInfoAboutFields = board.GetCurrentInfoAboutFields(); string step; if (_gameWithAI && _currentPlayer == "o") { var computer = new AI(); step = computer.Move(_boardSize, _fieldsToWin); } else { step = ConsoleReadHelper.GetSymbolField(_currentPlayer, "Type next step: "); } var index = currentInfoAboutFields.FirstOrDefault(x => x.SymbolField == step); _tab[index.IndexOne, index.IndexTwo] = _currentPlayer; //mark symbol on board index.FieldIsEmpty = false; index.Mark = _currentPlayer; var ifWinner = CheckSomeoneWin(); var ifDraw = CheckIsItDraw(); if (ifWinner) { Console.Clear(); board.DisplayBoard(_tab);//display board Console.WriteLine($"\n\n\t\tWinner is player: {_currentPlayer.ToUpper()}".ToUpper() + $"\n\n\n\n -----type one key on keyboard, to get back to main menu------"); Console.ReadKey(); _gameFinished = true; return; } if (ifDraw) { board.DisplayBoard(_tab);//display board Console.WriteLine($"THERE IS NO WINNER... IT'S DRAW " + $"\n\n\n\n -----tap any key on keyboard, to get back to main menu------"); Console.ReadKey(); _gameFinished = true; return; } if (_currentPlayer == "x") { _currentPlayer = "o"; } else { _currentPlayer = "x"; } }
static void Main(string[] args) { board.Draw(); while (true) { ReadCommand(Console.ReadLine()); ai.Move(); } }
static void Main(string[] args) { Player P1 = new Player("P1"); //Board board = new Board(); AI P2 = new AI(); string line; int inp; while (true) { Console.Write("Enter the positin you want to play (0-8): "); line = Console.ReadLine(); // Read string from console if (!int.TryParse(line, out inp)) // Try to parse the string as an integer { Console.WriteLine("Not an integer!"); } else if (P2.rootNode.board.CheckValid(inp)) { if (P2.rootNode.board.SetMove(inp)) { int condition = P2.rootNode.board.CheckCondition(); if (condition != 0) { P2.rootNode.board.Print(); Console.WriteLine(" Game ended with condition {0}", condition); break; } } //TODO Why should the board not be given as input? inp = P2.Move(); if (P2.rootNode.board.SetMove(inp)) { P2.rootNode.board.Print(); int condition = P2.rootNode.board.CheckCondition(); if (condition != 0) { //P2.rootNode.board.Print(); if (condition > 0) { Console.WriteLine(" Game ended with Player {0} win", condition); } else { Console.WriteLine(" Game ended with draw"); } break; } } } } Console.ReadLine(); }