本文整理汇总了C#中IAgentData类的典型用法代码示例。如果您正苦于以下问题:C# IAgentData类的具体用法?C# IAgentData怎么用?C# IAgentData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IAgentData类属于命名空间,在下文中一共展示了IAgentData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decide
/// <summary>
/// Depending on the group policy of its parent, the floating point return value indicates whether the decider will be activated.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <param name="decisionData"> Decision data to use in activate method. </param>
/// <returns> Floating point value used to decide if the decider will be activated. </returns>
public override float Decide(IAgentData agentData, ref IDecisionData decisionData)
{
// Create blackboard.
Blackboard blackboard = new Blackboard();
// Add parent blackboards.
if (this.Blackboard != null)
{
blackboard.Parents.Add(this.Blackboard);
}
blackboard.Parents.Add(agentData.Blackboard);
// Setup blackboard.
Blackboard previousBlackboard = agentData.Blackboard;
agentData.Blackboard = blackboard;
// Deactivate child.
IDecisionData childDecisionData = null;
float decisionValue = this.DecideChild(agentData, ref childDecisionData);
// Tear down.
agentData.Blackboard = previousBlackboard;
// Create decision data.
if (decisionValue > 0.0f)
{
decisionData = new DecisionData { Blackboard = blackboard, ChildDecisionData = childDecisionData };
}
return decisionValue;
}
示例2: Update
/// <summary>
/// Per frame update.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <returns> Execution status after this update. </returns>
public override ExecutionStatus Update(IAgentData agentData)
{
Data data = agentData.GetTaskData<Data>();
if (data.Status == ExecutionStatus.Running)
{
// Update.
data.Status = this.UpdateChild(agentData);
}
else
{
// Restart if still possible.
IDecisionData decisionData = null;
++agentData.CurrentDeciderLevel;
float decisionValue = this.Task.Decide(agentData, ref decisionData);
--agentData.CurrentDeciderLevel;
if (decisionValue > 0.0f)
{
data.Status = this.ActivateChild(agentData, decisionData);
if (data.Status == ExecutionStatus.Running)
{
data.Status = this.UpdateChild(agentData);
}
}
else
{
data.Status = ExecutionStatus.Failed;
}
}
return ExecutionStatus.Running;
}
示例3: Deactivate
/// <summary>
/// Deactivation.
/// </summary>
/// <param name="agentData"> Agent data. </param>
public override void Deactivate(IAgentData agentData)
{
ITask task = this.GetTask(agentData);
if (task != null)
{
task.Deactivate(agentData);
}
}
示例4: Decide
/// <summary>
/// Decision function for a boolean condition.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <returns> Returns true if the condition is forfilled, else false. </returns>
protected override bool Decide(IAgentData agentData)
{
object attribute = null;
if (!agentData.Blackboard.TryGetValue(this.BlackboardAttributeKey, out attribute))
{
return false;
}
// Check that not null.
return attribute != null;
}
示例5: Deactivate
/// <summary>
/// Deactivation.
/// </summary>
/// <param name="agentData"> Agent data. </param>
public override void Deactivate(IAgentData agentData)
{
Data data = agentData.GetTaskData<Data>();
// Deactivate child if running.
if (data.Status == ExecutionStatus.Running)
{
this.DeactivateChild(agentData);
}
agentData.CurrentTaskData = null;
}
示例6: Update
/// <summary>
/// Per frame update.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <returns> Execution status after this update. </returns>
public override ExecutionStatus Update(IAgentData agentData)
{
// Get key of attribute to remove.
object key = this.GetBlackboardAttributeKey(agentData);
if (key != null)
{
// Remove attribute.
agentData.Blackboard.RemoveValue(key);
}
return ExecutionStatus.Success;
}
示例7: Activate
/// <summary>
/// Activation. This method is called when the task was chosen to be executed. It's called right before the first update of the task. The task can setup its specific task data in here and do initial actions.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <param name="decisionData"> Decision data to use in activate method. </param>
/// <returns> Execution status after activation. </returns>
public override ExecutionStatus Activate(IAgentData agentData, IDecisionData decisionData)
{
Data data = new Data();
data.Status = this.ActivateChild(agentData, decisionData);
if (data.Status == ExecutionStatus.Failed)
{
return ExecutionStatus.Failed;
}
agentData.CurrentTaskData = data;
return ExecutionStatus.Running;
}
示例8: Deactivate
/// <summary>
/// Deactivation.
/// </summary>
/// <param name="agentData"> Agent data. </param>
public override void Deactivate(IAgentData agentData)
{
Data data = agentData.GetTaskData<Data>();
// Setup blackboard.
Setup(agentData, data);
// Deactivate child.
this.DeactivateChild(agentData);
// Tear down.
TearDown(agentData, data);
}
示例9: Update
/// <summary>
/// Per frame update.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <returns> Execution status after this update. </returns>
public override ExecutionStatus Update(IAgentData agentData)
{
// Get value from blackboard.
object attribute = null;
if (!agentData.Blackboard.TryGetValue(this.SourceAttributeKey, out attribute))
{
return ExecutionStatus.Failed;
}
// Set value to target key.
agentData.Blackboard.SetValue(this.TargetAttributeKey, attribute);
return ExecutionStatus.Success;
}
示例10: Activate
/// <summary>
/// Activation. This method is called when the task was chosen to be executed. It's called right before the first update of the task. The task can setup its specific task data in here and do initial actions.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <param name="decisionData"> Decision data to use in activate method. </param>
/// <returns> Execution status after activation. </returns>
public override ExecutionStatus Activate(IAgentData agentData, IDecisionData decisionData)
{
Data data = new Data { Status = ExecutionStatus.Failed };
// Check if child wants to run.
float childDecisionValue = this.DecideChild(agentData, ref decisionData);
if (childDecisionValue > 0.0f)
{
data.Status = this.ActivateChild(agentData, decisionData);
}
agentData.CurrentTaskData = data;
return ExecutionStatus.Running;
}
示例11: Activate
/// <summary>
/// Activation. This method is called when the task was chosen to be executed. It's called right before the first update of the task. The task can setup its specific task data in here and do initial actions.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <param name="decisionData"> Decision data to use in activate method. </param>
/// <returns> Execution status after activation. </returns>
public override ExecutionStatus Activate(IAgentData agentData, IDecisionData decisionData)
{
DecisionData taskDecisionData = (DecisionData)decisionData;
// Create child blackboard.
Data data = new Data { Blackboard = taskDecisionData.Blackboard, PreviousBlackboard = agentData.Blackboard };
agentData.CurrentTaskData = data;
// Setup blackboard.
Setup(agentData, data);
// Activate child.
ExecutionStatus result = this.ActivateChild(agentData, taskDecisionData.ChildDecisionData);
if (result != ExecutionStatus.Running)
{
// Tear down.
TearDown(agentData, data);
}
return result;
}
示例12: Activate
/// <summary>
/// Activation. This method is called when the task was chosen to be executed. It's called right before the first update of the task. The task can setup its specific task data in here and do initial actions.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <param name="decisionData"> Decision data to use in activate method. </param>
/// <returns> Execution status after activation. </returns>
public override ExecutionStatus Activate(IAgentData agentData, IDecisionData decisionData)
{
Blackboard blackboard = agentData.Blackboard;
if (blackboard.Parents == null)
{
return ExecutionStatus.Failed;
}
// Find attribute on parent blackboard.
foreach (Blackboard parent in blackboard.Parents)
{
object attribute = null;
if (parent.TryGetValue(this.AttributeKey, out attribute))
{
// Set attribute on blackboard.
blackboard.SetValue(this.AttributeKey, attribute);
return ExecutionStatus.Success;
}
}
return ExecutionStatus.Failed;
}
示例13: Update
/// <summary>
/// Per frame update.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <returns> Execution status after this update. </returns>
public override ExecutionStatus Update(IAgentData agentData)
{
Data data = agentData.CurrentTaskData as Data;
if (data.Status == ExecutionStatus.Running)
{
data.Status = this.UpdateChild(agentData);
}
else
{
// Restart if still possible.
IDecisionData decisionData = null;
float decisionValue = this.Task.Decide(agentData, ref decisionData);
if (decisionValue > 0.0f)
{
data.Status = this.ActivateChild(agentData, decisionData);
if (data.Status == ExecutionStatus.Running)
{
data.Status = this.UpdateChild(agentData);
}
}
}
return data.Status == ExecutionStatus.Failed ? ExecutionStatus.Failed : ExecutionStatus.Running;
}
示例14: UpdateAgent
private bool UpdateAgent(GridRegion destination, IAgentData cAgentData)
{
// Try local first
if (cAgentData is AgentData)
{
if (m_localBackend.UpdateAgent(destination, (AgentData) cAgentData))
return true;
}
else if (cAgentData is AgentPosition)
{
if (m_localBackend.UpdateAgent(destination, (AgentPosition) cAgentData))
return true;
}
// else do the remote thing
if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
{
// Eventually, we want to use a caps url instead of the agentID
string uri = MakeUri(destination, true) + cAgentData.AgentID + "/";
if (m_blackListedRegions.ContainsKey(uri))
{
//Check against time
if (m_blackListedRegions[uri] > 3 &&
Util.EnvironmentTickCountSubtract(m_blackListedRegions[uri]) > 0)
{
MainConsole.Instance.Warn("[SimServiceConnector]: Blacklisted region " + destination.RegionName + " requested");
//Still blacklisted
return false;
}
}
try
{
OSDMap args = cAgentData.Pack();
args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
args["destination_name"] = OSD.FromString(destination.RegionName);
args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
OSDMap result = WebUtils.PutToService(uri, args, true, true, false);
if (!result["Success"].AsBoolean())
{
if (m_blackListedRegions.ContainsKey(uri))
{
if (m_blackListedRegions[uri] == 3)
{
//add it to the blacklist as the request completely failed 3 times
m_blackListedRegions[uri] = Util.EnvironmentTickCount() + 60*1000; //60 seconds
}
else if (m_blackListedRegions[uri] == 0)
m_blackListedRegions[uri]++;
}
else
m_blackListedRegions[uri] = 0;
return result["Success"].AsBoolean();
}
//Clear out the blacklist if it went through
m_blackListedRegions.Remove(uri);
OSDMap innerResult = (OSDMap) result["_Result"];
return innerResult["Updated"].AsBoolean();
}
catch (Exception e)
{
MainConsole.Instance.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e);
}
return false;
}
return false;
}
示例15: GetBlackboardAttributeKey
/// <summary>
/// Should return the key of the blackboard attribute to remove.
/// </summary>
/// <param name="agentData"> Agent data. </param>
/// <returns> Key of the blackboard attribute to remove. </returns>
protected abstract object GetBlackboardAttributeKey(IAgentData agentData);