static void Main(string[] args) { // Maximum depth the algorithm should search to int maxDepth = 4; // Board attributes for its size int boardRows = 8, boardCols = 8; // Default empty square value - BE SURE ITS THE SAME HERE AND IN BOARD CLASS int emptySquare = 7; // Containers for the miniMax return values List<int> miniMaxValues = new List<int>(); // Container to store and pass on only the move returned by miniMax List<int> chosenMove = new List<int>(); // Initial values for blackPoint and whitePoints int blackPoints = 0, whitePoints = 0; // String to say who won the game string winner = "None"; #region Create Start // Create rows int[][] startState = new int[boardRows][]; // Create cols for (int i = 0; i < boardRows; ++i) startState[i] = new int[boardCols]; // fill in the board with start state for (int r = 0; r < boardRows; ++r) { for (int c = 0; c < boardCols; ++c) { if (r == 3 && c == 3) startState[r][c] = 1; else if (r == 3 && c == 4) startState[r][c] = 0; else if (r == 4 && c == 3) startState[r][c] = 0; else if (r == 4 && c == 4) startState[r][c] = 1; else startState[r][c] = emptySquare; } } #endregion Board board = new Board(startState, 1); board.DisplayBoard(); #region MiniMax Driver Section while (true) { // Player 1 (Black) Moves first miniMaxValues = MiniMax(board, 1, 1, maxDepth, 0); //miniMaxValues = MiniMaxMove(board, 1, 1, maxDepth, 0); //miniMaxValues = Unpredictable(board, 1); //miniMaxValues = Greedy(board, 1); //miniMaxValues = Human(board, 1); if (((miniMaxValues[1] == -1 || miniMaxValues[2] == -1 || miniMaxValues[3] == -1 || miniMaxValues[4] == -1) && board.IsGameOver(0)) || //other player cannot move also (board.Evaluate(1) == 0) || (board.Evaluate(0) == 0)// one player or the other have 0 point ) { blackPoints = board.Evaluate(1); whitePoints = board.Evaluate(0); break; } else if(miniMaxValues[1] != -1 && miniMaxValues[2] != -1 && miniMaxValues[3] != -1 && miniMaxValues[4] != -1) { // New move coordinates bool skip = true; chosenMove.Clear(); foreach (int val in miniMaxValues) { if (skip) { skip = false; continue; } chosenMove.Add(val); } board = board.MakeMove(chosenMove, 1); board.DisplayBoard(); } // Player 2 (White) Moves second //miniMaxValues = MiniMax(board, 0, 0, maxDepth, 0); //miniMaxValues = MiniMaxMove(board, 0, 0, maxDepth, 0); //miniMaxValues = Unpredictable(board, 0); miniMaxValues = Greedy(board, 0); //miniMaxValues = Human(board, 0); if (((miniMaxValues[1] == -1 || miniMaxValues[2] == -1 || miniMaxValues[3] == -1 || miniMaxValues[4] == -1) && board.IsGameOver(1)) || //other player cannot move also (board.Evaluate(1) == 0) || (board.Evaluate(0) == 0)// one player or the other have 0 point ) { blackPoints = board.Evaluate(1); whitePoints = board.Evaluate(0); break; } else if (miniMaxValues[1] != -1 && miniMaxValues[2] != -1 && miniMaxValues[3] != -1 && miniMaxValues[4] != -1) { // New move coordinates bool skip = true; chosenMove.Clear(); foreach (int val in miniMaxValues) { if (skip) { skip = false; continue; } chosenMove.Add(val); } board = board.MakeMove(chosenMove, 0); board.DisplayBoard(); } } #endregion // End game output if (blackPoints > whitePoints) winner = "Black Wins!"; else if (whitePoints > blackPoints) winner = "White Wins!"; else winner = "It's a Draw!"; Console.WriteLine("Game Over!"); Console.WriteLine("Black: " + blackPoints + " White: " + whitePoints); Console.WriteLine(winner); #region System("pause") Equivalent Console.WriteLine(); Console.Write("Press Enter To Exit"); Console.ReadLine(); #endregion }