Ejemplo n.º 1
0
        private static void randomMethodCalls()
        {
            Console.WriteLine("-- Random Method Calls --");

            //add actions to the selector
            var selector = RandomSelector
                           .Add(() => { Console.WriteLine("do first thing"); })
                           .Add(() => { Console.WriteLine("do other thing"); });

            for (int i = 0; i < 5; i++)
            {
                selector.Choose(); //randomly picks an action to run
            }

            Console.WriteLine();
        }
Ejemplo n.º 2
0
        private static void weightedRandomMethodCalls()
        {
            Console.WriteLine("-- Weighted Random Method Calls --");

            //add actions to the selector (must add up to 1.0)
            var selector = RandomSelector
                           .Add(0.7, () => { Console.WriteLine("0.7 - probably do this"); })
                           .Add(0.2, () => { Console.WriteLine("0.2 - maybe do this"); })
                           .Add(0.1, () => { Console.WriteLine("0.1 - small chance of this"); });

            for (int i = 0; i < 5; i++)
            {
                selector.Choose(); //randomly picks an action to run
            }

            Console.WriteLine();
        }
Ejemplo n.º 3
0
        private static void weightedGeneric()
        {
            Console.WriteLine("-- Weighted Random Return Values --");

            //add actions to the selector (must add up to 1.0)
            var selector = RandomSelector <int>
                           .Add(0.7, 1)
                           .Add(0.2, 2)
                           .Add(0.1, 3);

            for (int i = 0; i < 5; i++)
            {
                var val = selector.Choose(); //randomly picks an action to run
                Console.WriteLine("chose " + val);
            }

            Console.WriteLine();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reproduction process
        /// </summary>
        private void Reproduce()
        {
            RandomSelector <Species> selector = new RandomSelector <Species>();

            foreach (Species s in AllSpecies)
            {
                selector.Add(s, s.Score);
            }

            foreach (Client c in AllClients)
            {
                if (c.Species == null)
                {
                    Species s = selector.Random();
                    c.Genome = s.Breed();
                    s.ForcePut(c);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 消えた部屋につながっていた袋小路の処理
        /// </summary>
        /// <param name="room"></param>
        void ProcessDeadEnd(DungeonRoom room)
        {
            var deadends = new List<DungeonPath>();

            UpdateAccessibility();

            foreach (var portal in room.Portals)
            {
                if (portal.ConnectedPaths.Count == 0)
                    continue;

                var path = portal.ConnectedPaths[0];

                if (path.Accessible)
                {
                    // 袋小路をリストアップ
                    deadends.Add(path);
                }
                else
                {
                    // 孤立している通路は消す
                    RemovePath(path);
                }
            }

            var selector = new RandomSelector<DeadEndDisposal>(Rand);
            selector.Add(40, DeadEndDisposal.CONNECT);
            selector.Add(55, DeadEndDisposal.REMOVE);
            selector.Add(5, DeadEndDisposal.LEAVE);

            while (deadends.Count > 0)
            {
                var disposal = selector.Get();

                if (disposal == DeadEndDisposal.CONNECT && deadends.Count >= 2)
                {
                    var another = Rand.Next(1, deadends.Count);

                    var portals = new DungeonPortal[2]{
                        deadends[0].GetTerminalPortal(),
                        deadends[another].GetTerminalPortal()
                    };

                    var path = GeneratePath(
                        portals[0],
                        portals[1],
                        IsHorizontalPortals(portals[0], portals[1])
                        );

                    if (path != null)
                    {
                        AddPath(path);
                        deadends.RemoveAt(another);
                    }
                    deadends.RemoveAt(0);

                }
                else if (disposal == DeadEndDisposal.REMOVE)
                {
                    RemovePath(deadends[0]);
                    deadends.RemoveAt(0);
                }
                else if (disposal == DeadEndDisposal.LEAVE)
                {
                    deadends.RemoveAt(0);
                }
            }

        }