1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System.Diagnostics;
- using FourInARow;
- 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 MinMaxABFourInARowBoard();
- while (true)
- {
- AiMove(board, minmax);
- HumanMove(board, minmax);
- Console.Clear();
- }
- }
- private static void AiMove(GameBoard board, MinMaxABFourInARowBoard minmax)
- {
- //Console.WriteLine(board);
- Console.WriteLine("Thinking...");
- var sw = new Stopwatch();
- sw.Start();
- var move = minmax.GetBestMove(board, Player.Computer, depth);
- sw.Stop();
- Console.WriteLine($"Decision made in {sw.Elapsed}");
- //Console.Clear();
- board.PlaceCoin(Player.Computer, move);
- Console.WriteLine($"AI Moves {move + 1}");
- //Console.WriteLine(board);
- if (board.GetWinner() == Player.Computer)
- {
- Console.WriteLine("AI Wins");
- Environment.Exit(0);
- }
- if (!board.HasEmptyColumns())
- {
- Console.WriteLine("TIE");
- Environment.Exit(0);
- }
- }
- private static void HumanMove(GameBoard board, MinMaxABFourInARowBoard minmax)
- {
- Console.WriteLine(board);
- Console.Write("Your move: ");
- board.PlaceCoin(Player.Player, int.Parse(Console.ReadLine()!) - 1);
- if (board.GetWinner() == Player.Player)
- {
- Console.WriteLine("Human Wins");
- Environment.Exit(0);
- }
- if (!board.HasEmptyColumns())
- {
- Console.WriteLine("TIE");
- Environment.Exit(0);
- }
- }
- }
|