static void Main(string[] args) { Console.Title = "TicTacToe"; var players = new IPlayer[] { new HumanConsolePlayer(), new AlphaBetaMinimaxPlayer() }; int current = 0; var alternante = 0; Grid g = Grid.Empty; while (true) { g = players[current].MakeMove(g); current = (current + 1) % 2; if (g.IsFinished) { ConsoleGridRenderer.Render(g); if (!g.IsDraw) { Console.WriteLine("{0} win!", g.CurrentIsO ? "X" : "O"); } else { Console.WriteLine("Draw!"); } current = (++alternante % 2); g = Grid.Empty; } Console.WriteLine("\n"); } }
public Grid MakeMove(Grid g) { GridCells move; while (true) { ConsoleGridRenderer.Render(g); Console.WriteLine("\nEnter {0} move: ", g.CurrentIsO ? "O" : "X"); if (Enum.TryParse <GridCells>(Console.ReadLine().ToUpper(), out move) && g.CanMove(move)) { return(g.MakeMove(move)); } else { Console.WriteLine("Invalid Move!"); } } }