Esempio n. 1
0
        public override void Run()
        {
            base.Run();
            GameObject currentVehicle = VTOLAPI.instance.GetPlayersVehicleGameObject();

            ModuleEngine[] engines = currentVehicle.GetComponentsInChildren <ModuleEngine>();

            System.Random rand  = new System.Random();
            int           index = rand.Next(engines.ToList().Count());

            Debug.Log($"Total Engines: {engines.ToList().Count()}");

            if (!engines[index].failed)
            {
                Debug.Log($"Failing Engine {index}");
                engines[index].FailEngine();
                if (rand.Next(1, 100) < 80)
                {
                    Debug.Log($"Unfailing Engine {index}");
                    StartCoroutine(unfailEngine(index, engines));
                }
                else
                {
                    Debug.Log($"Engine {index} is permanently failed");
                }
            }
        }
Esempio n. 2
0
        public void RemoveTest()
        {
            int num  = 50000;
            var list = new SortSet <int, int>();
            var lst  = new List <int>();
            var rand = new System.Random();

            for (var i = 0; i < num; i++)
            {
                var val = rand.Next();
                lst.Add(val);
                list.Add(val, val);
            }

            foreach (int n in lst)
            {
                list.Remove(n);
            }

            foreach (var val in list)
            {
                Assert.Fail();
                if (val < 0)
                {
                }
            }

            if (list.Count != 0)
            {
                Assert.Fail();
            }
        }
        private List <MedicationSchedule> ParseResultFromUrl(string res)
        {
            var random = new System.Random(1);
            var id     = CurrentTimeMillis();

            if (res != null)
            {
                var medicationScheduleList = new List <MedicationSchedule>();
                var results = new JSONArray(res);

                for (var i = 0; i < results.Length(); i++)
                {
                    var    obj             = (JSONObject)results.Get(i);
                    string uuid            = obj.GetString("uuid");
                    string timestampString = obj.GetString("timestamp");
                    string title           = obj.GetString("title");
                    string content         = obj.GetString("content");
                    var    postpone        = Convert.ToInt32(obj.GetString("postpone"));

                    id += 10;

                    medicationScheduleList.Add(new MedicationSchedule(uuid, timestampString, title, content, postpone, id));
                    Log.Error(Log_Tag, "MEDICATIONSTRING " + timestampString);
                }
                return(medicationScheduleList);
            }
            return(null);
        }
Esempio n. 4
0
        public void GetRankTest()
        {
            for (var _ = 0; _ < 100; _++)
            {
                var num  = 100;
                var list = new SortSet <int, int>();
                var lst  = new List <int>();
                var rand = new System.Random();

                for (var i = 0; i < num; i++)
                {
                    if (rand.NextDouble() < 0.1)
                    {
                        lst.Add(i);
                    }
                    list.Add(i, i);
                }

                foreach (var n in lst)
                {
                    if (list.GetRank(n) != n)
                    {
                        Assert.Fail();
                    }
                }

                Assert.AreEqual(-1, list.GetRank(-1));
            }
        }
Esempio n. 5
0
    // Use this for initialization
    void Awake()
    {
        firePoint = gameObject.transform.Find("Firepoint");
        rand      = new System.Random();

        // to ensure ammunition flies faster than players
        PlayerSpaceshipController shipController = GetComponent <PlayerSpaceshipController>();

        if (shipController != null)
        {
            //Speed += shipController.AccelerationForce;
            playerId = shipController.PlayerId;
        }

        if (firePoint == null)
        {
            Debug.LogError("Firepoint was null. Is child missing or named wrong?");
        }


        ProjectileLogic projectileLogic = null;

        foreach (GameObject ammuType in Ammunition)
        {
            projectileLogic = ammuType.GetComponent <ProjectileLogic>();

            if (projectileLogic == null)
            {
                Debug.LogError("Ammunition \"" + ammuType.name + "\" does not have ProjectileLogic component.");
            }
        }
    }
Esempio n. 6
0
    private PlayerSkills.BaseSkill GetMarcEnergySkill()
    {
        PlayerSkills.BaseSkill skill = player.GetComponent <PlayerSkills>().fireball;
        var random  = new System.Random();
        var skillID = random.Next(0, 5);

        switch (skillID)
        {
        case 0:
            skill = player.GetComponent <PlayerSkills>().warcry;
            break;

        case 1:
            skill = player.GetComponent <PlayerSkills>().berserk;
            break;

        case 2:
            skill = player.GetComponent <PlayerSkills>().feelNoPain;
            break;

        case 3:
            skill = player.GetComponent <PlayerSkills>().rushdown;
            break;

        case 4:
            skill = player.GetComponent <PlayerSkills>().offering;
            break;
        }

        return(skill);
    }
Esempio n. 7
0
    private PlayerSkills.BaseSkill GetVincentEnergySkill()
    {
        PlayerSkills.BaseSkill skill = player.GetComponent <PlayerSkills>().fireball;
        var random  = new System.Random();
        var skillID = random.Next(0, 5);

        switch (skillID)
        {
        case 0:
            skill = player.GetComponent <PlayerSkills>().fireball;
            break;

        case 1:
            skill = player.GetComponent <PlayerSkills>().lightning;
            break;

        case 2:
            skill = player.GetComponent <PlayerSkills>().rushdown;
            break;

        case 3:
            skill = player.GetComponent <PlayerSkills>().offering;
            break;

        case 4:
            skill = player.GetComponent <PlayerSkills>().healingWave;
            break;
        }

        return(skill);
    }
        private IEnumerator FlashLightsRandom()
        {
            var colorList = new List <Color> {
                Color.black, Color.green, Color.red, Color.yellow
            };

            System.Random rand      = new System.Random();
            int           index     = rand.Next(colorList.Count);
            Color         randColor = colorList[index];

            double randWait = rand.NextDouble();

            if (gear != null && gear.statusLight != null)
            {
                gear.statusLight.toggleColor = randColor;
                gear.statusLight.Toggle();
            }
            else
            {
                Debug.Log("It seems gear or statuslight is null");
            }
            yield return(new WaitForSeconds((float)randWait));

            if (running)
            {
                this.StartCoroutine(FlashLightsRandom());
            }
        }
Esempio n. 9
0
        public Vector2[] SamplePositions(System.Random random)
        {
            Vector2[] samples = null;
            switch (DistributionType)
            {
            case Distribution.PoissonDisc:
                samples = GetPoissonGridSamples(random);
                break;

            case Distribution.Uniform:
                samples = GetUniformSamples();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            DetailModifierNode mod = GetInputValue <DetailModifierNode>("Modifier");

            if (mod != null)
            {
                return(mod.SamplePositions(samples, random));
            }

            return(samples);
        }
Esempio n. 10
0
        public void AddElementTest()
        {
            //var list2 = new SortSet<object, int>();
            int num  = 50000;
            var list = new SortSet <int, int>();
            var rand = new System.Random();

            for (var i = 0; i < num; i++)
            {
                var val = rand.Next();
                list.Add(val, val);
                //list.Add(i,i);
            }

            var max = 0;

            foreach (var val in list)
            {
                if (max <= val)
                {
                    max = val;
                }
                else
                {
                    Assert.Fail();
                }
            }
        }
Esempio n. 11
0
        // Start is called before the first frame update
        void Start()
        {
            _random         = new System.Random(randomSeed);
            _campfireLights = new List <Light>(GetCampfireLights());
            _lightIntensity = new List <float>();

            foreach (var light in _campfireLights)
            {
                _lightIntensity.Add(light.intensity);
            }

            // Avoid light flicker overlapping
            if (numberPrimes < _campfireLights.Count * 2)
            {
                numberPrimes = _campfireLights.Count * 2;
            }

            _primes = new List <int>(GetPrimes(numberPrimes));

            // Select primes from the list for each light
            _intervals = new List <FlickerInterval>();
            foreach (var campfireLight in _campfireLights)
            {
                var interval = GetInterval(_primes, _random);
                _intervals.Add(new FlickerInterval(
                                   campfireLight,
                                   interval,
                                   maxFlickerDuration,
                                   _random));
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Generate a valid credit card number based on provider using Luhn's (Mod10) formula.
        /// </summary>
        /// <returns>The random valid credit card number.</returns>
        public string GetRandomValidCreditCardNumber(CreditCard provider)
        {
            bool   isValid = false;
            string fakeCreditCardNumber = "";

            while (!isValid)
            {
                System.Random r = new System.Random();
                fakeCreditCardNumber = provider.Prefix.ToString();

                //Build out randomized number that is 16 digits long.
                while (fakeCreditCardNumber.Length < 16)
                {
                    fakeCreditCardNumber += r.Next(0, 10);
                }

                List <char> ccChar         = fakeCreditCardNumber.ToCharArray().ToList();
                List <char> reversedNumber = ccChar;
                reversedNumber.Reverse();
                char check_digit = reversedNumber.First();
                reversedNumber.RemoveAt(0);

                var sum = 0;
                for (var x = 0; x < reversedNumber.Count; x++)
                {
                    var current_sum = 0;
                    //Double every other value.
                    if (x % 2 == 0)
                    {
                        var doubled_sum = reversedNumber[x].ToString().ToInt() * 2;
                        if (doubled_sum >= 10)
                        {
                            current_sum = doubled_sum.ToString()[0].ToString().ToInt() + doubled_sum.ToString()[1].ToString().ToInt();
                        }
                        else
                        {
                            current_sum = doubled_sum;
                        }
                    }
                    else
                    {
                        current_sum = reversedNumber[x].ToString().ToInt();
                    }

                    sum += current_sum;
                }

                string new_sum = (sum * 9).ToString();
                if (new_sum[new_sum.Length - 1].ToString().ToInt() == check_digit.ToString().ToInt())
                {
                    isValid = true;
                    break;
                }

                fakeCreditCardNumber = "";
            }

            return(fakeCreditCardNumber);
        }
Esempio n. 13
0
 public int Get(System.Random random)
 {
     if (Min == Max)
     {
         return(Min);
     }
     return(random.Next(Min, Max));
 }
Esempio n. 14
0
 internal Test(String name, String[] data, Collator collator, System.Random r, Control control)
 {
     this.name     = name;
     this.data     = data;
     this.collator = collator;
     this.control  = control;
     this.r        = r;
 }
Esempio n. 15
0
        /// <summary>
        /// 创建随机的字符区域编码
        /// </summary>
        /// <param name="length">要随机的长度</param>
        /// <returns></returns>
        private object[] CreateRegionCode(int length)
        {
            //定义一个字符串数组储存汉字编码的组成元素
            string[] rBase = new String[16] {
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"
            };
            var rnd = new System.Random();

            //定义一个object数组用来
            object[] bytes = new object[length];

            /*每循环一次产生一个含两个元素的十六进制字节数组,并将其放入byte数组中
             * 每个汉字有四个区位码组成
             * 区位码第1位和区位码第2位作为字节数组第一个元素
             * 区位码第3位和区位码第4位作为字节数组第二个元素
             */
            for (int i = 0; i < length; i++)
            {
                //区位码第1位
                int    r1     = rnd.Next(11, 14);
                string str_r1 = rBase[r1].Trim();
                //区位码第2位
                rnd = new Random(r1 * Guid.NewGuid().GetHashCode() + i);//更换随机数发生器的种子避免产生重复值
                var    r2     = rnd.Next(0, r1 == 13 ? 7 : 16);
                string str_r2 = rBase[r2].Trim();
                //区位码第3位
                rnd = new Random(r2 * Guid.NewGuid().GetHashCode() + i);
                int    r3     = rnd.Next(10, 16);
                string str_r3 = rBase[r3].Trim();
                //区位码第4位
                rnd = new Random(r3 * Guid.NewGuid().GetHashCode() + i);
                int r4;
                switch (r3)
                {
                case 10:
                    r4 = rnd.Next(1, 16);
                    break;

                case 15:
                    r4 = rnd.Next(0, 15);
                    break;

                default:
                    r4 = rnd.Next(0, 16);
                    break;
                }

                string str_r4 = rBase[r4].Trim();
                //定义两个字节变量存储产生的随机汉字区位码
                byte byte1 = Convert.ToByte(str_r1 + str_r2, 16);
                byte byte2 = Convert.ToByte(str_r3 + str_r4, 16);
                //将两个字节变量存储在字节数组中
                byte[] str_r = { byte1, byte2 };
                //将产生的一个汉字的字节数组放入object数组中
                bytes.SetValue(str_r, i);
            }
            return(bytes);
        }
Esempio n. 16
0
    private void AimTower()
    {
        var v1 = _player.transform.position;
        var v2 = _tower.transform.position;

        if (v2.z < 0)
        {
            Random rnd = new System.Random();
            float  x   = -1;
            float  y   = -1;
            while (x <= 3.1f || x >= 20 || y >= 9 || y <= 3.1f)
            {
                x = 3.1f + (float)(rnd.NextDouble() * (20 - 3.1f + 1));
                y = 3.1f + (float)(rnd.NextDouble() * (9 - 3.1f + 1));
                if (x > _player.transform.position.x - 0.5f && x < _player.transform.position.x + 0.5f)
                {
                    if (y > _player.transform.position.y - 0.5f && y < _player.transform.position.y + 0.5f)
                    {
                        x = -1;
                        y = -1;
                    }
                }
            }
            _tower.transform.position = new Vector3(x, y, 0);
            return;
        }

        var angleBetween = Mathf.Atan2(v2.y - v1.y, v2.x - v1.x) * 180 / Mathf.PI - 90;

        if (_towerAngle < angleBetween)
        {
            _towerAngle += _rotSpeed / 3;
        }
        else
        {
            _towerAngle -= _rotSpeed / 3;
        }
        _tower.transform.rotation = Get2DAngle(_towerAngle);

        if (myTimer2 == 0)
        {
            myTimer2 = 50;

            var obj    = (GameObject)Instantiate(_bullet, v2, Get2DAngle(0));
            var bullet = new BulletInfo(obj, _towerAngle + 90);

            var pos = bullet.Position;
            pos.x          -= 0.7f * Mathf.Cos((_towerAngle + 90) * Mathf.PI / 180);
            pos.y          -= 0.7f * Mathf.Sin((_towerAngle + 90) * Mathf.PI / 180);
            bullet.Position = pos;

            _bullets.Add(bullet);

            AudioSource.PlayClipAtPoint(shot, v2);
        }
    }
Esempio n. 17
0
        private void GenerateEnemy(int size)
        {
            var random = new System.Random();

            if (Enemy == null)
            {
                Enemy = GameObject.FindWithTag("Enemy");
            }
            AddElement(Enemy, random.Next(size) / 2, 1, random.Next(size) / 2, 1, 0);
        }
Esempio n. 18
0
 private void Start()
 {
     dropZoneParent = GameObject.Find("DropZones");
     rng            = new System.Random();
     coolDown       = 60f;
     onCoolDown     = false;
     dropzones      = dropZoneParent.transform.childCount;
     prompted       = false;
     state          = true;
 }
Esempio n. 19
0
 private static void Scramble(String[] data, System.Random r)
 {
     for (int i = 0; i < data.Length; ++i)
     {
         int    ix = r.Next(data.Length);
         String s  = data[i];
         data[i]  = data[ix];
         data[ix] = s;
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        nextMovementType = new Random();
        nextMonster      = new Random();

        nextMovementType2 = new Random();
        nextMonster2      = new Random();

        randomRandoms = new Random();
    }
    int[] getRanArray(int pCurrentN, System.Random pRand)
    {
        int[] randArr = new int[pCurrentN];
        int   n       = randArr.Length;

        for (int i = 0; i < n; i++)
        {
            randArr[i] = pRand.Next(1, 101);
        }
        return(randArr);
    }
    void OnTriggerEnter(Collider other)
    {
        System.Random r    = new System.Random();
        int           rInt = r.Next(0, 100);

        Debug.Log("A");
        if (probability > rInt)
        {
            Debug.Log("Dead");
            EventController.current.ChangeMode("finish", "You get burn");
        }
    }
Esempio n. 23
0
        private IEnumerator ExplodeCreature(Creature creature, Vector3 dir)
        {
            var random = new System.Random();

            while (Time.time - creature.spawnTime <= 2)
            {
                yield return(new WaitForFixedUpdate());
            }

            string[] parts =
            {
                "LeftHand",  "LeftForeArm",  "LeftArm",
                "RightHand", "RightForeArm", "RightArm",
                "LeftFoot",  "LeftLeg",
                "RightFoot", "RightLeg",
                "Head"
            };

            int index = 0;

            while (index < parts.Length)
            {
                foreach (var part in creature.ragdoll.parts)
                {
                    try
                    {
                        part.rb.AddForce((dir + Vector3.up),
                                         ForceMode.Impulse);

                        if (part.name == parts[index])
                        {
                            if (random.Next(1, 101) <= 50)
                            {
                                part.Slice();
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Debug.Log(exception.Message);
                    }
                }

                index++;
            }

            if (creature.state != Creature.State.Dead)
            {
                creature.Kill();
            }

            yield return(null);
        }
Esempio n. 24
0
        /// <summary>
        /// Creates a list of positions in the range of [0, 1] by
        /// running the poisson disc sampling algorithm.
        /// </summary>
        /// <param name="density">Density of the placement of objects</param>
        /// <param name="gridSize">Size of the grid to sample</param>
        /// <param name="random">Random number generator to sample</param>
        private Vector2[] GetPoissonGridSamples(float density, int gridSize, System.Random random)
        {
            PoissonDiscSampler pds   = new PoissonDiscSampler(gridSize, gridSize, density, random);
            List <Vector2>     total = new List <Vector2>();

            foreach (Vector2 sample in pds.Samples())
            {
                total.Add(sample / gridSize);
            }

            return(total.ToArray());
        }
Esempio n. 25
0
    private void Start()
    {
        energySkillOneImage.sprite = player.GetComponent <PlayerController>().energySkill1.icon;
        energySkillTwoImage.sprite = player.GetComponent <PlayerController>().energySkill2.icon;
        staminaSkillImage.sprite   = player.GetComponent <PlayerController>().staminaSkill.icon;
        _newSkill = GetNewSkill();
        var random  = new System.Random();
        var random1 = random.Next(0, 10);

        _newSkill.skillLevel = random1 > 6 ? 1 : 0;
        newSkillImage.sprite = _newSkill.icon;
    }
Esempio n. 26
0
    /// <summary>
    /// 字体随机颜色
    /// </summary>
    public System.Drawing.Color GetRandomColor()
    {
        System.Random RandomNum_First = new System.Random((int)DateTime.Now.Ticks);
        System.Threading.Thread.Sleep(RandomNum_First.Next(50));
        System.Random RandomNum_Sencond = new System.Random((int)DateTime.Now.Ticks);
        int           int_Red           = RandomNum_First.Next(180);
        int           int_Green         = RandomNum_Sencond.Next(180);
        int           int_Blue          = (int_Red + int_Green > 300) ? 0 : 400 - int_Red - int_Green;

        int_Blue = (int_Blue > 255) ? 255 : int_Blue;
        return(System.Drawing.Color.FromArgb(int_Red, int_Green, int_Blue));
    }
Esempio n. 27
0
 public float Get(System.Random random)
 {
     if (Math.Abs(Max) < 0.00001f && Math.Abs(Min) < 0.00001f)
     {
         return(0);
     }
     if (Max < Min)
     {
         return(random.NextFloat(Max, Min));
     }
     return(random.NextFloat(Min, Max));
 }
Esempio n. 28
0
 public Randomizer()
 {
     // It's tempting to seed the randomizer with the current time, but that's kind of
     // predictable, so instead, add a random time span to the current time and use that
     TimeSpan randomTime = new TimeSpan(
         GetBasicRandomNumber(365),
         GetBasicRandomNumber(24),
         GetBasicRandomNumber(60),
         GetBasicRandomNumber(60),
         GetBasicRandomNumber(1000));
     var seedTime = DateTime.Now.Add(randomTime);
     _mainCore = new System.Random((int)seedTime.Ticks);
 }
Esempio n. 29
0
        private GameObject FindPotentialListeningDeviceObject()
        {
            List <GameObject> potentialListeningDevices = GameObject.FindObjectsOfType <BuggableFurniture>().Select(x => x.gameObject).OfType <GameObject>().ToList();

            if (potentialListeningDevices.Count == 0)
            {
                return(null);
            }

            System.Random random      = new System.Random();
            int           randomIndex = random.Next(0, potentialListeningDevices.Count);

            return(potentialListeningDevices.ElementAt(randomIndex));
        }
Esempio n. 30
0
        public void Init(int seed)
        {
            for (int i = 0; i < Tiles.Length; i++)
            {
                Tiles[i].TileIndex = i;
            }


            cells = new Cell[OutputWidth * OutputHeight];
            for (int i = 0; i < cells.Length; i++)
            {
                cells[i] = new Cell(this, Tiles.Length);
            }

            for (int i = 0; i < cells.Length; i++)
            {
                (int x, int y) = SequentialToCoordinate(i);

                Cell right = null;
                Cell up    = null;
                Cell left  = null;
                Cell down  = null;

                int?rightIndex = CoordinateToSequential(x + 1, y);
                int?upIndex    = CoordinateToSequential(x, y - 1);
                int?leftIndex  = CoordinateToSequential(x - 1, y);
                int?downIndex  = CoordinateToSequential(x, y + 1);

                if (rightIndex != null)
                {
                    right = cells[rightIndex.Value];
                }
                if (upIndex != null)
                {
                    up = cells[upIndex.Value];
                }
                if (leftIndex != null)
                {
                    left = cells[leftIndex.Value];
                }
                if (downIndex != null)
                {
                    down = cells[downIndex.Value];
                }

                cells[i].Init(right, up, left, down);
            }

            random = new System.Random(seed);
        }
        public static int linear_fit_classification_rosenblatt(ref double[] model, double[,] inputs, double[] outputs, int iterationNumber, double step)
        {
            double[,] X = new double[inputs.GetLength(0), inputs.GetLength(1) + 1];
            for (int j = 0; j < inputs.GetLength(0); j++)
            {
                X[j, 0] = 1;
                for (int k = 0; k < inputs.GetLength(1); k++)
                {
                    X[j, k + 1] = inputs[j, k];
                }
            }

            System.Random random = new System.Random();

            int len1 = X.GetLength(1);

            double[,] rndInput = new double[len1, 1];
            double[] flatRndInput = new double[len1 - 1];
            double[,] rndOutput = new double[1, 1];

            for (int i = 0; i < iterationNumber; i++)
            {
                int num = random.Next(0, outputs.Length);

                for (int j = 0; j < len1; j++)
                {
                    rndInput[j, 0] = X[num, j];
                    if (j > 0)
                    {
                        flatRndInput[j - 1] = X[num, j];
                    }
                }

                rndOutput[0, 0] = outputs[num];

                double linearClassifyRes = linear_classify(ref model, flatRndInput);

                double[,] sub = new double[1, 1];
                sub[0, 0]     = linearClassifyRes;

                double[,] subRes      = SubstractMatrix(rndOutput, sub);
                double[,] multiplyRes = MultiplyMatrix(rndInput, subRes);
                double[,] rectModel   = ToRectangular(model, 1);

                rectModel = AdditionMatrix(rectModel, MultiplyMatrixScalar(step, multiplyRes));
                ToLinear(ref model, rectModel);
            }

            return(0);
        }
Esempio n. 32
0
    public Stage GenerateStage(int eventCount, int timeStep, bool shields, bool asteroids, bool bosses, bool colorsShifts, bool rotators)
    {
        var stage = new List<GameEvent> ();
        var currentColor = Colors.player;
        System.Random randGen = new System.Random ();
        //Set seeds!
        var firstShift = (int)eventCount / 3;
        var secondShift = (int)(eventCount * 2.0 / 3.0);
        for (int i = 0; i < eventCount; i++) {
          if (i == eventCount - 1 && bosses) {
        stage.Add (((GameEvent)new Boss (new Vector3 (0, 0, 0), 1, timeStep)));
        continue;
          }
          if (colorsShifts && (i == firstShift || i == secondShift)) {
        currentColor = ColorUtils.GetRandomBackgroundColor (currentColor, randGen);
        stage.Add ((GameEvent)new BackgroundShift (currentColor, timeStep));
        continue;
          }

          var spawns = new List<Spawn> ();

          foreach (var slot in RandomSample(Constants.slots, randGen, randGen.Next(2,5))) {
        var chance = randGen.NextDouble ();
        var position = new Vector3 (slot, 5, 1);
        var color = ColorUtils.GetRandomColorForBackground (currentColor, randGen);
        var cannons = new bool[8];
        for(int j=0; j<8; j++) {
          if((randGen.Next() % 3) == 0)
            cannons[j] = true;
          else
            cannons[j] = false;
        }

        if (cannons.All(f=>!f)) {
          var luckyCannon = randGen.Next () % 8;
              cannons [luckyCannon] = true;
        }
        spawns.Add (BuildSingleSpawn (position, cannons, shields,  asteroids, rotators, color, chance));
          }
          stage.Add ((GameEvent)new SpawnSet (spawns, timeStep));
        }
        return new Stage (stage);
    }