Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int iterations = 1000000;

            Picker <MyEnum> picker = new Picker <MyEnum>();

            picker.AddItem(MyEnum.Item1, 25);
            picker.AddItem(MyEnum.Item2, 25);
            picker.AddItem(MyEnum.Item3, 25);
            picker.AddItem(MyEnum.Item4, 25);

            Console.WriteLine("Generating {0} values...", iterations);

            Stopwatch timer = Stopwatch.StartNew();

            for (int i = 0; i < iterations; i++)
            {
                picker.NextItem();
            }

            timer.Stop();

            Console.WriteLine("Time: {0}ms", timer.Elapsed.TotalMilliseconds);
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.Write("TestBot");

            var rounds = int.Parse(Console.ReadLine());
            var rand = new Random(rounds ^ Magic);

            picker = new Picker<Move>(rand);

            picker.AddItem(Move.Paper, 100d / 3d);
            picker.AddItem(Move.Rock, 100d / 3d);
            picker.AddItem(Move.Scissors, 100d / 3d);

            var patternEnumerator = CreatePattern(rounds, rand).GetEnumerator();

            while (true)
            {
                patternEnumerator.MoveNext();
                Console.Write((int)patternEnumerator.Current);

                int opponent;
                if (int.TryParse(Console.ReadLine(), out opponent))
                {

                }
                else
                    break;
            }
        }
Ejemplo n.º 3
0
        public void AddItem_BagIsFull_ThrowException()
        {
            Picker jo = new Picker(10);

            for (int i = 0; i != 11; i++)
            {
                jo.AddItem(new Chanterelle());
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.Write("SpanBot V0.1");

            var rounds = int.Parse(Console.ReadLine());

            picker = new Picker<Move>(new Random(rounds ^ Magic));

            picker.AddItem(Move.Paper, 100 / 3);
            picker.AddItem(Move.Rock, 100 / 3);
            picker.AddItem(Move.Scissors, 100 / 3);

            var opponentsMoves = new List<Move>();

            while (true)
            {
                var move = Move.None;
                if (opponentsMoves.Count < PatternFindLength + 1)
                {
                    move = picker.NextItem();
                    Console.WriteLine($"Randomly picked {move}");
                    //Console.Write((int)move);
                }
                else
                {
                    var matches = FindPatterns(opponentsMoves, opponentsMoves.Take(PatternFindLength).ToList(), 10, 0);
                    var afterBestMatch = opponentsMoves[matches.First().Item2];
                    move = afterBestMatch.WinningMove();
                    Console.WriteLine($"Pattern matched {move}");
                    //Console.Write((int)move);
                }

                int opponentOut;
                if (int.TryParse(Console.ReadLine(), out opponentOut))
                {
                    var opponent = (Move)opponentOut;
                    opponentsMoves.Add(opponent);
                    Console.WriteLine($"{move} against {opponent} -> {move.WouldWin(opponent)}");
                }
                else
                    break;
            }
        }
Ejemplo n.º 5
0
        public void Run()
        {
            var itemCount = int.MaxValue;

            var picker = new Picker <MyEnum>();

            picker.AddItem(MyEnum.Item1, 1);
            picker.AddItem(MyEnum.Item2, 2);
            picker.AddItem(MyEnum.Item3, 3);
            picker.AddItem(MyEnum.Item4, 4);

            Console.WriteLine($"Generating {itemCount:N0} values...");

            var timer = Stopwatch.StartNew();

            picker.NextItems(itemCount);

            timer.Stop();

            Console.WriteLine($"Time: {timer.Elapsed.TotalMilliseconds}ms");
        }
Ejemplo n.º 6
0
        public void Run()
        {
            var itemCount = 100000;

            var picker = new Picker <MyEnum>();

            picker.AddItem(MyEnum.Item1, 1);
            picker.AddItem(MyEnum.Item2, 2);
            picker.AddItem(MyEnum.Item3, 3);
            picker.AddItem(MyEnum.Item4, 4);

            var items = Enum.GetValues(typeof(MyEnum)).Cast <MyEnum>().ToDictionary(n => n, n => 0);

            Console.WriteLine($"Generating {itemCount:N0} values...");

            foreach (var item in picker.NextItems(itemCount))
            {
                items[item] += 1;
            }

            Console.WriteLine(string.Join("\n", items.Select(p => $"{p.Key}: {p.Value}, {(p.Value / (double)itemCount) * 100d}%")));
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            // create a new picker that returns MyEnums
            var picker = new Picker <MyEnum>();

            // add the four weighted enum values to it
            picker.AddItem(MyEnum.Item1, 1);
            picker.AddItem(MyEnum.Item2, 2);
            picker.AddItem(MyEnum.Item3, 3);
            picker.AddItem(MyEnum.Item4, 4);
            // the weights total to 10, meaning that
            // MyEnum.Item1 has a chance of 1/10 to be returned
            // MyEnum.Item2 has a chance of 2/10 to be returned
            // MyEnum.Item3 has a chance of 3/10 to be returned
            // MyEnum.Item4 has a chance of 4/10 to be returned

            // take a value from the picker and display it
            var item = picker.NextItem();

            Console.WriteLine($"You got {item}!");

            // take multiple values and display them
            var items = picker.NextItems(5).ToArray();

            Console.WriteLine($"You also got {string.Join(", ", items.Take(4))} and {items.Last()}!");

            // create a new categorised picker
            // you need to give a method that takes in your item and returns a name for that item
            // the method below simply calls .ToString() on the item
            var catPick = new CategorisedPicker <MyEnum>(m => m.ToString());

            // add a category called "Another" to a category called "Test". the picker will add the missing category "Test" automatically.
            catPick.AddCategory("Test/Another");
            catPick.AddCategory("Test/YetAnother");

            // add a category called "MoreTest" to the previously added category "Another". this time, the picker will throw an exception if the path contains missing categories.
            catPick.AddCategory("Test/Another/MoreTest", false);
            // the following would fail
            // catPick.AddCategory("Test/Invalid/WhatAreYouDoing", false);

            // add two items to the "Another/MoreTest" category, both with equal weight
            catPick.AddItem("Test/Another/MoreTest", MyEnum.Item1, 1);
            catPick.AddItem("Test/Another/MoreTest", MyEnum.Item2, 1);

            // add two items to the "Test/YetAnother" category, both with equal weight
            catPick.AddItem("Test/YetAnother", MyEnum.Item3, 1);
            catPick.AddItem("Test/YetAnother", MyEnum.Item4, 1);

            // right now, our category hierarchy looks like this

            /*
             * Test
             *  Another
             *      MoreTest
             *          Item: Item1, weight: 1
             *          Item: Item2, weight: 1
             *  YetAnother
             *      Item: Item3, weight: 1
             *      Item: Item4, weight: 1
             */

            // pick one item from the picker
            // this will go through all categories, and picks an item from the first category it find that contains items
            // looking at our hierarchy above, the first category that contains items is MoreTest
            Console.WriteLine($"From Test/Another/MoreTest: {catPick.NextItem()}");

            // pick one item from the picker, this time specifying a certain category of where to find items from
            Console.WriteLine($"From Test/YetAnother: {catPick.NextItem("Test/YetAnother")}");

            Console.ReadKey();
        }