override public NextChoiceType Execute() { NextChoiceType nextChoice = new NextChoiceType(); nextChoice.NextMove = NextChoiceType.NextMoveType.UNKNOWN; return(nextChoice); }
// Called each ai's turn, runs all the rules and finds the best rule that matches and executes that rule which gives // the best move for that rule public NextChoiceType RunAI_Evalute(WorldData worldState) { RulePriortyType highestRulePriority = RulePriortyType.NONE; Rule highestMatchingRule = null; NextChoiceType bestMove = null; //Find Maching rules, keep track of the one with the highest priority foreach (var r in Rules) { if (r.Match(worldState) && r.rulePriority > highestRulePriority) { highestRulePriority = r.rulePriority; highestMatchingRule = r; } } //Execute the rule with the highest priority bestMove = highestMatchingRule.Execute(); return(bestMove); }
// Use this for initialization void Start() { //find the world data ( 1 copy exists globally ) worldState = GameObject.Find("WorldDataManager"); worldStateScript = worldState.GetComponent <WorldData>(); //Create the framework, it gets initialized in constructor //TODO ruleBasedAI = new RuleFrameWork(); ruleBasedAI = new RuleFrameWork(); //We don't have a next move yet as we are just starting nextMove = null; AmberColor = new Color(1.0f, 1.0f, 0); RedColor = new Color(1f, 0, 0); GreenColor = new Color(0, 1f, 0); GO_FORCE = 1.5f + Random.Range(0.0f, 1.0f); SLOW_DRAG = 0.2f + Random.Range(0.2f, 0.5f); initGo = false; }
// Update is called once per frame void Update() { nextMove = ruleBasedAI.RunAI_Evalute(worldStateScript); //Get our next move //run the evaluate every frame, NOTE: does not have to be every frame, //in a turn based game this would run on a button press //TODO nextMove = ruleBasedAI.RunAI_Evalute(worldStateScript); if (nextMove != null) { if (nextMove.NextMove == NextChoiceType.NextMoveType.STOP) { GetComponent <Renderer>().material.color = RedColor; } else if (nextMove.NextMove == NextChoiceType.NextMoveType.GO) { GetComponent <Renderer>().material.color = GreenColor; } else if (nextMove.NextMove == NextChoiceType.NextMoveType.SLOW_DOWN) { GetComponent <Renderer>().material.color = AmberColor; } } }