Example #1
0
        static void RandomPoolTest()
        {
            RandomWeightPool <Item> rp = new RandomWeightPool <Item>();

            rp.SetItemWeight(new Item()
            {
                Name = "5"
            }, 5);
            rp.SetItemWeight(new Item()
            {
                Name = "10"
            }, 10);
            Dictionary <Item, int> counter = new Dictionary <Item, int>();

            for (int i = 0; i < 100000; i++)
            {
                var it = rp.GetItem();
                if (!counter.ContainsKey(it))
                {
                    counter.Add(it, 0);
                }
                counter[it]++;
            }

            foreach (var p in counter)
            {
                Console.WriteLine(p.Key.Name + "__" + p.Value);
            }
            Console.ReadKey();
        }
Example #2
0
        public static RandomWeightPool <string> Config2IdPool(string data)
        {
            RandomWeightPool <string> pool = new RandomWeightPool <string>();

            if (string.IsNullOrEmpty(data))
            {
                return(pool);
            }
            string[] srr = data.Split(SplitChar);
            foreach (var s in srr)
            {
                string[] pair = s.Split('|');
                if (pair.Length > 1)
                {
                    pool.SetItemWeight(pair[0], float.Parse(pair[1]));
                }
            }
            return(pool);
        }