//write out all the rules,with colour depending on whether they are right or wrong public string GenerateFeedback(List <FRule> right, List <FRule> wrong, FireWallData inner) { string feedback = ""; List <FRule> allInnerRules = new List <FRule> (); foreach (var rule in inner.rawinputRules) { allInnerRules.Add(rule); } foreach (var rule in inner.rawoutputRules) { allInnerRules.Add(rule); } print("innerRules" + allInnerRules.Count); foreach (var rule in allInnerRules) { if (CompareAgainstAList(rule, right)) { feedback += "<color=green><size=12>" + rule.FeedbackString() + "</size></color>\n"; } else if (CompareAgainstAList(rule, wrong)) { feedback += "<color=red><size=12>" + rule.FeedbackString() + "</size></color>\n"; } else { feedback += "<color=yellow><size=12>" + rule.FeedbackString() + "</size></color>\n"; } } //allInnerRules.Clear (); return(feedback); }
//give it right and bad, if right comes before bad its all good public bool LevelCheckInput(FRule goodRule, FRule badRule, FireWallData check) { Stack <FRule> inputCopy = new Stack <FRule>(); for (int i = 0; i < check.inputRules.Count; i++) { FRule x = check.rawinputRules[i]; // print (x.ToString ()); inputCopy.Push(x); } //sanity check,dont run without any rules if (inputCopy.Count == 0) { return(false); } //flags for hitting good/bad bool good = false; bool bad = false; //if we are dealing with input //check all input rules for (int i = 0; i <= inputCopy.Count; i++) { //print ("i# in " + i.ToString()); //make a local variable to avoid retyping FRule rule = inputCopy.Peek(); //look at the rule at the top of stack,if it matches the good rule if (Check(rule, goodRule)) { //if it matches, set good to true good = true; } //check the bad rule if (Check(rule, badRule)) { //if it matches, set good to true bad = true; } //MASTER CHECK IMPORTANT if (good && !bad) { return(true); } if (bad && !good) { return(false); } //pop the now checked rule inputCopy.Pop(); } // if we have not returned true by this point, the good rule doesnt exist return(false); }
public void OnClickFirewall(GameObject panelLeft, GameObject panelRight, FireWall firewall) { this.data = data; currentLeftPanel.SetActive(false); currentLeftPanel = panelLeft; currentLeftPanel.SetActive(true); currentRightPanel.SetActive(false); currentRightPanel = panelRight; currentRightPanel.SetActive(true); //set the right firewall for rules management ToggleControl currentToggleControl = currentRightPanel.GetComponentInChildren <ToggleControl> (); currentToggleControl.firewall = firewall; }
public string GenerateFeedback(List <FRule> rightin, List <FRule> wrongin, List <FRule> rightout, List <FRule> wrongout, FireWallData inner, FireWallData outer) { string feedback = ""; //make a new list and copy values in List <FRule> allInnerRules = new List <FRule> (); foreach (var rule in inner.rawinputRules) { allInnerRules.Add(rule); } foreach (var rule in inner.rawoutputRules) { allInnerRules.Add(rule); } List <FRule> allOuterRules = new List <FRule> (); foreach (var rule in outer.rawinputRules) { allOuterRules.Add(rule); } foreach (var rule in outer.rawoutputRules) { allOuterRules.Add(rule); } feedback += "Inner\n"; foreach (var rule in allInnerRules) { if (CompareAgainstAList(rule, rightin)) { feedback += "<color=green><size=12>" + rule.FeedbackString() + "</size></color>\n"; } else if (CompareAgainstAList(rule, wrongin)) { feedback += "<color=red><size=12>" + rule.FeedbackString() + "</size></color>\n"; } else { feedback += "<color=yellow><size=12>" + rule.FeedbackString() + "</size></color>\n"; } } feedback += "\nOuter\n"; foreach (var rule in allOuterRules) { if (CompareAgainstAList(rule, rightout)) { feedback += "<color=green><size=12>" + rule.FeedbackString() + "</size></color>\n"; } else if (CompareAgainstAList(rule, wrongout)) { feedback += "<color=red><size=12>" + rule.FeedbackString() + "</size></color>\n"; } else { feedback += "<color=yellow><size=12>" + rule.FeedbackString() + "</size></color>\n"; } } return(feedback); }
//give it right and bad, if right comes before bad its all good public bool LevelCheckOutput(FRule goodRule, FRule badRule, FireWallData check) { //flags for hitting good/bad bool good = false; bool bad = false; //set up new queues/copies that we can pop from Stack <FRule> outputCopy = new Stack <FRule>(); //check if there are actually any rules for (int i = 0; i < check.outputRules.Count; i++) { FRule x = check.rawoutputRules[i]; //print ("push "+x.ToString ()); outputCopy.Push(x); } if (outputCopy.Count == 0) { return(false); } //if we are dealing with input //check all input rules //print("cyclecount " + outputCopy.Count.ToString()); for (int i = 0; i <= outputCopy.Count; i++) { //make a local variable to avoid retyping FRule rule = outputCopy.Peek(); //print ("currently checked rule "+rule.ToString ()); //print ("currentlt against rule "+goodRule.ToString ()); //look at the rule at the top of stack,if it matches the good rule if (Check(rule, goodRule)) { //if it matches, set good to true good = true; } //check the bad rule if (Check(rule, badRule)) { //if it matches, set good to true bad = true; } //MASTER CHECK IMPORTANT if (good && !bad) { return(true); } if (bad && !good) { return(false); } //pop the now checked rule outputCopy.Pop(); } // if we have not returned true by this point, the good rule doesnt exist // print("not exist in"); return(false); }