예제 #1
0
        private void ShuffleUnits(INumber newNumber, IEnumerable<int> positionsToShuffle, IList<int> lockedPositions, Random random)
        {
            foreach (var positionToShuffle in positionsToShuffle)
            {
                var contextLockedPositions = new List<int>();

                contextLockedPositions.AddRange(lockedPositions);
                contextLockedPositions.Add(positionToShuffle);

                var firstPositionToShuffle = positionToShuffle;
                var secondPositionToShuffle = this.GetRandomPosition(newNumber, contextLockedPositions, random, lockPosition: false);

                var firstValueToShuffle = newNumber.GetUnitValue(firstPositionToShuffle);
                var secondValueToShuffle = newNumber.GetUnitValue(secondPositionToShuffle);

                newNumber.EditUnit(firstPositionToShuffle, secondValueToShuffle);
                newNumber.EditUnit(secondPositionToShuffle, firstValueToShuffle);
            }
        }
예제 #2
0
        private void ReplaceUnits(INumber newNumber, int unitsToReplace, IList<int> lockedPositions, IList<int> usedValues, Random random)
        {
            var exceededUnits = (unitsToReplace + lockedPositions.Count + this.unitsToInclude.Count()) - newNumber.Units.Count();

            if (exceededUnits > 0)
            {
                unitsToReplace = unitsToReplace - exceededUnits;
            }

            for (var i = 0; i < unitsToReplace; i++)
            {
                var positionToReplace = this.GetRandomPosition(newNumber, lockedPositions, random);
                var randomNumberUnitValue = this.GetRandomNumberUnitValue(newNumber, usedValues, random);

                usedValues.Add(newNumber.GetUnitValue(positionToReplace));

                newNumber.EditUnit(positionToReplace, randomNumberUnitValue);
            }
        }