示例#1
0
 /// <summary>
 /// Returns a <see cref="Vector3"/> with random values between -1 and 1 for its coordinates.
 /// </summary>
 /// <returns>A random vector3.</returns>
 public static Vector3 Random( )
 {
     return(new Vector3(
                ThreadRandom.NextFloat( ) * 2 - 1,
                ThreadRandom.NextFloat( ) * 2 - 1,
                ThreadRandom.NextFloat( ) * 2 - 1));
 }
示例#2
0
        public IList <StringUnit> Breed()
        {
            //Get random index and split there.
            var len        = ParentA.Genome.Length;
            var splitIndex = ThreadRandom.Next(len);

            var parentAFirst  = ParentA.Genome.ToString(0, splitIndex);
            var parentASecond = ParentA.Genome.ToString(splitIndex, len - (splitIndex));
            var parentBFirst  = ParentB.Genome.ToString(0, splitIndex);
            var parentBSecond = ParentB.Genome.ToString(splitIndex, len - (splitIndex));

            //AF -> BS and BF -> AS
            var firstChild  = new StringUnit(new StringBuilder(string.Concat(parentAFirst, parentBSecond)), ParentA, ParentB);
            var secondChild = new StringUnit(new StringBuilder(string.Concat(parentBFirst, parentASecond)), ParentA, ParentB);
            var children    = new List <StringUnit>()
            {
                firstChild, secondChild
            };

            //Attempt mutation
            //todo: make Mutate method part of IPopulationUnit to avoid type casting here?
            foreach (StringUnit child in children)
            {
                child.Mutate();
                child.CalculateFitness(TargetString);
            }

            return(children);
        }
示例#3
0
        public ActionResult Index()
        {
            var memes = GlobalMemeConfiguration.Memes.GetMemes();

            // note: since this method uses output caching, you should really only expect
            // the value to change once per minute
            var randomIndex = ThreadRandom.Next(0, memes.Count);
            var randomMeme  = memes[randomIndex];

            var root = HostingEnvironment.ApplicationVirtualPath ?? "";

            if (!root.EndsWith("/"))
            {
                root += "/";
            }

            var viewModel = new IndexViewModel()
            {
                RecentMemes = new List <RecentMeme>
                {
                    new RecentMeme
                    {
                        Url   = root + "sap/wears-suit-and-tie-to-interview/phone-interview.jpg",
                        Alt   = "socially awkward penguin: wears suit and tie to interview" + Environment.NewLine + "phone interview",
                        Title = "socially awkward penguin"
                    },
                    new RecentMeme
                    {
                        Url   = root + "fry/not-sure-if-sunny-outside/or-hungover.jpg",
                        Alt   = "futurama fry: not sure if sunny outside" + Environment.NewLine + "or hungover",
                        Title = "futurama fry"
                    },
                    new RecentMeme
                    {
                        Url   = root + "scc/i-don't-buy-things-with-money/i-buy-them-with-hours-of-my-life.jpg",
                        Alt   = "sudden clarity clarence: i don't buy things with money" + Environment.NewLine + "i buy them with hours of my life",
                        Title = "sudden clarity clarence"
                    },
                    new RecentMeme
                    {
                        Url   = root + "blb/has-pet-rock/it-runs-away.jpg",
                        Alt   = "bad luck brian: has pet rock" + Environment.NewLine + "it runs away",
                        Title = "bad luck brian"
                    }
                },
                BuilderViewModel = new BuilderViewModel
                {
                    Memes        = memes,
                    Lines        = Enumerable.Repeat("", randomMeme.Lines.Count).ToList(),
                    SelectedMeme = randomMeme.Aliases.First()
                }
            };

            return(View(viewModel));
        }
示例#4
0
        public bool Mutate()
        {
            //Slow mutations over time
            var probability = (double)Globals.BaseMutationChance * (double)1001;

            if (ThreadRandom.Next(1, 1001) <= probability)
            {
                //todo:extract this builder into a threatstatic builder
                var b = Globals.GetStringBuilder(Genome.ToString());
                b[ThreadRandom.Next(b.Length)] = Globals.RandomChar();
                SetupBuilder(b);
                return(true);
            }
            return(false);
        }
示例#5
0
文件: Utils.cs 项目: GKBelmonte/Core
 public static bool ProbabilityPass(float p)
 {
     return(ThreadRandom.ProbabilityPass(p));
 }