/// <summary> /// Initializes a new instance of the <see cref="AnyBall.Rule.CS_RuleSet"/> class. /// </summary> /// <param name="g_rule">the rule to initialize with.</param> public CS_RuleSet(CS_Rule g_rule) { myRules = new List <CS_Rule> (); myRules.Add(g_rule); myRuleInfo = g_rule.GetInfo(); }
/// <summary> /// Adds a new rule. /// </summary> public void AddRule() { // create new rule int t_num = Random.Range(0, myRulePrefabs.Length); CS_Rule t_rule = Instantiate(myRulePrefabs [t_num], this.transform).GetComponent <CS_Rule> (); t_rule.gameObject.name = myRulePrefabs [t_num].name; // a list of rule set that can add the rule List <CS_RuleSet> t_combineList = new List <CS_RuleSet> (); for (int i = 0; i < myAllRules.Count; i++) { for (int j = 0; j < myAllRules [i].mySequence.Count; j++) { if (myAllRules [i].mySequence [j].CheckCombine(t_rule)) { t_combineList.Add(myAllRules [i].mySequence [j]); } } } // if the rule can be combined if (t_combineList.Count > 0 && Random.Range(0f, 1f) > 0.2f) { // pick a random rule set from the list and add the rule into the rule set t_combineList [Random.Range(0, t_combineList.Count)].AddRule(t_rule); t_combineList.Clear(); return; } t_combineList.Clear(); // create a new rule set with the rule CS_RuleSet t_ruleSet = new CS_RuleSet(t_rule); // a list of rule sequence that can add the rule set List <CS_RuleSequence> t_sequenceList = new List <CS_RuleSequence> (); for (int i = 0; i < myAllRules.Count; i++) { if (myAllRules [i].CheckSequence(t_ruleSet)) { t_sequenceList.Add(myAllRules [i]); } } // if the rule set can be part of the sequence if (t_sequenceList.Count > 0 && Random.Range(0f, 1f) > 0.3f) { // pick a random rule sequence from the list and add the rule set into the sequence t_sequenceList [Random.Range(0, t_combineList.Count)].AddRuleSet(t_ruleSet); t_sequenceList.Clear(); return; } t_sequenceList.Clear(); // if didn't combine/put into sequence, add a new sequence with the rule set CS_RuleSequence t_ruleSequence = new CS_RuleSequence(t_ruleSet); myAllRules.Add(t_ruleSequence); }
public bool CheckGoal(CS_Rule g_rule, int g_index) { foreach (CS_Rule f_rule in myRules) { if (g_rule == f_rule) { continue; } if (f_rule.GetIsOn(g_index) == false) { return(false); } } return(true); }
/// <summary> /// Adds the rule to rule set. /// </summary> /// <returns><c>true</c>, if rule was added, <c>false</c> otherwise.</returns> /// <param name="g_rule">rule you want to add.</param> public bool AddRule(CS_Rule g_rule) { if (CheckCombine(g_rule) == false) { return(false); } myRules.Add(g_rule); SetInfo(g_rule.GetInfo()); //update the extendable in the sequence //fix : if hat + football + footbal, the 2nd football should be added to the sequence myRuleSequence.UpdateExtendable(); return(true); }
public bool CheckCombine(CS_Rule g_rule) { //cannot combine the same rule foreach (CS_Rule f_rule in myRules) { if (f_rule.gameObject.name == g_rule.gameObject.name) { return(false); } } if (myRuleInfo.myScoreType == ScoreType.Keeping || g_rule.GetInfo().myScoreType == ScoreType.Keeping) { return(false); } if (myRuleInfo.myScoreType == ScoreType.Trigger && g_rule.GetInfo().myScoreType == ScoreType.Trigger) { return(false); } return(true); }
public void AddRule(CS_Rule g_rule) { myRules.Add(g_rule); }