本文整理汇总了C#中IAgent.IsMultiAgent方法的典型用法代码示例。如果您正苦于以下问题:C# IAgent.IsMultiAgent方法的具体用法?C# IAgent.IsMultiAgent怎么用?C# IAgent.IsMultiAgent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAgent
的用法示例。
在下文中一共展示了IAgent.IsMultiAgent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoAsexualReproduction
protected override IAgent DoAsexualReproduction(IAgent parent, ILocation location)
{
if (parent == null) throw new ArgumentNullException("parent");
if (location == null) throw new ArgumentNullException("location");
if (parent.IsMultiAgent())
{
return DoMulticellularAsexualReproduction(parent, location);
}
// Reproduce assuming this agent has a single cell
var childCell = asexualReproductionInteraction.Interact(parent.Cells[0], null);
var childAgent = new GridAgent();
childAgent.Cells.Add(childCell);
this.RegisterBirth(childAgent, new BirthEvent(location, CurrentGeneration, asexualReproductionInteraction.GetType(), parent.Species));
this.AddEventToAgent(parent, new ReproductionEvent(location, CurrentGeneration, asexualReproductionInteraction.GetType(), null, childAgent.Species));
return childAgent;
}
示例2: DoSexualReproduction
private IList<IAgent> DoSexualReproduction(IAgent parent1, IAgent parent2, IInteraction<ICell, ICell, IList<ICell>> interaction, ILocation location)
{
if (parent1 == null) throw new ArgumentNullException("parent1");
if (parent1.Cells.Count == 0) throw new ArgumentException("Agent must have at least one cell", "parent1");
if (parent2 == null) throw new ArgumentNullException("parent2");
if (parent2.Cells.Count == 0) throw new ArgumentException("Agent must have at least one cell", "parent2");
if (interaction == null) throw new ArgumentNullException("interaction");
if (location == null) throw new ArgumentNullException("location");
if (parent1.IsMultiAgent() || parent2.IsMultiAgent())
{
return DoMulticellularSexualReproduction(parent1, parent2, interaction, location);
}
// Reproduce assuming both agents have a single cell
var childCells = interaction.Interact(parent1.Cells[0], parent2.Cells[0]);
var child1 = new GridAgent();
child1.Cells.Add(childCells[0]);
this.RegisterBirth(child1, new BirthEvent(location, CurrentGeneration, interaction.GetType(), parent1.Species, parent2.Species));
var child2 = new GridAgent();
child2.Cells.Add(childCells[1]);
this.RegisterBirth(child2, new BirthEvent(location, CurrentGeneration, interaction.GetType(), parent1.Species, parent2.Species));
// Events
this.AddEventToAgent(parent1, new ReproductionEvent(location, CurrentGeneration, interaction.GetType(), parent2.Species, child1.Species, child2.Species));
this.AddEventToAgent(parent2, new ReproductionEvent(location, CurrentGeneration, interaction.GetType(), parent1.Species, child1.Species, child2.Species));
return new[] {child1, child2};
}