1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System.Diagnostics;
- using Connect4;
- using MinMaxAB;
- const int depth = 9;
- var board = new GameBoard(new(7, 6));
- while (true)
- {
- AiMove(board);
- HumanMove(board);
- }
- static void AiMove(GameBoard board)
- {
- Console.WriteLine("Thinking...");
- var sw = new Stopwatch();
- sw.Start();
- var move = Connect4Minimax.GetBestMove(board, depth);
- sw.Stop();
- Console.WriteLine($"Decision made in {sw.Elapsed}");
- board.PlaceCoin(Player.Computer, move);
- Console.WriteLine($"AI Moves {move + 1}");
- if (board.GetWinner() == Player.Computer)
- {
- Console.Clear();
- Console.WriteLine(board);
- Console.WriteLine("AI Wins");
- Environment.Exit(0);
- }
- if (!board.HasEmptyColumns())
- {
- Console.Clear();
- Console.WriteLine(board);
- Console.WriteLine("TIE");
- Environment.Exit(0);
- }
- }
- static void HumanMove(GameBoard board)
- {
- Console.WriteLine(board);
- Console.Write("Your move: ");
- GC.Collect(2, GCCollectionMode.Aggressive);
- GC.WaitForFullGCComplete();
- board.PlaceCoin(Player.Human, int.Parse(Console.ReadLine()!) - 1);
- Console.Clear();
- if (board.GetWinner() == Player.Human)
- {
- Console.WriteLine("Human Wins");
- Environment.Exit(0);
- }
- if (!board.HasEmptyColumns())
- {
- Console.WriteLine("TIE");
- Environment.Exit(0);
- }
- }
|