public static string GetRandomImage(bool next)
    {
        string[]       fileList = HttpRuntime.Cache["RandomFileList"] as string[];
        RandomSequence rs       = HttpContext.Current.Session["RandomImageSequence"] as RandomSequence;

        if (fileList == null)
        {
            fileList = WebUtils.GetRandomImgFileList();
            HttpRuntime.Cache.Insert("RandomFileList", fileList, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration);
        }

        if (rs == null || (rs != null && rs.SequenceLooped))
        {
            rs = RandomSequence.GetRandomSequence(fileList.Length);
            HttpContext.Current.Session["RandomImageSequence"] = rs;
        }

        List <RandomImage> randomImageList = WebUtils.GetRandomImageListFromCache();

        if (!next)
        {
            //rs.GetPrevious();
            //rs.GetPrevious();
        }

        string randomImage     = next ? fileList[rs.GetNext()] : fileList[rs.GetPrevious()];
        string imageDirectLink = "";

        if (randomImageList.Any(x => x.FileName == randomImage))
        {
            imageDirectLink = randomImageList.Where(x => x.FileName == randomImage).Single().ImageId;
        }

        return(cms.Current.GetRootPath + "randimg/" + imageDirectLink + ";" + cms.Current.GetRootPath + "RandomImg/" + randomImage);
    }
Esempio n. 2
0
        public void Test_RandomSequence_ShouldAlternate_WhenOnlyTwoObjects()
        {
            object[] objects = new object[2] {
                new object(), new object()
            };
            RandomSequence <object> sequence = new RandomSequence <object>(objects);

            sequence.initialise();
            object firstObject  = sequence.Current;
            object secondObject = sequence.Next;

            for (int i = 0; i < num_of_cycles; i++)
            {
                object current = sequence.Current;
                object next    = sequence.Next;
                if (i % 2 == 0)
                {
                    if (current != firstObject || next != secondObject)
                    {
                        FailWithShouldAlternateMessage();
                    }
                }
                else
                {
                    if (current == firstObject || next == secondObject)
                    {
                        FailWithShouldAlternateMessage();
                    }
                }
                sequence.advance();
            }
        }
Esempio n. 3
0
        public void ctor_Test()
        {
            RandomSequence rSeq = new RandomSequence(1000);
            var values = rSeq.GetDoubles().Take(100).ToList();

            Assert.AreEqual(values.Count(), 100);
        }
Esempio n. 4
0
    public void InitializeSoundPlayer()
    {
        _sequence = new RandomSequence(_randomsource, _audioBanks);

        _randomsource.outputAudioMixerGroup     = output;
        _musicsource.outputAudioMixerGroup      = music;
        _eventmusicsource.outputAudioMixerGroup = music;
        _uisource.outputAudioMixerGroup         = ui;
        _generalsource.outputAudioMixerGroup    = output;
    }
Esempio n. 5
0
        public void Random_with_Seed_Test(int seedMax)
        {
            Func<int> randomSeed =
                () => Helpers.SeedHelper.GetRandomSeed(
                    new RNGCryptoServiceProvider(), seedMax);

            RandomSequence seq = new RandomSequence(seed: randomSeed);
            var values = seq.GetDoubles().Take(100).ToList();
            Assert.AreEqual(values.Count(), 100);
            Assert.LessOrEqual(seq.Seed, seedMax);
        }
Esempio n. 6
0
                // ...

                void Start()
                {
                    setNextPlayTime();
                    audioSource = GetComponent <AudioSource>();

                    randomSequence = new RandomSequence(audioClips.Length, 8);

                    for (int i = 0; i < 128; i++)
                    {
                        //print(randomSequence.get());
                    }
                }
Esempio n. 7
0
        public void Random_with_Seed_Exception_Test(int seedMax)
        {
            Assert.Throws(typeof(ArgumentException), () =>
            {
                Func<int> randomSeed =
                    () => Helpers.SeedHelper.GetRandomSeed(
                        new RNGCryptoServiceProvider(),
                        seedMax);

                RandomSequence seq = new RandomSequence(seed: randomSeed);
            });
        }
Esempio n. 8
0
        private void NewRound()
        {
            myCards  = new List <int>();
            hisCards = new List <int>();
            rs       = new RandomSequence(52);

            for (int i = 0; i < 2; i++)
            {
                myCards.Add(rs.NextNumber());
                hisCards.Add(rs.NextNumber());
            }
            myFull  = false;
            hisFull = false;
            Invalidate(new Rectangle(xoff, yoff, 324, 244));
        }
Esempio n. 9
0
        public void DrawDoubleTest()
        {
            double a = RandomSequence.DrawDouble();
            double b = RandomSequence.DrawDouble();
            double c = RandomSequence.DrawDouble();

            double[] testValues = { a, b, c };
            double[] trueValues = { 0.668106465911542, 0.140907298373481, 0.125518289453126 };

            double tolerance = 1e-15;

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(testValues[i], trueValues[i], tolerance);
            }
            //CollectionAssert.AreEqual(testValues}, trueValues, 1e-12,
            //                          "oups, didn't work " + a.ToString() + "/" + b.ToString() + "/" + c.ToString());
        }
Esempio n. 10
0
        /*
         * HELPER CODE
         */
        public static string Code(int char_count)
        {
            string           code = "";
            Random           rdn  = new Random();
            HashSet <string> text = new HashSet <string>();

            var list = new RandomSequence[]
            {
                new RandomSequence("abcdefghijklmnopqrstuvxywz"),
                new RandomSequence("ABCDEFGHIJKLMNOPQRSTUVXYWZ"),
                new RandomSequence("0123456789")
            };

            //while (true)
            //{
            //    for (int l = 0; l < 10; l++)
            //    {
            //        code += list[rdn.Next(0, list.Length)].SelectOne();
            //    }
            //    if (text.Contains(code))
            //    {
            //        Console.WriteLine("Contain");
            //        break;
            //    }
            //    text.Add(code);
            //    Console.WriteLine($"{code} / {count++}");
            //    code = "";
            //    //Console.ReadKey();
            //}

            for (int l = 0; l < char_count; l++)
            {
                code += list[rdn.Next(0, list.Length)].SelectOne();
            }

            return(code);
        }
Esempio n. 11
0
    private Task getBTfromGenotype(BTNode subTree)
    {
        string taskName = subTree.taskName;

        if (subTree.isLeafNode())
        {
            // Actions
            if (taskName.Equals("Jump"))
            {
                Jump temp = new Jump();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveLeftForSeconds"))
            {
                MoveLeftForSeconds temp = new MoveLeftForSeconds();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveRightForSeconds"))
            {
                MoveRightForSeconds temp = new MoveRightForSeconds();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveRightForDistance"))
            {
                MoveRightForDistance temp = new MoveRightForDistance();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("ShootBullet"))
            {
                ShootBullet temp = new ShootBullet();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveLeftForDistance"))
            {
                MoveLeftForDistance temp = new MoveLeftForDistance();
                #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            // TO DO add conditionals
            else if (taskName.Equals("AtEdge"))
            {
                AtEdge temp = new AtEdge();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("HittingWall"))
            {
                HittingWall temp = new HittingWall();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("LowLife"))
            {
                LowLife temp = new LowLife();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("PlayerInRange"))
            {
                PlayerInRange temp = new PlayerInRange();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else
            {
                Grounded temp = new Grounded();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
        }
        else
        {
            if (taskName.Equals("Selector"))
            {
                Selector temp = new Selector();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else if (taskName.Equals("Sequence"))
            {
                Sequence temp = new Sequence();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else if (taskName.Equals("RandomSelector"))
            {
                RandomSelector temp = new RandomSelector();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else if (taskName.Equals("RandomSequence"))
            {
                RandomSequence temp = new RandomSequence();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else
            {
                Parallel temp = new Parallel();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
        }
    }
Esempio n. 12
0
        private static void ReadBody(StreamReader sr, int mapWidth, int mapHeight, Random r,
                                     List <SceneManager.ScenePosData> cachedMapData, List <DbSceneSpecialPosData> cachedSpecialData,
                                     int wid, int height, int xoff, int yoff)
        {
            int cellWidth  = GameConstants.SceneTileStandardWidth * mapWidth / 1422;
            int cellHeight = GameConstants.SceneTileStandardHeight * mapHeight / 855;
            Dictionary <int, List <SceneManager.ScenePosData> > randomGroup = new Dictionary <int, List <SceneManager.ScenePosData> >();

            for (int i = 0; i < height; i++)
            {
                string[] data = sr.ReadLine().Split('\t');
                for (int j = 0; j < wid; j++)
                {
                    int val = Int32.Parse(data[j]);
                    if (val == 0)
                    {
                        continue;
                    }

                    int lineOff = (int)(cellWidth * (height - i - 1) * GameConstants.SceneTileGradient);
                    SceneManager.ScenePosData so = new SceneManager.ScenePosData
                    {
                        Id     = val,
                        X      = xoff + j * cellWidth + lineOff,
                        Y      = yoff + i * cellHeight,
                        Width  = cellWidth,
                        Height = cellHeight
                    };
                    if (val < 1000) //随机组
                    {
                        so.Id = (height - i) * 1000 + j + 1;
                        if (!randomGroup.ContainsKey(val))
                        {
                            randomGroup[val] = new List <SceneManager.ScenePosData>();
                        }
                        randomGroup[val].Add(so);
                    }
                    else
                    {
                        cachedMapData.Add(so);
                    }
                }
            }

            RandomSequence rs = new RandomSequence(randomGroup.Count, r);

            for (int i = 0; i < Math.Ceiling(randomGroup.Keys.Count * 0.5f); i++)
            {
                foreach (var randPos in randomGroup[rs.NextNumber() + 1])
                {
                    cachedMapData.Add(randPos);
                }
            }

            string line;

            while ((line = sr.ReadLine()) != null)
            {
                string[] data = line.Split('\t');
                if (data.Length < 2)
                {
                    continue;
                }

                var posData = new DbSceneSpecialPosData();
                posData.Id         = Int32.Parse(data[0]);
                posData.Type       = data[1];
                posData.MapSetting = true;
                if (data.Length > 2)
                {
                    posData.Info = Int32.Parse(data[2]);
                }
                cachedSpecialData.Add(posData);
            }
        }