| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- namespace GFGGame
- {
- //两边扩散结构
- //初始化时从最大值,最小值之间随机一个值
- //每次取值从两边随机一边取值
- public struct BilateralDiffusionStruct
- {
- private readonly int minValue;
- private readonly int maxValue;
- public int leftPosition;
- public int rightPosition;
- public BilateralDiffusionStruct(int minValue, int maxValue)
- {
- this.minValue = minValue;
- this.maxValue = maxValue;
- var currenValue = RandomUtil.RandomInt(minValue, maxValue);
- if (currenValue == maxValue)
- {
- leftPosition = currenValue;
- rightPosition = currenValue;
- }
- else
- {
- leftPosition = currenValue;
- rightPosition = currenValue + 1;
- }
- }
- public BilateralDiffusionStruct(int minValue, int maxValue, int leftPosition, int rightPosition)
- {
- this.minValue = minValue;
- this.maxValue = maxValue;
- this.leftPosition = leftPosition;
- this.rightPosition = rightPosition;
- }
- public int NextValue()
- {
- int nextValue;
- if (leftPosition > minValue && rightPosition < maxValue)
- {
- nextValue = RandomUtil.RandomNext(2) == 0 ? leftPosition-- : rightPosition++;
- }
- else if (leftPosition <= minValue && rightPosition >= maxValue)
- {
- return -1;
- }
- else if (leftPosition < minValue)
- {
- nextValue = rightPosition++;
- }
- else
- {
- nextValue = leftPosition--;
- }
- return nextValue;
- }
- public bool IsFull()
- {
- return leftPosition < minValue && rightPosition > maxValue;
- }
- }
- }
|