예제 #1
0
        /// <summary>
        /// Try to get a slot based on utility of all available slots (relative to the current satisfaction level of the needs of the agent).
        /// </summary>
        /// <returns>Success if a slot has been distributed to the agent.</returns>
        public override Action.Result Run()
        {
            if (agent.Blackboard.currentState == Blackboard.AgentState.ExitNEEDSIMBehaviors)
            {
                //Actions should be interrupted until the agent state is dealt with.
                return(Result.Failure);
            }

            //If previously a slot was allocated, try to consume it.
            if (agent.Blackboard.currentState == Blackboard.AgentState.WaitingForSlot)
            {
                if (agent.AcceptSlot())
                {
                    return(Result.Success);
                }
                else
                {
                    agent.Blackboard.currentState = Blackboard.AgentState.PonderingNextAction;
                }
            }

            //Try to allocate a slot to the agent that has the highest value regardless of state.
            Simulation.Bidding.Result biddingResult = Simulation.Bidding.ValueOrientedBid(agent.AffordanceTreeNode);

            //Simulation.Bidding.BidParentGrandparentRoot(agent.AffordanceTreeNode);
            if (biddingResult == Simulation.Bidding.Result.Success)
            {
                agent.Blackboard.currentState = Blackboard.AgentState.WaitingForSlot;
                return(Result.Running);
            }

            agent.Blackboard.currentState = Blackboard.AgentState.None;
            return(Result.Failure);
        }
예제 #2
0
        /// <summary>
        /// Get a goal from the simulation, and try to get a slot where the goal can be satisfied.
        /// </summary>
        /// <returns>Success if a slot has been distributed to the agent.</returns>
        public override Action.Result Run()
        {
            if (agent.Blackboard.currentState == Blackboard.AgentState.ExitNEEDSIMBehaviors)
            {
                //Actions should be interrupted until the agent state is dealt with.
                return(Result.Failure);
            }

            //Get the goal to satisfy the need with the lowest satisfaction. You can replace the goals for your specific game.
            agent.AffordanceTreeNode.Goal = agent.AffordanceTreeNode.SatisfactionLevels.GoalToSatisfyLowestNeed();

            //If previously a slot was allocated to this agent, try to consume/use it.
            if (agent.Blackboard.currentState == Blackboard.AgentState.WaitingForSlot)
            {
                if (agent.AcceptSlot())
                {
                    return(Result.Success);
                }
                else
                {
                    agent.Blackboard.currentState = Blackboard.AgentState.PonderingNextAction;
                }
            }

            //Try to allocate a slot to the agent that will satisfy the goal.
            // Simple solution
            Simulation.Bidding.Result biddingResult = Simulation.Bidding.GoalOrientedBid(agent.AffordanceTreeNode);
            // You can instead use callbacks to adjust evaluataion of the slots to your game.
            // This is demonstrated in the class DecideClosestGoal
            // Simulation.Bidding.Result biddingResult = Simulation.Bidding.GoalOrientedBid(agent.AffordanceTreeNode, preferShortestDistanceByAir);

            if (biddingResult == Simulation.Bidding.Result.Success)
            {
                agent.Blackboard.currentState = Blackboard.AgentState.WaitingForSlot;
                return(Result.Running);
            }

            agent.Blackboard.currentState = Blackboard.AgentState.None;
            return(Result.Failure);
        }