int Minmax(Board node, int depth, bool maximizingPlayer) { int bestValue = 0; if (depth == 0) { return(node.EvaluateBoard(this)); } if (maximizingPlayer) { bestValue = -int.MaxValue; foreach (Board child in node.GetChildren(this.character)) // This is when the computer wants to move { int tempV = Minmax(child, depth - 1, false); bestValue = Global.max(bestValue, tempV); } return(bestValue); } else { char ch; if (this.character == Global.X) { ch = Global.O; } else { ch = Global.X; } bestValue = int.MaxValue; foreach (Board child in node.GetChildren(ch)) // This is when the player wants to move { int tempV = Minmax(child, depth - 1, true); bestValue = Global.min(bestValue, tempV); } return(bestValue); } }