public override void Process(T context, TimeSpan span) { _ = context ?? throw new ArgumentNullException(nameof(context)); indexer.Clear(); for (int i = 0; i < context.VirusData.Items.Span.Length; i++) { var item = context.VirusData.Items.Span[i]; if (item.IsInfected == InfectionData.Infected) { indexer.AddItem(context.Persons.Items.Span[i]); } } //try to infection context.VirusData.ForAllParallelWtihReference(context.Persons, (ref InfectionData data, ref PositionItem p) => { if (data.IsInfected == InfectionData.NotInfected) { int count = indexer.GetItemsCountInDistance(p.Position, InfectionRadius); if (count > 0 && Helper.RandomFloat(1) <= 1 - (Math.Pow((1 - InfectionRate), count))) { data.IsInfected = InfectionData.Infected; } else { data.IsInfected = InfectionData.NotInfected; } } }); }
public override void Process(T context, TimeSpan span) { infectedItems.Clear(); //refresh infected person indexer context.SIRInfo.ForAllWtihReference(context.Persons, (ref SIRData sir, ref PositionItem pos) => { if (sir.Status == SIRData.Infective) { infectedItems.AddItem(pos); } }); //try to be infected ProcessInfection(context, span); //update ground info ProcessGround(context, span); ProcessCure(context, span); }
public override void Init(T context) { POIList.AddRange(create(context)); POIIndex = new QuadTreeNode <Vector2>(new RectangleF(0, 0, context.Size.Width, context.Size.Height), (ref Vector2 x) => { return(x); }); create = null;//release creation function to reduce other object reference foreach (var item in POIList) { POIIndex.AddItem(item); } //init home position context.Persons.ForAllParallelWtihReference(context.POIData, (ref PositionItem pos, ref POIInfo poi) => { poi.POIStatus = POIStatusEnum.AtHome; poi.HomePosition = pos.Position; }); }