当前位置: 首页>>代码示例>>C#>>正文


C# IAgent.IsMultiAgent方法代码示例

本文整理汇总了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;
        }
开发者ID:andrewanderson,项目名称:Web-Critters,代码行数:20,代码来源:GridSimulation.cs

示例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};
        }
开发者ID:andrewanderson,项目名称:Web-Critters,代码行数:31,代码来源:GridSimulation.cs


注:本文中的IAgent.IsMultiAgent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。