Exemplo n.º 1
0
 public static void Shuffle <T>(this IList <T> list, RandomInt rnd)
 {
     for (var i = 0; i < list.Count; i++)
     {
         list.Swap(i, rnd.GetValue(i, list.Count));
     }
 }
Exemplo n.º 2
0
 public static AttrPlus LoadFromText(string tmp)
 {
     if (!string.IsNullOrEmpty(tmp))
     {
         AttrPlus plus = new AttrPlus();
         string[] tmpList;
         tmpList = tmp.Split(';');
         for (int i = 0; i < tmpList.Length; i++)
         {
             string[] tmplist2;
             tmplist2 = tmpList[i].Split(',');
             if (tmplist2.Length % 2 != 0)
             {
                 Debug.LogError("load RandomInt error:" + tmp);
             }
             else
             {
                 AttrPlus.Data data = new Data();
                 data.AttrID    = Convert.ToInt32(tmplist2[0]);
                 data.PlusValue = RandomInt.Load(tmplist2[1]);
                 plus.mList.Add(data);
             }
         }
         return(plus);
     }
     return(null);
 }
Exemplo n.º 3
0
        public static void ExampleDelegateReturn()
        {
            Console.WriteLine("-------------------------------------------------------------");
            Console.WriteLine("example delegate return value");

            RandomInt del = GetRandomInt;

            del += GetRandomInt;
            del += GetRandomInt;
            del += GetRandomInt;
            del += GetRandomInt;
            del += GetRandomInt;
            del += GetRandomInt;
            del += GetRandomInt;
            del += GetRandomInt;
            del += GetRandomInt;
            del += GetRandomInt;
            del += GetRandomInt;

            Console.WriteLine($"actions in delagate: {del.GetInvocationList().Length}");
            var total = 0;

            foreach (RandomInt d in del.GetInvocationList())
            {
                total += d();
                Console.WriteLine(d());
            }
            Console.WriteLine(total);

            Console.WriteLine("-------------------------------------------------------------");
        }
Exemplo n.º 4
0
        public void RandomIntTest()
        {
            var random = new RandomInt();

            var integer = random.GetNext();

            Assert.IsInstanceOfType(integer, typeof(int));
        }
Exemplo n.º 5
0
 private IEnumerator HandleSpecialCyl()
 {
     while (true)
     {
         AssignCmColor32(specialCylColorCollection.colorCollectionArray[
                             RandomInt.GenerateNumber(0, specialCylColorCollection.colorCollectionArray.Length)]);
         yield return(new WaitForSeconds(colorChangeSpeedRate));
     }
 }
Exemplo n.º 6
0
        public void RandomIntWithLimits()
        {
            const int Min = -100;
            const int Max = 100;

            var random = new RandomInt(Min, Max);
            var integer = random.GetNext();

            Assert.IsTrue(integer >= Min && integer <= Max);
        }
Exemplo n.º 7
0
        ///--------------------------------------------------------------------------------
        /// <summary>Use RandomInt as basis for default compare (there is no other useful
        /// property for this object).</summary>
        ///--------------------------------------------------------------------------------
        public virtual int CompareTo(object obj)
        {
            DataObjectBase baseObj = obj as DataObjectBase;

            if (obj != null)
            {
                return(RandomInt.CompareTo(baseObj.RandomInt));
            }
            return(0);
        }
Exemplo n.º 8
0
        private RandomInt CreateRandomInt(JToken item)
        {
            int upper = (int)item["upper"];
            int lower = (int)item["lower"];

            var result = new RandomInt(lower, upper);

            result.DebugInfo = GetDebugInfo(item);

            return(result);
        }
Exemplo n.º 9
0
        public async Task <Cart> NewAnnonymousCart()
        {
            await HttpContext.Session.LoadAsync();

            Cart cart = new Cart();

            cart.Id = RandomInt.Get();
            HttpContext.Session.SetObject("AnnonymousCart", cart);
            await HttpContext.Session.CommitAsync();

            return(cart);
        }
Exemplo n.º 10
0
    internal List <ObjectType> Spawn(Gate gate)
    {
        // Debug.Log ( "Spawning list named " + Name );

        List <ObjectType> objectsToSpawn = new List <ObjectType>();

        // get total chance token count
        int totalChanceCount = 0;

        for (int i = 0; i < Items.Count; i++)
        {
            totalChanceCount += Items[i].Chance;
        }

        // draw a value in this full range
        int chanceValue = RandomInt.Range(0, totalChanceCount);

        // try to find to which item this value belongs to
        int chanceRangeLowValue = 0;

        for (int i = 0; i < Items.Count; i++)
        {
            int changeCountForThisItem = Items[i].Chance;

            // compute low-high chance range
            int chanceRangeHighValue = chanceRangeLowValue + changeCountForThisItem;

            // spawn this item if change value in this item's chance range
            bool isChanceInThisRange = (chanceValue >= chanceRangeLowValue) && (chanceValue < chanceRangeHighValue);
            // or spawn if forced by special 0 chance value
            bool isSpawnForced = (Items[i].Chance == 0);

            bool spawnThisItem = isSpawnForced || isChanceInThisRange;

            if (spawnThisItem)
            {
                ObjectType type = Items[i].ObjectType;

//              Debug.Log
//              (
//                  "  -> Spawning item " + type.ToString () + " at gate " + gate.name + " => "
//                  + ( isSpawnForced ? "Spawn force by special chance value at 0. " : "" )
//                  + ( isChanceInThisRange ? ( "Chance value " + chanceValue + " in range [" + chanceRangeLowValue + " , " + chanceRangeHighValue + "]." ) : "" )
//              );

                objectsToSpawn.Add(type);
            }

            chanceRangeLowValue = chanceRangeHighValue;
        }

        return(objectsToSpawn);
    }
Exemplo n.º 11
0
    public static void Shuffle <T> (this IList <T> list)
    {
        int n = list.Count;

        while (n > 1)
        {
            n--;
            int k     = RandomInt.Range(0, n);
            T   value = list[k];
            list[k] = list[n];
            list[n] = value;
        }
    }
Exemplo n.º 12
0
    internal static T GetRandomElement <T> (this T[] self)
    {
        int count = self.Length;

        if (count == 0)
        {
            return(default(T));
        }
        else
        {
            return(self[RandomInt.Range(0, count - 1)]);
        }
    }
Exemplo n.º 13
0
        public FruitBasketGame(List <Player> players, IFruitBasketConfig config)
        {
            Check.NotNull(players, nameof(players));
            Check.NotNull(config, nameof(config));

            _config  = config;
            _players = players;

            if (_players.Count < _config.MinPlayersCount || _players.Count > _config.MaxPlayersCount)
            {
                throw new ArgumentException($"Number of players must be between {_config.MinPlayersCount} and {_config.MaxPlayersCount}");
            }
            Secret = RandomInt.Next(_config.MinFruitBasketWeight, _config.MaxFruitBasketWeight);
        }
Exemplo n.º 14
0
    void Start()
    {
        Gate[] gates = FindObjectsOfType <Gate> ();

        if ((gates.Length > 0) && (!GatesSetup.InstanceCreated))
        {
            Debug.LogError("There is no GatesSetup in this scene.");
            return;
        }

        List <SpawnList> spawnLists = GatesSetup.Instance.SpawnLists;

        if (spawnLists.Count > 0)
        {
            if (spawnLists.Count < gates.Length)
            {
                Debug.LogWarning("The GatesSetup in this scene is not properly setup. Add more spawn list. You have " + gates.Length + " gate(s) in this scene. You have only " + spawnLists.Count + " spawn list. Create at least as many spawn list that there are gates in this scene.");
            }

            List <int> indices = new List <int> ();

            for (int i = 0; i < gates.Length; i++)
            {
                indices.Add(i % spawnLists.Count);
            }

            indices.Shuffle();

            for (int i = 0; i < gates.Length; i++)
            {
                gates[i].SpawnListIndex = indices[i];
            }
        }
        else
        {
            Debug.LogError("The GatesSetup in this scene is not properly setup.");
        }

        int exitGateIndex = RandomInt.Range(0, gates.Length - 1);

        gates[exitGateIndex].IsExit = true;
        Debug.Log("Exit gate is " + gates[exitGateIndex].gateName.ToString());

        //Init timer
        lastTime = Time.time;

        blackFade.SetActive(true);
        blackFade.FadeOut(0.5f, FadeOutEndAction.Destroy);
    }
Exemplo n.º 15
0
    IEnumerator RandomDiceRollLoop()
    {
        int RandomInt;

        while (HasBeenRolled == false)
        {
            RandomInt = Random.Range(1, 11);
            if (RandomInt.ToString() != DiceRoll.text)
            {
                DiceRoll.text = RandomInt.ToString();
                yield return(new WaitForSeconds(.2F));
            }
        }
        RolledNumber       = int.Parse(DiceRoll.text);
        Player.CurrentRoll = RolledNumber;
    }
Exemplo n.º 16
0
        public static void RandomTest1(bool isActive)
        {
            if (!isActive)
            {
                return;
            }
            RandomInt  ran = new RandomInt();
            List <int> l   = ran.GetRandomList(20, 100, 0);

            if (l == null)
            {
                Console.WriteLine("参数异常!");
                return;
            }
            l.ForEach(_ => Console.WriteLine(_));
        }
Exemplo n.º 17
0
                public static RandomInt Load(string text)
                {
                    RandomInt RandMax = new RandomInt();

                    string[] tmplist;
                    tmplist = text.Split('_');
                    if (tmplist.Length != 2)
                    {
                        Debug.LogError("load RandomInt error:" + text);
                    }
                    else
                    {
                        RandMax.m_Min = Convert.ToInt32(tmplist[0]);
                        RandMax.m_Max = Convert.ToInt32(tmplist[1]);
                    }
                    return(RandMax);
                }
Exemplo n.º 18
0
        public void SendEmail(string to, string subject, string emailBody)
        {
            //Arrange
            int number = RandomInt.Next(0, 9999999);

            subject = $"{subject} {number}";

            //Test
            Ui.InboxPage.LeftMenu.ClickComposeButton();
            Ui.NewMessageDialog.FillToField(to);
            Ui.NewMessageDialog.FillSubject(subject);
            Ui.NewMessageDialog.FillBody(emailBody);
            Ui.NewMessageDialog.FillCc(Config.Email);
            Ui.NewMessageDialog.ClickSendButton();

            //Asserts
            Assert.That(Ui.InboxPage.Grid.IsEmailExist(subject));
        }
Exemplo n.º 19
0
    public void PlaceAllObjects(RandomInt quantity, RandomInt width, RandomInt height, GameObject objectToInstanciate, Transform holder, Tiles type,
                                int marginSize     = 1,
                                bool fillWith      = false,
                                Vector2?itemSize   = null,
                                bool placeByCenter = false
                                )
    {
        Vector2 itemFinalSize = Vector2.one;

        if (itemSize != null)
        {
            itemFinalSize = itemSize.Value;
        }

        for (int i = 0; i < quantity.GetRandomInt(); i++)
        {
            PlaceObject(width.GetRandomInt(), height.GetRandomInt(), objectToInstanciate, holder, type, itemFinalSize, fillWith, marginSize, placeByCenter);
        }
    }
Exemplo n.º 20
0
    internal static bool GetRandomElementNotIn <T> (this T[] self, IEnumerable <T> list, out T element)
    {
        int count        = self.Length;
        int initialIndex = RandomInt.Range(0, count - 1);
        int index        = initialIndex;

        while (true)
        {
            element = self[index];
            if (!list.Contains <T> (element))
            {
                return(true);
            }

            index = (index + 1) % count;
            if (index == initialIndex)
            {
                return(false);
            }
        }
    }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            int Randomizer()
            {
                int r = new Random().Next(100);

                System.Threading.Thread.Sleep(r);
                return(r);
            }

            RandomInt[] random = new RandomInt[3];

            for (int i = 0; i < random.Length; i++)
            {
                random[i] = Randomizer;
            }

            Average average = delegate(RandomInt[] c)
            {
                int summ = 0;
                for (int i = 0; i < c.Length; i++)
                {
                    Console.Write(c[i].Invoke() + " ");
                    summ += c[i].Invoke();
                }
                return(summ / c.Length);
            };



/*           for (int i = 0; i < random.Length; i++)
 *          {
 *              Console.Write(random[i]()+ " ");
 *          }*/

            Console.WriteLine("1");
            Console.WriteLine(average(random));
            //Console.WriteLine(Randomizer());
            Console.ReadLine();
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            Calculations del = LengthCircle;

            del += AreaCircle;
            del += Volume;
            del(10);

            RandomInt delFirst  = RandomNum;
            RandomInt delSecond = RandomNum;
            RandomInt delThird  = RandomNum;

            AnonimMethod anonimMethod = delegate(RandomInt delFirst, RandomInt delSecond, RandomInt delThird)
            {
                double a = Convert.ToDouble(delFirst());
                double b = Convert.ToDouble(delFirst());
                double c = Convert.ToDouble(delFirst());
                return((a + b + c) / 3);
            };

            Console.WriteLine("\nСреднее арифметическое 3 чисел: " + anonimMethod(delFirst, delSecond, delThird));
        }
Exemplo n.º 23
0
        public static void Load()
        {
            for (int i = 0; i < Asteroid.asteroidCount; i++)
            {
                _asteroids.Add(new Asteroid(
                                   new Point(RandomInt.Next(Game.Width / 2, Game.Width), RandomInt.Next(0, Game.Height)),
                                   new Point(RandomInt.Next(1, 10), RandomInt.Next(1, 10)),
                                   new Size(RandomInt.Next(10, 50), RandomInt.Next(10, 50))));
            }

            for (int i = 0; i < Star.starCount; i++)
            {
                _stars.Add(new Star(
                               new Point(RandomInt.Next(0, Game.Width), RandomInt.Next(0, Game.Height)),
                               new Point(RandomInt.Next(1, 10), 0),
                               new Size(RandomInt.Next(50, 80), RandomInt.Next(60, 100))));
            }

            _medpacks.Add(new Medpack(
                              new Point(RandomInt.Next(Game.Width / 2, Game.Width), RandomInt.Next(20, Game.Height)),
                              new Point(RandomInt.Next(1, 5), 0),
                              new Size(30, 25)));
        }
Exemplo n.º 24
0
    public void GenerateTorch(Room room, RandomInt randomQuantityBySide)
    {
        //TODO CHANGER 9A POUR QUE 9A SOIT A lentree dans la room plutot
        GameObject     mapHolder             = GameObject.Find(mapHolderName);
        List <Vector2> patternPositionsSud   = new List <Vector2>();
        List <Vector2> patternPositionsNord  = new List <Vector2>();
        List <Vector2> patternPositionsOuest = new List <Vector2>();
        List <Vector2> patternPositionsEst   = new List <Vector2>();

        //Recherches des patterns
        int quantity = randomQuantityBySide.GetRandomInt();

        for (int i = 0; i < quantity; i++)
        {
            Vector2?patternPositionSud = room.FindRandomPattern(TilesPattern.wallSud);
            if (patternPositionSud != null)
            {
                patternPositionsSud.Add(patternPositionSud.Value);
            }
        }

        quantity = randomQuantityBySide.GetRandomInt();
        for (int i = 0; i < quantity; i++)
        {
            Vector2?patternPositionNord = room.FindRandomPattern(TilesPattern.wallNord);
            if (patternPositionNord != null)
            {
                patternPositionsNord.Add(patternPositionNord.Value);
            }
        }

        quantity = randomQuantityBySide.GetRandomInt();
        for (int i = 0; i < quantity; i++)
        {
            Vector2?patternPositionOuest = room.FindRandomPattern(TilesPattern.wallOuest);
            if (patternPositionOuest != null)
            {
                patternPositionsOuest.Add(patternPositionOuest.Value);
            }
        }

        quantity = randomQuantityBySide.GetRandomInt();
        for (int i = 0; i < quantity; i++)
        {
            Vector2?patternPositionEst = room.FindRandomPattern(TilesPattern.wallEst);
            if (patternPositionEst != null)
            {
                patternPositionsEst.Add(patternPositionEst.Value);
            }
        }

        //Suppression des doublons
        patternPositionsSud   = patternPositionsSud.Distinct().ToList();
        patternPositionsNord  = patternPositionsNord.Distinct().ToList();
        patternPositionsOuest = patternPositionsOuest.Distinct().ToList();
        patternPositionsEst   = patternPositionsEst.Distinct().ToList();

        //Instanciation
        foreach (var pattern in patternPositionsSud)
        {
            GameObject o = Instantiate(torch, pattern + new Vector2(1.5f, 0.5f), Quaternion.identity) as GameObject;
            o.transform.parent = mapHolder.transform;
        }
        foreach (var pattern in patternPositionsNord)
        {
            GameObject o = Instantiate(torch, pattern + new Vector2(1.5f, 2.5f), Quaternion.identity) as GameObject;
            o.transform.parent = mapHolder.transform;
        }
        foreach (var pattern in patternPositionsOuest)
        {
            GameObject o = Instantiate(torch, pattern + new Vector2(0.5f, 1.5f), Quaternion.identity) as GameObject;
            o.transform.parent = mapHolder.transform;
        }
        foreach (var pattern in patternPositionsEst)
        {
            GameObject o = Instantiate(torch, pattern + new Vector2(2.5f, 1.5f), Quaternion.identity) as GameObject;
            o.transform.parent = mapHolder.transform;
        }
    }
Exemplo n.º 25
0
        IEnumerator GenDungen()
        {
            m_isFinishGen = false;

            m_rooms         = new List <Room>();
            m_doors         = new List <Door>();
            m_openSet       = new List <Connector>();
            m_globalVoxels  = new HashSet <Vector3>();
            m_connectorsPos = new HashSet <Vector3>();

            if (m_random == null)
            {
                m_random = new RandomInt();
            }
            if (!m_useCustomSeed)
            {
                m_seed = Random.Range(0, int.MaxValue);
            }
            Debug.Log("seed = " + m_seed);
            m_random.Init(m_seed);

            int spawnRoomID = m_random.GetValue(0, m_generatorData.GetSpawnRoomCount(m_activeSetIndex));

            m_startRoom = Instantiate(m_generatorData.GetSpawnRoom(m_activeSetIndex, spawnRoomID));
            m_startRoom.transform.SetParent(this.transform);
            m_openSet.Add(m_startRoom.m_connectors[0]);

            var volume = m_startRoom.GetComponent <Volume>();

            volume.CalculateBound();
            AddGlobalVoxels(volume);
            AddConnectorsPos(m_startRoom);

            //创建房间
            while (m_openSet.Count > 0)
            {
                Debug.LogFormat("生成第{0}个地宫", m_rooms.Count);
                yield return(GenerateNextRoom());

                if (m_debugRoomGenProcess)
                {
                    yield return(new WaitForSeconds(1f));
                }
            }
            //创建门

            /*
             * for (int i = 0; i < m_rooms.Count; i++)
             * {
             *  var room = m_rooms[i];
             *  for (int j = 0; j < room.m_connectors.Count; j++)
             *  {
             *      var connector = room.m_connectors[j];
             *
             *      if (connector.m_isOpen) {
             *          if (connector.m_doorType != -1) {// -1 为不需要门
             *              Door d = Instantiate(m_generatorData.GetDoor(m_activeSetIndex, connector.m_doorType));
             *              m_doors.Add(d);
             *
             *              connector.m_door = d;
             *              connector.m_shareConnetor.m_door = d;
             *
             *              d.gameObject.transform.position = connector.transform.position;
             *              d.gameObject.transform.rotation = connector.transform.rotation;
             *
             *              d.gameObject.transform.SetParent(this.transform);
             *          }
             *          //关闭连接器
             *          connector.m_isOpen = false;
             *          connector.m_shareConnetor.m_isOpen = false;
             *      }
             *  }
             * }
             */
            m_isFinishGen = true;
            Debug.Log("完成地宫的生成,房间数:" + m_rooms.Count);
        }
Exemplo n.º 26
0
 private void Start()
 {
     imSpecial = RandomInt.GenerateNumber(0, 20) > 17;
 }
Exemplo n.º 27
0
    static internal T GetRandomEnumValue <T> ()
    {
        var v = System.Enum.GetValues(typeof(T));

        return((T)v.GetValue(RandomInt.Range(0, v.Length - 1)));
    }
Exemplo n.º 28
0
        public static void Update()
        {
            foreach (Star a in _stars)
            {
                a.Update();
            }
            foreach (Bullet b in _bullets)
            {
                b.Update();
            }
            foreach (Medpack c in _medpacks)
            {
                c.Update();
            }
            var temp_b = new List <Bullet>();
            var temp_a = new List <Asteroid>();
            var temp_m = new List <Medpack>();

            if (_asteroids.Count == 0)
            {
                Asteroid.asteroidCount++;
                for (int i = 0; i < Asteroid.asteroidCount; i++)
                {
                    _asteroids.Add(new Asteroid(
                                       new Point(RandomInt.Next(Game.Width / 2, Game.Width), RandomInt.Next(0, Game.Height)),
                                       new Point(RandomInt.Next(1, 10), RandomInt.Next(1, 10)),
                                       new Size(RandomInt.Next(10, 50), RandomInt.Next(10, 50))));
                }
            }
            if (_medpacks.Count == 0)
            {
                _medpacks.Add(new Medpack(
                                  new Point(RandomInt.Next(Game.Width / 2, Game.Width), RandomInt.Next(20, Game.Height)),
                                  new Point(RandomInt.Next(1, 5), 0),
                                  new Size(30, 25)));
            }

            foreach (var asteroid in _asteroids)
            {
                asteroid.Update();
                foreach (var bullet in _bullets)
                {
                    if (bullet.Collision(asteroid))
                    {
                        System.Media.SystemSounds.Hand.Play();
                        temp_a.Add(asteroid);
                        temp_b.Add(bullet);
                    }
                }
                if (_ship.Collision(asteroid))
                {
                    _ship.EnergyLow(RandomInt.Next(1, 10));
                    System.Media.SystemSounds.Asterisk.Play();
                    temp_a.Add(asteroid);
                    if (_ship.Energy <= 0)
                    {
                        _ship.Die();
                    }
                }
            }
            foreach (var medpack in _medpacks)
            {
                if (medpack.Collision(_ship))
                {
                    temp_m.Add(medpack);
                    _ship.EnergyUp(RandomInt.Next(10, 30));
                }
            }
            foreach (Bullet b in temp_b)
            {
                _bullets.Remove(b);
            }
            foreach (Asteroid a in temp_a)
            {
                _asteroids.Remove(a);
            }
            foreach (Medpack m in temp_m)
            {
                _medpacks.Remove(m);
            }
        }
Exemplo n.º 29
0
 protected virtual int NextGuess()
 {
     return(RandomInt.Next(Config.MinFruitBasketWeight, Config.MaxFruitBasketWeight));
 }