public void PostOrder(BTNode node) { if (node.getYesNode() != null) { PostOrder(node.getYesNode()); } if (node.getNoNode() != null) { PostOrder(node.getNoNode()); } if (node.getMessage() != null) { Console.WriteLine(node.getMessage()); } }
public void EvaluationFunction(BTNode node) { if (node.getYesNode() != null) { EvaluationFunction(node.getYesNode()); } if (node.getNoNode() != null) { EvaluationFunction(node.getNoNode()); } if (node.getYesNode() == null && node.getNoNode() == null) { node.value = (int)node.getMessage().LongCount(); Console.WriteLine(node.getMessage() + ": " + node.value + ": " + node.IsLeafNode(node)); } }
static void ReturnPostorder(BTNode rootNode) { if (rootNode.getYesNode() != null) { ReturnPostorder(rootNode.getYesNode()); } if (rootNode.getNoNode() != null) { ReturnPostorder(rootNode.getNoNode()); } Console.WriteLine(rootNode.getMessage()); }
public int ABPruning(BTNode concerningNode, bool isMax, int alpha = int.MinValue, int beta = int.MaxValue) { Console.WriteLine(string.Format("Now checking node {0}", concerningNode.getMessage())); if (!concerningNode.isQuestion()) { return(concerningNode.Evaluation()); } if (isMax) { int best = int.MinValue; for (int i = 0; i < 2; i++) { int value = ABPruning(i == 0 ? concerningNode.getYesNode() : concerningNode.getNoNode(), false, alpha, beta); best = Math.Max(best, value); alpha = Math.Max(alpha, best); if (beta <= alpha) { break; } } return(best); } else { int best = int.MaxValue; for (int i = 0; i < 2; i++) { int value = ABPruning(i == 0 ? concerningNode.getYesNode() : concerningNode.getNoNode(), true, alpha, beta); best = Math.Min(best, value); beta = Math.Min(beta, best); if (beta <= alpha) { break; } } return(best); } }
public void PrintOrder(BTNode concerningNode, Order order, string currentStreak = "") { switch (order) { case Order.PreOrder: Console.WriteLine(string.Format("CurrentStreak: {0}, Message: {1}", currentStreak, concerningNode.getMessage())); //Printing the message if (concerningNode.getYesNode() != null) { PrintOrder(concerningNode.getYesNode(), order, currentStreak + "Y"); } if (concerningNode.getNoNode() != null) { PrintOrder(concerningNode.getNoNode(), order, currentStreak + "N"); } break; case Order.InOrder: if (concerningNode.getYesNode() != null) { PrintOrder(concerningNode.getYesNode(), order, currentStreak + "Y"); } Console.WriteLine(string.Format("CurrentStreak: {0}, Message: {1}", currentStreak, concerningNode.getMessage())); //Printing the message if (concerningNode.getNoNode() != null) { PrintOrder(concerningNode.getNoNode(), order, currentStreak + "N"); } break; case Order.PostOrder: if (concerningNode.getYesNode() != null) { PrintOrder(concerningNode.getYesNode(), order, currentStreak + "Y"); } if (concerningNode.getNoNode() != null) { PrintOrder(concerningNode.getNoNode(), order, currentStreak + "N"); } Console.WriteLine(string.Format("CurrentStreak: {0}, Message: {1}", currentStreak, concerningNode.getMessage())); //Printing the message break; } }