Ejemplo n.º 1
0
        private void Mutate(List <DungeonOp> input)
        {
            var mutationOp = random.Next(100);

            if (mutationOp < 50) // add a random op
            {
                var op    = DungeonOp.CreateRandom();
                var index = random.Next(input.Count);
                input.Insert(index, op);
            }
            else if (mutationOp >= 33 && mutationOp < 66) // swap two elements
            {
                var firstIndex  = random.Next(input.Count);
                var secondIndex = random.Next(input.Count);
                // Swap. Don't care if they're the same
                var temp = input[firstIndex];
                input[firstIndex]  = input[secondIndex];
                input[secondIndex] = temp;
            }
            else // remove random element
            {
                if (input.Count > MINIMUM_SOLUTION_SIZE)
                {
                    var index = random.Next(input.Count);
                    input.RemoveAt(index);
                }
            }
        }
Ejemplo n.º 2
0
        // Not part of the engine because it doesn't know if we want a tree, list, etc.
        private List <DungeonOp> CreateRandomDungeonOpList()
        {
            var length   = random.Next(40, 50);
            var toReturn = new List <DungeonOp>();

            while (toReturn.Count < length)
            {
                var newOp = DungeonOp.CreateRandom();
                toReturn.Add(newOp);
            }
            return(toReturn);
        }