private void Start() { this.EnsureRequiredFieldsAreSetInEditor(); // Init AI var knowledgeProvider = new KnowledgeProvider(this); var goalSelector = new GoalSelector.Builder() .WithReevaluationPeriod(3.0f) .WithGoal( new Goal("BuildHouse", new List <IPrecondition> { new IsTrue(new SymbolId("HouseBuilt")) } ), () => town.House.IsBuilt ? -1 : 1 ) .WithGoal( new Goal("DestroyHouse", new List <IPrecondition> { new IsTrue(new SymbolId("HouseBuilt")) } ), () => town.House.IsBuilt ? 1 : -1 ) .WithGoal( new Goal("BuildHouse", new List <IPrecondition> { new IsTrue(new SymbolId("HouseBuilt")) } ), () => town.House.IsBuilt ? -1 : 1 ) .Build(); var actionFactory = GetActionFactory(); var planner = new ForwardPlanner(100, 200, learn, experienceWeight); var planExecutor = new PlanExecutor(actionFactory); agent = new Agent( new AgentConfiguration.Builder() .WithKnowledgeProvider(knowledgeProvider) .WithGoalSelector(goalSelector) .WithPlanner(planner) .WithPlanExecutor(planExecutor) .Build() ); navMeshAgent = GetComponent <NavMeshAgent>(); DebugUtils.Assert(navMeshAgent != null, "{0} requires {1} to be present", GetType(), typeof(NavMeshAgent)); // Init view toolAnimationTimer = new ResettableStopwatchExecutionTimer(true); // Init UI planExecutionStatePanel.PlanExecution = planExecutor.CurrentExecution; }
public GoalSelector(IDictionary <Goal, GoalEvaluator> evaluators, float reevaluationPeriod = DEFAULT_REEVALUATION_PERIOD) { this.evaluators = PreconditionUtils.EnsureNotNull(evaluators, "evaluators"); this.reevaluationPeriod = reevaluationPeriod; this.reevaluationTimer = new ResettableStopwatchExecutionTimer(false); this.ForceReevaluation(); }
private GoalSelector(IDictionary <Goal, GoalEvaluator> evaluators, float reevaluationPeriod = DefaultReevaluationPeriod) { this.evaluators = PreconditionUtils.EnsureNotNull(evaluators, "evaluators"); this.reevaluationPeriod = reevaluationPeriod; reevaluationTimer = new ResettableStopwatchExecutionTimer(false); ForceReevaluation(); }
void Start() { this.EnsureRequiredFieldsAreSetInEditor(); // Init AI var knowledgeProvider = new KnowledgeProvider(this); var goalSelector = new GoalSelector.Builder() .WithReevaluationPeriod(3.0f) .WithGoal( new Goal( "BuildHouse", new List <IPrecondition>() { new IsTrue(new SymbolId("HouseBuilt")) } ), () => town.House.IsBuilt ? -1 : 1 ) .Build(); var actionFactory = this.GetActionFactory(); var planner = new RegressivePlanner(20, 5); var planExecutor = new PlanExecutor(actionFactory); this.agent = new Agent( new AgentEnvironment.Builder() .WithKnowledgeProvider(knowledgeProvider) .WithGoalSelector(goalSelector) .WithPlanner(planner) .WithPlanExecutor(planExecutor) .Build() ); this.navMeshAgent = this.GetComponent <NavMeshAgent>(); DebugUtils.Assert(this.navMeshAgent != null, "{0} requires {1} to be present", this.GetType(), typeof(NavMeshAgent)); // Init view this.toolAnimationTimer = new ResettableExecutionTimer(true); // Init UI this.planExecutionStatePanel.PlanExecution = planExecutor.CurrentExecution; }
//Run test case and log results private static void SingleRun(string name, IPlanner planner, WorldState state, HashSet <PlanningAction> availableActions, Goal goal, IResettableTimer timer, bool resetExperience = false) { print($"-----------------{name}---------------------------"); if (resetExperience) { planner.ClearExperience(); } timer.Reset(false); var plan = planner.FormulatePlan(state, availableActions, goal); print( $"{planner.GetType()} has found a plan of length {plan.Length} and cost {plan.Cost} to satisfy \"{goal.Name}\" in {timer.ElapsedSeconds} seconds" ); // print(plan.ToString()); }