예제 #1
0
        public void MutateChromosome()
        {
            const uint symbolCount    = 32;
            const int  sequenceLength = 10000;

            var chromo = Rando.Fast(123)
                         .ToUintEnumerator(symbolCount)
                         .Take(sequenceLength)
                         .ToList()
                         .ToChromosomeUint(symbolCount);

            const int    seed          = 1234;
            const double mutationRate  = 0.1;
            const double insertionRate = 0.0;
            const double deletionRate  = 0.0;

            var newChromo = chromo.StandardPropigate
                            (
                rando: Rando.Fast(seed),
                mutationRate: mutationRate,
                insertionRate: insertionRate,
                deletionRate: deletionRate
                            );

            var diffCount = newChromo.Sequence.GetDifferentItems(chromo.Sequence).Count();

            Assert.AreEqual(newChromo.Sequence.Count, sequenceLength);
            Assert.IsTrue(diffCount < sequenceLength * mutationRate * 1.1);
            Assert.IsTrue(diffCount > sequenceLength * mutationRate * 0.9);
        }
예제 #2
0
        public void TestGuidHashErgodictiy()
        {
            var guidsAndKeys = new Dictionary <Guid, int>();
            var curGuid      = Guid.NewGuid();

            for (var i = 0; i < 100000; i++)
            {
                var curSeed = curGuid.ToHash();
                guidsAndKeys[curGuid] = curSeed;
                var randy = Rando.Fast(curSeed);
                curGuid = randy.NextGuid();
                guidsAndKeys[curGuid] = curSeed;
                curGuid = randy.NextGuid();
                guidsAndKeys[curGuid] = curSeed;
                curGuid = randy.NextGuid();
                guidsAndKeys[curGuid] = curSeed;
                curGuid = randy.NextGuid();
                guidsAndKeys[curGuid] = curSeed;
                curGuid = randy.NextGuid();
                guidsAndKeys[curGuid] = curSeed;
                curGuid = randy.NextGuid();
                guidsAndKeys[curGuid] = curSeed;
                curGuid = randy.NextGuid();
            }
        }
예제 #3
0
        public static ISgMutantProfile ToSgMutantProfile
        (
            this ISorterGenomeEval parentGenomeEval,
            ISorterMutateParams sorterMutateParams
        )
        {
            var rando = Rando.Fast(sorterMutateParams.Seed);

            var layer = SorterLayer.Make(new[] { parentGenomeEval.SorterGenome }, 0)
                        .Reproduce(
                seed: rando.NextInt(),
                newGenomeCount: sorterMutateParams.MutantCount,
                mutationRate: sorterMutateParams.SorterMutationRate,
                insertionRate: sorterMutateParams.SorterInsertionRate,
                deletionRate: sorterMutateParams.SorterDeletionRate
                );

            var compPool = CompPool.MakeEmpty(parentGenomeEval.SorterGenome.KeyCount)
                           .AddSorterEvalsParallel(layer.Genomes.Select(g => g.ToSorter()));

            return(new SgMutantProfileImpl(
                       parentGenomeEval: parentGenomeEval,
                       sorterGenomeEvals: compPool.SorterEvals.Where(ev => ev.SwitchUseCount <= sorterMutateParams.MaxScore)
                       .Select(ev => SorterGenomeEval.Make
                               (
                                   sorterGenome: layer.GetGenome(ev.Sorter.Guid),
                                   parentGenomeEval: parentGenomeEval,
                                   sorterEval: ev,
                                   generation: 1,
                                   success: ev.Success
                               )),
                       scores: compPool.SorterEvals.Select(ev => (double)ev.SwitchUseCount),
                       sorterMutateParams: sorterMutateParams
                       ));
        }
예제 #4
0
 public Dart(float xpos, float ypos, Duck owner, float fireAngle)
     : base(xpos, ypos)
 {
     this._sprite         = new SpriteMap("dart", 16, 16);
     this.graphic         = (Sprite)this._sprite;
     this.center          = new Vec2(8f, 8f);
     this.collisionOffset = new Vec2(-4f, -2f);
     this.collisionSize   = new Vec2(9f, 4f);
     this.depth           = new Depth(-0.5f);
     this.thickness       = 1f;
     this.weight          = 3f;
     this._owner          = owner;
     this.breakForce      = 1f;
     this._stickTime      = 2f + Rando.Float(0.8f);
     if ((double)Rando.Float(1f) > 0.949999988079071)
     {
         this._stickTime += Rando.Float(15f);
     }
     this.angle = fireAngle;
     if (owner == null)
     {
         return;
     }
     owner.clip.Add((MaterialThing)this);
     this.clip.Add((MaterialThing)owner);
 }
        public MusketSmoke(float xpos, float ypos)
            : base(xpos, ypos)
        {
            this.xscale    = 0.15f + Rando.Float(0.15f);
            this.yscale    = this.xscale;
            this.angle     = Maths.DegToRad(Rando.Float(360f));
            this._fastGrow = 0.6f + Rando.Float(0.3f);
            this._angleInc = Maths.DegToRad(Rando.Float(2f) - 1f);
            this._scaleInc = 1f / 1000f + Rando.Float(1f / 1000f);
            this._fade     = 0.0015f + Rando.Float(1f / 1000f);
            this.move.x    = Rando.Float(0.2f) - 0.1f;
            this.move.y    = Rando.Float(0.2f) - 0.1f;
            GraphicList graphicList = new GraphicList();
            Sprite      graphic1    = new Sprite("smoke");

            graphic1.depth = new Depth(1f);
            graphic1.CenterOrigin();
            graphicList.Add(graphic1);
            Sprite graphic2 = new Sprite("smokeBack");

            graphic2.depth = new Depth(-0.1f);
            graphic2.CenterOrigin();
            graphicList.Add(graphic2);
            this.graphic          = (Sprite)graphicList;
            this.center           = new Vec2(0.0f, 0.0f);
            this.depth            = new Depth(1f);
            this._backgroundSmoke = new Sprite("smokeBack");
        }
예제 #6
0
        public void WordTest()
        {
            String tmpFile = System.IO.Path.GetTempFileName();

            this.testFiles.Add(tmpFile);
            long size = Rando.RandomInt(500, 5000);

            ps.AddCommand("New-RandomFile")
            .AddParameter("Size", size)
            .AddParameter("OutputFile", tmpFile)
            .AddParameter("StringType", "Word")
            .AddParameter("Seperator", ";");

            var list = this.DoInvoke <FileInfo>();

            Assert.AreEqual(1, list.Count);

            foreach (var hr in list)
            {
                Assert.IsTrue(hr.Length >= size, String.Format("Output size is smaller than requested: expected={0}, actual={1}", size, hr.Length));
                Assert.AreEqual(tmpFile, hr.FullName);

                Char[] text = System.IO.File.ReadAllText(hr.FullName).ToCharArray();
                for (int i = 0; i < text.Length; i++)
                {
                    Char c = text[i];
                    Assert.IsTrue((Char.IsLetter(c) || c == ';' || c == ' ' || c == '-' || c == '\''), String.Format("Character is not an expected value: '{0}',{1}", c, i));
                }
            }
        }
        public void TestUpdateWithMergeAndTrack()
        {
            var tracker = ScpWorkflowTracker.Make();

            var builder = ScpWorkflowBuilder.Make
                          (
                workFlowGuid: Guid.NewGuid(),
                repository: TestRepository.EntityRepository,
                sorterGroupGuid: TestRepository.SorterLayerGuid,
                scpParamsGuid: TestRepository.ScpParamsGuid
                          );

            var updatedBuilder = builder;

            for (var i = 0; i < 5000; i++)
            {
                var seeds = Rando.Fast(i * 17).ToIntEnumerator().Take(5).ToList();

                updatedBuilder = ScpWorkflowBuilder.UpdateAndTrack(
                    builder: updatedBuilder,
                    seeds: seeds,
                    mergeWithPrev: true,
                    tracker: tracker
                    );

                System.Diagnostics.Debug.WriteLine(tracker.PoolReport);

                tracker = tracker.Trim(1000);
            }


            Assert.AreEqual(updatedBuilder.InputEntities.Count, 3);
            Assert.IsNotNull(updatedBuilder.Entity);
            Assert.AreEqual(updatedBuilder.Seeds.Count(), 25);
        }
예제 #8
0
        public static UpdateGaVm GaConjOrbitVm()
        {
            var randy = Rando.Standard(Seed);
            var gasd  = randy.ToGaConjOrbitData(
                order: Order,
                sorterCount: SorterCount,
                sortableCount: SortableCount,
                stageCount: StageCount,
                sortableWinRate: SortableWinRate,
                sorterWinRate: SorterWinRate);

            var gaRet = new UpdateGaVm(
                gaSortingData: gasd,
                order: Order,
                width: GridSpan,
                height: GridSpan,
                sorterWinRate: SorterWinRate,
                sortableWinRate: SortableWinRate,
                sorterCount: SorterCount,
                stageCount: StageCount,
                sortableCount: SortableCount,
                proc: ProcScheme5,
                update_params: UpdateParams);

            return(gaRet);
        }
예제 #9
0
        public static UpdateGaVm Direct()
        {
            var randy = Rando.Standard(Seed);
            var gasd  = randy.ToDirectGaSortingData(
                order: Order,
                sorterCount: SorterCount,
                sortableCount: SortableCount,
                stageCount: StageCount,
                sortableWinRate: SortableWinRate,
                sorterWinRate: SorterWinRate,
                stageReplacementMode: StageReplacementMode);

            var gaRet = new UpdateGaVm(
                gaSortingData: gasd,
                order: Order,
                width: GridSpan,
                height: GridSpan,
                sorterWinRate: SorterWinRate,
                sortableWinRate: SortableWinRate,
                sorterCount: SorterCount,
                stageCount: StageCount,
                sortableCount: SortableCount,
                proc: ProcScheme2,
                update_params: UpdateParams);

            return(gaRet);
        }
예제 #10
0
        public void TestSortliness()
        {
            var       seed   = 1223;
            const int order  = 24;
            const int trials = 5000;
            var       randy  = Rando.Standard(seed);

            for (var i = 0; i < trials; i++)
            {
                var stagey  = randy.ToFullSorterStage(order, 0);
                var stagey2 = randy.ToFullSorterStage(order, 0);
                var stagey3 = randy.ToFullSorterStage(order, 0);
                var stagey4 = randy.ToFullSorterStage(order, 0);

                var permy = randy.ToPermutation(order);

                var strey0 = stagey.Sort(permy);
                var strey2 = stagey2.Sort(strey0.Item2);
                var strey3 = stagey3.Sort(strey2.Item2);
                var strey4 = stagey4.Sort(strey3.Item2);
                var strey5 = stagey.Sort(strey4.Item2);
                var strey6 = stagey2.Sort(strey5.Item2);
                var strey7 = stagey3.Sort(strey6.Item2);
                var strey8 = stagey4.Sort(strey7.Item2);

                var pr   = permy.SortednessSq();
                var psr0 = strey0.Item2.SortednessSq();
                var psr2 = strey8.Item2.SortednessSq();

                Console.WriteLine($"{pr} {psr0} {psr2}");
            }
        }
예제 #11
0
        public void TestSorterSort()
        {
            var        seed        = 1223;
            const uint order       = 24;
            var        permCount   = 2000u;
            var        sorterCount = 200u;
            var        randy       = Rando.Standard(seed);

            var permies = 0u.CountUp(permCount)
                          .Select(i => randy.ToPermutation(order).ToSortable())
                          .ToList();

            var sorters = 0u.CountUp(sorterCount)
                          .Select(i => randy.ToSorter(order, i))
                          .ToList();

            for (var i = 0; i < sorterCount; i++)
            {
                var res = permies.Select(p => sorters[i].Sort(p)).ToList();
                for (var j = 0; j < res.Count(); j++)
                {
                    Console.WriteLine($"{j} {i} {res[j].Sortedness}");
                }
            }
        }
예제 #12
0
 public override void Update()
 {
     if (!this._created)
     {
         this._created = true;
     }
     if (this._sprite.frame > this._smokeFrame && !this._smoked)
     {
         int num = Graphics.effectsLevel == 2 ? Rando.Int(1, 4) : 1;
         for (int index = 0; index < num; ++index)
         {
             SmallSmoke smallSmoke = SmallSmoke.New(this.x + Rando.Float(-5f, 5f), this.y + Rando.Float(-5f, 5f));
             smallSmoke.vSpeed = Rando.Float(0.0f, -0.5f);
             smallSmoke.xscale = smallSmoke.yscale = Rando.Float(0.2f, 0.7f);
             Level.Add((Thing)smallSmoke);
         }
         this._smoked = true;
     }
     if ((double)this._wait <= 0.0)
     {
         this.y += this.vSpeed;
     }
     if (!this._sprite.finished)
     {
         return;
     }
     Level.Remove((Thing)this);
 }
예제 #13
0
        public DubstepGun(float xval, float yval)
            : base(xval, yval)
        {
            PlayBinding = new StateBinding("Playing");

            _bio        = "Plays generic dubstep loop and destroys everything";
            _editorName = "Dubstep Gun";

            ammo      = LoopTimings.Length + Rando.Int(-5, 5);
            _ammoType = new ATGrenade();
            _type     = "gun";

            sprite = new SpriteMap(DuckUtils.GetAsset("weapons/dubstep_gun.png"), 16, 16);
            sprite.AddAnimation("anim", Maths.IncFrameTimer() * 4f, true, 0, 1, 2, 3);
            sprite.SetAnimation("anim");
            graphic = sprite;
            center  = new Vec2(8f, 10f);

            sound = SFX.Get(DuckUtils.GetAsset("sounds/dubstep_sample.wav"), 1f, 0f, 0f, false);

            collisionOffset = new Vec2(-8f, -6f);
            collisionSize   = new Vec2(16f, 11f);
            _barrelOffsetTL = new Vec2(16f, 6f);
            _fireSound      = "pistolFire";
            _kickForce      = 3f;
            _holdOffset     = new Vec2(-1f, 0f);
            loseAccuracy    = 0.1f;
            maxAccuracyLost = 1f;
            physicsMaterial = PhysicsMaterial.Metal;
        }
예제 #14
0
        public override void PopShell(float x, float y, int dir)
        {
            PistolShell pistolShell = new PistolShell(x, y);

            pistolShell.hSpeed = (float)dir * (1.5f + Rando.Float(1f));
            Level.Add((Thing)pistolShell);
        }
예제 #15
0
        public void Example002()
        {
            String tmpFile = System.IO.Path.GetTempFileName();

            this.testFiles.Add(tmpFile);

            int rowCount = Rando.RandomInt(1000, 100000);

            var ht = new Hashtable();

            ht.Add("one", "IPv4");
            ht.Add("two", "Word");
            ht.Add("three", "EmailSimple:10");
            ht.Add("four", "Hex:5");
            ht.Add("five", "datetime:yyyy-MM-ddTHH:mm:ss");

            ps.AddCommand("New-RandomCSVFile")
            .AddParameter("RowCount", rowCount)
            .AddParameter("IncludeHeader", true)
            .AddParameter("Columns", ht)
            .AddParameter("OutputFile", tmpFile);

            var list = this.DoInvoke <FileInfo>();

            Assert.AreEqual(1, list.Count);

            VerifyCSVFile(tmpFile, ",", rowCount + 1, 5, null);
        }
예제 #16
0
        private static Shapes GetRandomShape()
        {
            List <Shapes> list = Enum.GetValues(typeof(Shapes)).Cast <Shapes>().ToList();

            list.Remove(Shapes.RandomShape);
            return(Rando.RandomPick <Shapes>(list));
        }
예제 #17
0
        public void DigitOnlyTest()
        {
            String tmpFile = System.IO.Path.GetTempFileName();

            this.testFiles.Add(tmpFile);
            long size = Rando.RandomInt(500, 5000);

            ps.AddCommand("New-RandomFile")
            .AddParameter("Size", size)
            .AddParameter("OutputFile", tmpFile)
            .AddParameter("StringType", "Digits");

            var list = this.DoInvoke <FileInfo>();

            Assert.AreEqual(1, list.Count);

            foreach (var hr in list)
            {
                Assert.AreEqual(size, hr.Length);
                Assert.AreEqual(tmpFile, hr.FullName);

                Char[] text = System.IO.File.ReadAllText(hr.FullName).ToCharArray();
                for (int i = 0; i < text.Length; i++)
                {
                    Char c = text[i];
                    Assert.IsTrue(Char.IsDigit(c), String.Format("Character is not a digit: '{0}',{1}", c, i));
                }
            }
        }
        public void TestMutateInsertDelete()
        {
            var stopwatch   = new Stopwatch();
            var origList    = Enumerable.Repeat(0, 1000).ToList();
            var randoMutate = Rando.Fast(123);
            var randoInsert = Rando.Fast(1234);
            var randoDelete = Rando.Fast(12345);

            stopwatch.Start();


            for (var i = 0; i < 1000; i++)
            {
                var insertedList = origList.MutateInsertDelete
                                   (
                    doMutation:  randoMutate.ToBoolEnumerator(0.1),
                    doInsertion: randoInsert.ToBoolEnumerator(0.1),
                    doDeletion:  randoDelete.ToBoolEnumerator(0.1),
                    mutator:     x => 0,
                    inserter:    x => 1,
                    paddingFunc:     x => 100000
                                   ).ToList();

                var sum = insertedList.Sum(t => t);
                Assert.AreEqual(insertedList.Count, 1000);
            }

            stopwatch.Stop();

            Debug.WriteLine("Time(ms): {0}", stopwatch.ElapsedMilliseconds);
        }
예제 #19
0
        private static String CombineNameForEmail(String firstname, String lastname)
        {
            String ans;
            var    i = Rando.RandomInt(0, 10);

            switch (i)
            {
            case 0:
                ans = firstname + lastname;
                break;

            case 1:
                ans = firstname + "_" + lastname;
                break;

            case 2:
                ans = firstname + lastname[0];
                break;

            case 3:
                ans = firstname[0] + lastname;
                break;

            case 4:
                ans = lastname + firstname[0] + firstname[1];
                break;

            default:
                ans = firstname + "." + lastname;
                break;
            }
            return(ans.Replace("'", ""));
        }
예제 #20
0
        public static List <Brush> RandomSolidBrushes(int seed, int brushCount)
        {
            if (_randomSolidBrushes != null)
            {
                return(_randomSolidBrushes);
            }
            _randomSolidBrushes = new List <Brush>();
            var randy = Rando.Fast(seed);

            for (int i = 0; i < brushCount; i++)
            {
                var scb = new SolidColorBrush(
                    new Color
                {
                    ScA = (float)1.0,
                    ScB = (float)randy.NextDouble(),
                    ScG = (float)randy.NextDouble(),
                    ScR = (float)randy.NextDouble()
                });

                scb.Freeze();
                _randomSolidBrushes.Add(scb);
            }

            return(_randomSolidBrushes);
        }
예제 #21
0
 public override void Update()
 {
     base.Update();
     if (!this.destroyed && !this._stuck)
     {
         if (!this.burning && Level.CheckCircle <SmallFire>(this.position, 8f) != null)
         {
             this.burning = true;
             this.onFire  = true;
             Level.Add((Thing)SmallFire.New(0.0f, 0.0f, 0.0f, 0.0f, stick: ((MaterialThing)this), firedFrom: ((Thing)this)));
             SFX.Play("ignite", Rando.Float(0.9f, 1f), Rando.Float(-0.2f, 0.2f));
         }
         this._sprite.frame = 0;
         this.angleDegrees  = -Maths.PointDirection(Vec2.Zero, new Vec2(this.hSpeed, this.vSpeed));
     }
     if (this._stuck)
     {
         this.vSpeed         = 0.0f;
         this.hSpeed         = 0.0f;
         this.grounded       = true;
         this._sprite.frame  = 1;
         this._stickTime    -= 0.01f;
         this.gravMultiplier = 0.0f;
     }
     if ((double)this._stickTime > 0.0 || this.destroyed)
     {
         return;
     }
     this.Destroy((DestroyType) new DTFade());
 }
        private IScpWorkflow ReproStep(int seed)
        {
            var randy = Rando.Fast(seed);

            var sorterLayer1 = SorterLayer0.Reproduce
                               (
                seed: randy.NextInt(),
                newGenomeCount: ScpParams.ChildCount,
                mutationRate: ScpParams.SorterMutationRate,
                insertionRate: ScpParams.SorterMutationRate,
                deletionRate: ScpParams.SorterDeletionRate
                               );

            //sorterLayer1 = sorterLayer1.Recombinate(ScpParams.SorterRecombinationRate, randy.NextInt());

            return(new ScpWorkflowImpl
                   (
                       compWorkflowState: CompWorkflowState.RunCompetition,
                       sorterLayer0: _sorterLayer0,
                       sorterLayer1: sorterLayer1,
                       compPool: CompPool,
                       sorterLayerEval: SorterLayerEval,
                       scpParams: ScpParams,
                       generation: Generation,
                       report: string.Empty
                   ));
        }
예제 #23
0
        public override bool Hit(Bullet bullet, Vec2 hitPos)
        {
            if (_equippedDuck == null || bullet.owner == duck || !bullet.isLocal)
            {
                return(false);
            }

            var particleEnd =
                hitPos
                + (bullet.travelDirNormalized * bullet.bulletSpeed
                   * 3)
                + new Vec2(Rando.Float(-5f, 5f), Rando.Float(-5f, 5f));

            for (int i2 = 0; i2 < 3; i2++)
            {
                Level.Add(DotParticle.New(
                              hitPos.x + Rando.Float(-2f, 2f),
                              hitPos.y + Rando.Float(-2f, 2f),
                              () => particleEnd,
                              bullet.color.Add(new Color(
                                                   (byte)Rando.Int(-15, 15),
                                                   (byte)Rando.Int(-15, 15),
                                                   (byte)Rando.Int(-15, 15)
                                                   )),
                              0.2f));
            }
            SFX.Play("scimiSurge", 0.8f, Rando.Float(-0.2f, 0.2f));
            return(true);
        }
        public override void BulletRemove()
        {
            NovaExp n = new(x, y, true);

            n.xscale *= 2.25f;
            n.yscale *= 2.25f;
            Level.Add(n);
            SFX.PlaySynchronized("explode", 0.8f, Rando.Float(-0.1f, 1f), 0f, false);
            if (isServerForObject)
            {
                IEnumerable <MaterialThing> things = Level.CheckCircleAll <MaterialThing>(position, 25f);
                foreach (MaterialThing t2 in things)
                {
                    if (t2 != BulletSafeDuck)
                    {
                        t2.Destroy(new DT_ThingBullet(this));
                    }
                }

                for (int i = 0; i < 6; i++)
                {
                    var bullet = new ArcaneNova_Magic_Stage3(position, GetBulletVecDeg(Rando.Float(0, 360), 6), BulletSafeDuck);
                    Level.Add(bullet);
                }
            }
            base.BulletRemove();
        }
예제 #25
0
 public override void Update()
 {
     this.timer -= 0.01f;
     if (timer <= 0 && !exploded)
     {
         exploded = true;
         float num1 = this.y - 2f;
         for (int index = 0; index < 20; ++index)
         {
             float      num2       = (float)((double)index * 18.0 - 5.0) + Rando.Float(10f);
             ATShrapnel atShrapnel = new ATShrapnel();
             atShrapnel.range = 60f + Rando.Float(18f);
             Bullet bullet = new Bullet(x + (float)(Math.Cos((double)Maths.DegToRad(num2)) * 6.0), num1 - (float)(Math.Sin((double)Maths.DegToRad(num2)) * 6.0), (AmmoType)atShrapnel, num2, (Thing)null, false, -1f, false, true);
             bullet.firedFrom = (Thing)this;
             Level.Add((Thing)bullet);
         }
         foreach (Window window in Level.CheckCircleAll <Window>(this.position, 40f))
         {
             if (Level.CheckLine <Block>(this.position, window.position, (Thing)window) == null)
             {
                 window.Destroy((DestroyType) new DTImpact((Thing)this));
             }
         }
     }
     if (exploded)
     {
         Level.Remove(this);
         Level.Remove(detonator);
     }
     if (this.owner as Duck != null)
     {
         var duck = (Duck)this.owner;
     }
     base.Update();
 }
예제 #26
0
        public void TestListPropigatorMutate()
        {
            const int startLen = 40;
            const int finalLen = 40;

            var lp = new ListPropigator <int>
                     (
                deletor: Deletor,
                deletionFrequency: 0.0,
                inserter: Inserter,
                insertionFrequency: 0.0,
                mutator: Mutator,
                mutationFrequency: 1.0,
                finalIndex: finalLen
                     );

            var randy = Rando.Fast(123);

            var track = new Tuple <IImmutableList <int>, int>
                        (
                ImmutableList <int> .Empty.AddRange(Enumerable.Range(0, startLen)),
                0
                        );

            while (track.Item2 < lp.FinalIndex)
            {
                track = lp.Propigate(track.Item1, randy, track.Item2);
            }

            Assert.AreEqual(track.Item1.Count, finalLen);
            Assert.IsTrue(track.Item1.All(t => t == 55));
        }
예제 #27
0
        protected override void CreateExplosion(Vec2 pos)
        {
            float x = pos.x;
            float y = pos.y - 2f;

            Level.Add(new Frog(x, y, Rando.Double() < 0.5f));

            int amount = Rando.Int(2, 4);

            for (int i = 0; i < amount; i++)
            {
                float deg = (float)i * 360f / amount + Rando.Float(-10f, 10f);
                float rad = Maths.DegToRad(deg);

                float xDir = (float)Math.Cos(rad);
                float yDir = (float)Math.Sin(rad);

                Frog thing = new Frog(x, y, xDir > 0);
                thing.hSpeed = xDir * 3;
                thing.vSpeed = yDir * yDir * -3 - 2;

                Level.Add(thing);
            }

            for (int i = 0; i < 3; i++)
            {
                Level.Add(SmallSmoke.New(x + Rando.Float(-8f, 8f), y + Rando.Float(-8f, 8f)));
            }
        }
예제 #28
0
        public void QuoteAll_False()
        {
            String tmpFile = System.IO.Path.GetTempFileName();

            this.testFiles.Add(tmpFile);

            int rowCount = Rando.RandomInt(50, 100);

            var ht = new Hashtable();

            ht.Add("one", "Sentence");
            ht.Add("two", "Domain");
            ht.Add("three", "Name");

            ps.AddCommand("New-RandomCSVFile")
            .AddParameter("RowCount", rowCount)
            .AddParameter("IncludeHeader", true)
            .AddParameter("QuoteAll", false)
            .AddParameter("Columns", ht)
            .AddParameter("OutputFile", tmpFile);

            var list = this.DoInvoke <FileInfo>();

            Assert.AreEqual(1, list.Count);

            VerifyCSVFile(tmpFile, ",", rowCount + 1, null, false);
        }
예제 #29
0
        public static ILayer <ISorterGenome> Recombinate
        (
            this ILayer <ISorterGenome> sorterGenomeLayer,
            double recombinationRate,
            int seed
        )
        {
            var rando = Rando.Fast(seed);

            var listGenomes = sorterGenomeLayer.Genomes
                              .ToList();

            var pairedGenomes = listGenomes.PairRandomly(rando.Spawn());

            var recombinedGenomes = pairedGenomes.Select(p => p.Recombine(rando.Spawn(), recombinationRate))
                                    .SelectMany(rp => new[] { rp.Item1, rp.Item2 })
                                    .ToList();

            //System.Diagnostics.Debug.WriteLine(recombinedGenomes.Select(g=>g.ParentGuid).Aggregate(string.Empty, (o,n) => o + " " + n.ToString()));

            return(Make
                   (
                       recombinedGenomes,
                       sorterGenomeLayer.Generation
                   ));
        }
예제 #30
0
파일: GaProc.cs 프로젝트: tp-nscan/CudaClr
        public static ProcResult Scheme4(int steps, GaData gasd)
        {
            var randy      = Rando.Standard(gasd.Data.GetSeed());
            var strRet     = String.Empty;
            var _stopwatch = new Stopwatch();

            _stopwatch.Reset();
            _stopwatch.Start();

            for (var i = 0; i < steps; i++)
            {
                gasd = gasd.EvolveStageDimerSortersAndSortables(randy);
                gasd.Data.SetCurrentStep(gasd.Data.GetCurrentStep() + 1);
            }

            _stopwatch.Stop();
            gasd.Data.SetSeed(randy.NextInt());

            var dRet = new Dictionary <string, object>();

            dRet.SetGaSortingData(gasd);
            return(new ProcResult(data: dRet,
                                  err: strRet,
                                  stepsCompleted: steps,
                                  time: _stopwatch.ElapsedMilliseconds));
        }