Program.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.Diagnostics;
  2. using FourInARow;
  3. using MinMaxAB;
  4. internal class Program
  5. {
  6. const int depth = 9;
  7. const bool maxPlayer = false;
  8. const int alpha = int.MinValue;
  9. const int beta = int.MaxValue;
  10. private static void Main()
  11. {
  12. var board = new GameBoard(new(7, 6));
  13. var minmax = new MinMaxABFourInARowBoard();
  14. while (true)
  15. {
  16. AiMove(board, minmax);
  17. HumanMove(board, minmax);
  18. Console.Clear();
  19. }
  20. }
  21. private static void AiMove(GameBoard board, MinMaxABFourInARowBoard minmax)
  22. {
  23. //Console.WriteLine(board);
  24. Console.WriteLine("Thinking...");
  25. var sw = new Stopwatch();
  26. sw.Start();
  27. var move = minmax.GetBestMove(board, Player.Computer, depth);
  28. sw.Stop();
  29. Console.WriteLine($"Decision made in {sw.Elapsed}");
  30. //Console.Clear();
  31. board.PlaceCoin(Player.Computer, move);
  32. Console.WriteLine($"AI Moves {move + 1}");
  33. //Console.WriteLine(board);
  34. if (board.GetWinner() == Player.Computer)
  35. {
  36. Console.WriteLine("AI Wins");
  37. Environment.Exit(0);
  38. }
  39. if (!board.HasEmptyColumns())
  40. {
  41. Console.WriteLine("TIE");
  42. Environment.Exit(0);
  43. }
  44. }
  45. private static void HumanMove(GameBoard board, MinMaxABFourInARowBoard minmax)
  46. {
  47. Console.WriteLine(board);
  48. Console.Write("Your move: ");
  49. board.PlaceCoin(Player.Player, int.Parse(Console.ReadLine()!) - 1);
  50. if (board.GetWinner() == Player.Player)
  51. {
  52. Console.WriteLine("Human Wins");
  53. Environment.Exit(0);
  54. }
  55. if (!board.HasEmptyColumns())
  56. {
  57. Console.WriteLine("TIE");
  58. Environment.Exit(0);
  59. }
  60. }
  61. }