Exemplo n.º 1
0
    public static WeightedRandomCollection <T> CreateWeightedBag <T>(T[] values, float initalWeight, IRandomGenerator randomGenerator = null)
    {
        var result = new WeightedRandomCollection <T>(randomGenerator);

        foreach (var n in values)
        {
            result.Add(n, initalWeight);
        }

        return(result);
    }
Exemplo n.º 2
0
    //
    public WeightedRandomCollection <T> WeightedBag <T>(T[] values, float initalWeight)
    {
        var result = new WeightedRandomCollection <T>(this);

        foreach (var n in values)
        {
            result.Add(n, initalWeight);
        }

        return(result);
    }
Exemplo n.º 3
0
    public WeightedRandomCollection <T> WeightedBag <T>(T[] values, float[] initalWeights)
    {
        var result = new WeightedRandomCollection <T>(this);

        for (var n = 0; n < values.Length; ++n)
        {
            result.Add(values[n], initalWeights[n]);
        }

        return(result);
    }
Exemplo n.º 4
0
    //
    public static WeightedRandomCollection <T> CreateWeightedBag <T>(IEnumerable <T> values, IEnumerable <float> initalWeights, IRandomGenerator randomGenerator = null)
    {
        var result = new WeightedRandomCollection <T>(randomGenerator);

        using (var valueEnumerator = values.GetEnumerator())
            using (var weightEnumerator = initalWeights.GetEnumerator())
            {
                while (valueEnumerator.MoveNext() && weightEnumerator.MoveNext())
                {
                    result.Add(valueEnumerator.Current, weightEnumerator.Current);
                }
            }


        return(result);
    }
Exemplo n.º 5
0
        //Get a block that meets certain requirements.
        LevelBlock GetPossibleLevelBlock(LevelBlockRequirements requirements)
        {
            WeightedRandomCollection<LevelBlock> possibleLevelBlocks = new WeightedRandomCollection<LevelBlock>();

            //Check all level blocks and see which ones would meet the requirements.
            foreach (LevelBlock levelBlock in levelBlocks)
            {
                if (levelBlock.MeetsRequirements(requirements))
                    possibleLevelBlocks.Add(levelBlock, levelBlock.AppearancePreference);
            }

            //If we've not found anything, return null.
            if (possibleLevelBlocks.IsWriteOnly)
                return null;

            //Then return one.
            return possibleLevelBlocks.Get();
        }