/// <summary> /// 根据每个后续的概率随机选择一个后续,并返回后续的索引 /// </summary> /// <returns>随机选择的后续索引值</returns> private int RandomlySelectResultList() { int result = 0; int countOfSuccessor = m_listSuccessor.Count; float[] probabilityArray = new float[countOfSuccessor]; for (int i = 0; i < countOfSuccessor; i++) { if (i == 0) { probabilityArray[0] = m_listSuccessor[0].Probability.Value; } else { probabilityArray[i] = m_listSuccessor[i].Probability.Value + probabilityArray[i - 1]; } } //根据随机产生的数字判断使用哪个结果链表 double randomNum = RandomNumer.Double() * probabilityArray[countOfSuccessor - 1]; for (int i = 0; i < countOfSuccessor; i++) { if (randomNum < probabilityArray[i]) { result = i; break; } } return(result); }
public double InsectSim(double insectIntake) { /* * 当该叶片的最低被啃食比例小于细胞纹理的最低被啃食比例时 * 说明该比例无或者存在一定的问题 * 因此将该比例设置为细胞纹理的最低被啃食比例 */ if (LimitRatio < CelluarTex.LimitRatio) { LimitRatio = CelluarTex.LimitRatio; /* * 调整最低被啃食比例 * 减少重复感 */ LimitRatio += (0.8 - LimitRatio) * RandomNumer.Double(); } /* * 叶片当前最大可被进食量 * 用于计算当前实际被进食量 */ double maxInsectIntake = (InsectedRatio - LimitRatio) * LeafArea_Uninsected; /* * 若该叶片已经老去 * 则不会被并病虫啃食 * 若还未老去,则根据叶片最大被进食量计算实际被进食量 * 当最大可被进食量不大于0时,说明无可被进食部分,因此实际被进食量为0 * 当最大可被进食量大于当前病虫进食量,则说明该叶片满足病虫进食需求,因此实际进食量为病虫进食量 * 当最大可被进食量大于0并且小于当前病虫进食量,则说明该叶片有被进食,但无法满足病虫进食需求 * 因此最大可被进食量均被进食,故实际进食量为最大可被进食量 */ double actualInsectIntake = Age >= MaizeParams.LEAF_MAX_DEVELOPMENT_AGE ? 0 : maxInsectIntake <= 0 ? 0 : maxInsectIntake >= insectIntake ? insectIntake : maxInsectIntake; //根据实际进食量计算叶片的面积 LeafArea -= actualInsectIntake; int threshold; //设置纹理 GameObjectOperation.SetTexture(Belong, GetWormholeTex(actualInsectIntake, out threshold)); //设置阈值 GameObjectOperation.SetThreshold(Belong, threshold); //返回剩余的病虫进食量 return(insectIntake - actualInsectIntake); }