public object Compile(HeuristicNode heuristic, List <Game> forward_gameStates) { this.forward_gameStates = forward_gameStates; List <object> parameters = new List <object>(); for (int i = 0; i < heuristic.children.Length; i++) { if (heuristic.children[i] != null) { parameters.Add(this.Compile(heuristic.children[i], forward_gameStates)); } } return(this.MapStringToFunction(heuristic.name, parameters)); }
public static void parseStringToTree(string input, HeuristicNode node) { int indexOfFirstOpenParenthesis = input.IndexOf('('); int individual_length = indexOfFirstOpenParenthesis; if (indexOfFirstOpenParenthesis > -1) { node.name = input.Substring(0, individual_length); int indexOfLastCloseParenthesis = input.LastIndexOf(')'); int substring_length = indexOfLastCloseParenthesis - indexOfFirstOpenParenthesis - 1; string substring = input.Substring(indexOfFirstOpenParenthesis + 1, substring_length); string[] temp = getParameters(substring); int i = 0; foreach (var word in temp) { if (word != "") { node.children[i] = new HeuristicNode(); parseStringToTree(word, node.children[i]); i++; } } } else { node.name = input; } }
public static void Main(string[] args) { HeuristicNode ht = new HeuristicNode(); string toParse = "IfThenElse(Function3(ARG1, ARG2), 'none', IfThenElse(Function2(ARG1, 14, ARG2), 'summon', IfThenElse(Function1(ARG0), 'play', 'pass')))"; HeuristicsCode hp = new HeuristicsCode(); parseStringToTree(toParse, ht); Console.WriteLine(ht.ToString()); Console.WriteLine(hp.Compile(ht, 9, 1, 1)); }