Beispiel #1
0
        private MazePoint GetNextPoint(List <MazePoint> activeCells, List <GrowingTreeStrategy> strategies)
        {
            var item     = _randomValueGenerator.GetNext(0, strategies.Count - 1);
            var strategy = strategies[item];
            var middle   = activeCells.Count / 2;

            switch (strategy)
            {
            case GrowingTreeStrategy.Oldest:
                return(activeCells.First());

            case GrowingTreeStrategy.Newest:
                return(activeCells.Last());

            case GrowingTreeStrategy.Middle:
                return(activeCells[middle]);

            case GrowingTreeStrategy.Random:
                var randomIndex = _randomValueGenerator.GetNext(0, activeCells.Count - 1);
                return(activeCells[randomIndex]);

            case GrowingTreeStrategy.RandomOldest:
                var randomFirstIndex = _randomValueGenerator.GetNext(middle, activeCells.Count - 1);
                return(activeCells[randomFirstIndex]);

            case GrowingTreeStrategy.RandomNewest:
                var randomLastIndex = _randomValueGenerator.GetNext(0, middle);
                return(activeCells[randomLastIndex]);

            default:
                throw new ArgumentException("Unsupported Cell Selection Strategy");
            }
        }
        public void SingleValue_GenerateValueBetween1and10_NumberFoundBetween1and10()
        {
            //Act
            var value = _random.GetNext(1, 10);

            //Assert
            Assert.That(value, Is.InRange(1, 10));
        }
Beispiel #3
0
 public void Shuffle <T>(List <T> array)
 {
     for (int i = 0; i < array.Count; i++)
     {
         int j   = _randomValueGenerator.GetNext(i, array.Count);
         T   tmp = array[j];
         array[j] = array[i];
         array[i] = tmp;
     }
 }
        public MazePoint RandomPoint(MazeSize size, PickType type)
        {
            var x = _randomValueGenerator.GetNext(0, size.X - 1);
            var y = _randomValueGenerator.GetNext(0, size.Y - 1);
            var z = _randomValueGenerator.GetNext(0, size.Z - 1);

            if (type == PickType.RandomEdge)
            {
                switch ((RandomEdgeOptions)_randomValueGenerator.GetNext(1, 6))
                {
                case RandomEdgeOptions.MinX:
                    x = 0;
                    break;

                case RandomEdgeOptions.MaxX:
                    x = size.X - 1;
                    break;

                case RandomEdgeOptions.MinY:
                    y = 0;
                    break;

                case RandomEdgeOptions.MaxY:
                    y = size.Y - 1;
                    break;

                case RandomEdgeOptions.MinZ:
                    z = 0;
                    break;

                case RandomEdgeOptions.MaxZ:
                    z = size.Z - 1;
                    break;
                }
            }
            return(_mazePointFactory.MakePoint(x, y, z));
        }