|
@@ -1,79 +1,68 @@
|
|
|
-using System.Diagnostics;
|
|
|
+using System.Diagnostics;
|
|
|
using Connect4;
|
|
|
using MinMaxAB;
|
|
|
|
|
|
-internal class Program
|
|
|
-{
|
|
|
- const int depth = 9;
|
|
|
- const bool maxPlayer = false;
|
|
|
- const int alpha = int.MinValue;
|
|
|
- const int beta = int.MaxValue;
|
|
|
-
|
|
|
- private static void Main()
|
|
|
- {
|
|
|
- var board = new GameBoard(new(7, 6));
|
|
|
- var minmax = new Connect4Minimax();
|
|
|
- while (true)
|
|
|
- {
|
|
|
- AiMove(board, minmax);
|
|
|
-
|
|
|
- HumanMove(board, minmax);
|
|
|
- }
|
|
|
- }
|
|
|
+const int depth = 9;
|
|
|
|
|
|
- private static void AiMove(GameBoard board, Connect4Minimax minmax)
|
|
|
- {
|
|
|
- //Console.WriteLine(board);
|
|
|
- Console.WriteLine("Thinking...");
|
|
|
-
|
|
|
- var sw = new Stopwatch();
|
|
|
- sw.Start();
|
|
|
- var move = minmax.GetBestMove(board, depth);
|
|
|
- sw.Stop();
|
|
|
- Console.WriteLine($"Decision made in {sw.Elapsed}");
|
|
|
+var board = new GameBoard(new(7, 6));
|
|
|
+while (true)
|
|
|
+{
|
|
|
+ AiMove(board);
|
|
|
|
|
|
- //Console.Clear();
|
|
|
+ HumanMove(board);
|
|
|
+}
|
|
|
|
|
|
- board.PlaceCoin(Player.Computer, move);
|
|
|
+static void AiMove(GameBoard board)
|
|
|
+{
|
|
|
+ Console.WriteLine("Thinking...");
|
|
|
|
|
|
- Console.WriteLine($"AI Moves {move + 1}");
|
|
|
+ var sw = new Stopwatch();
|
|
|
+ sw.Start();
|
|
|
+ var move = Connect4Minimax.GetBestMove(board, depth);
|
|
|
+ sw.Stop();
|
|
|
+ Console.WriteLine($"Decision made in {sw.Elapsed}");
|
|
|
|
|
|
- //Console.WriteLine(board);
|
|
|
+ board.PlaceCoin(Player.Computer, move);
|
|
|
|
|
|
- if (board.GetWinner() == Player.Computer)
|
|
|
- {
|
|
|
- Console.WriteLine("AI Wins");
|
|
|
- Environment.Exit(0);
|
|
|
- }
|
|
|
+ Console.WriteLine($"AI Moves {move + 1}");
|
|
|
|
|
|
- if (!board.HasEmptyColumns())
|
|
|
- {
|
|
|
- Console.WriteLine("TIE");
|
|
|
- Environment.Exit(0);
|
|
|
- }
|
|
|
+ if (board.GetWinner() == Player.Computer)
|
|
|
+ {
|
|
|
+ Console.Clear();
|
|
|
+ Console.WriteLine(board);
|
|
|
+ Console.WriteLine("AI Wins");
|
|
|
+ Environment.Exit(0);
|
|
|
}
|
|
|
|
|
|
- private static void HumanMove(GameBoard board, Connect4Minimax minmax)
|
|
|
+ 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.Write("Your move: ");
|
|
|
+ GC.Collect(2, GCCollectionMode.Aggressive);
|
|
|
+ GC.WaitForFullGCComplete();
|
|
|
+ board.PlaceCoin(Player.Human, int.Parse(Console.ReadLine()!) - 1);
|
|
|
|
|
|
- Console.Clear();
|
|
|
+ Console.Clear();
|
|
|
|
|
|
- if (board.GetWinner() == Player.Human)
|
|
|
- {
|
|
|
- Console.WriteLine("Human Wins");
|
|
|
- Environment.Exit(0);
|
|
|
- }
|
|
|
+ if (board.GetWinner() == Player.Human)
|
|
|
+ {
|
|
|
+ Console.WriteLine("Human Wins");
|
|
|
+ Environment.Exit(0);
|
|
|
+ }
|
|
|
|
|
|
- if (!board.HasEmptyColumns())
|
|
|
- {
|
|
|
- Console.WriteLine("TIE");
|
|
|
- Environment.Exit(0);
|
|
|
- }
|
|
|
+ if (!board.HasEmptyColumns())
|
|
|
+ {
|
|
|
+ Console.WriteLine("TIE");
|
|
|
+ Environment.Exit(0);
|
|
|
}
|
|
|
}
|