Esempio n. 1
0
 // Use this for initialization
 void Start()
 {
     pButton       = pauseButton.GetComponent <pauseButton>();
     bCollision    = stealthBomber.GetComponent <bomberCollision>();
     treeGenerator = obstaclesGenerator.GetComponent <generator>();
     points        = 0;
 }
Esempio n. 2
0
 private void FormTest_Load(object sender, EventArgs e)
 {
     _strand1 = new control_strand(this);
     _strand2 = new shared_strand();
     _action1 = generator.go(_strand1, Action1);
     _action2 = generator.go(_strand2, Action2);
 }
Esempio n. 3
0
        /*
         * --- Day 15: Dueling Generators ---
         * Here, you encounter a pair of dueling generators. The generators, called generator A and generator B, are trying to agree on a sequence of numbers. However, one of them is malfunctioning, and so the sequences don't always match.
         *
         * As they do this, a judge waits for each of them to generate its next value, compares the lowest 16 bits of both values, and keeps track of the number of times those parts of the values match.
         *
         * The generators both work on the same principle.
         * To create its next value, a generator will take the previous value it produced, multiply it by a factor (generator A uses 16807; generator B uses 48271),
         * and then keep the remainder of dividing that resulting product by 2147483647. That final remainder is the value it produces next.
         *
         * To calculate each generator's first value, it instead uses a specific starting value as its "previous value" (as listed in your puzzle input).
         *
         * For example, suppose that for starting values, generator A uses 65, while generator B uses 8921. Then, the first five pairs of generated values are:
         *
         * --Gen. A--  --Gen. B--
         * 1092455   430625591
         * 1181022009  1233683848
         * 245556042  1431495498
         * 1744312007   137874439
         * 1352636452   285222916
         * In binary, these pairs are (with generator A's value first in each pair):
         *
         * 00000000000100001010101101100111
         * 00011001101010101101001100110111
         *
         * 01000110011001001111011100111001
         * 01001001100010001000010110001000
         *
         * 00001110101000101110001101001010
         * 01010101010100101110001101001010
         *
         * 01100111111110000001011011000111
         * 00001000001101111100110000000111
         *
         * 01010000100111111001100000100100
         * 00010001000000000010100000000100
         * Here, you can see that the lowest (here, rightmost) 16 bits of the third value match: 1110001101001010. Because of this one match, after processing these five pairs, the judge would have added only 1 to its total.
         *
         * To get a significant sample, the judge would like to consider 40 million pairs. (In the example above, the judge would eventually find a total of 588 pairs that match in their lowest 16 bits.)
         *
         * After 40 million pairs, what is the judge's final count?
         */
        public override string Output(string input)
        {
            //input = "65,8921";
            var starts = input.Split(',');
            var genA   = new generator()
            {
                value = int.Parse(starts[0]), factor = 16807
            };
            var genB = new generator()
            {
                value = int.Parse(starts[1]), factor = 48271
            };
            int match = 0;

            for (var i = 0; i < 40000000; i++)
            {
                if (genA.next() == genB.next())
                {
                    match++;
                }
            }
            ;

            return(match.ToString());
        }
Esempio n. 4
0
    // Tries to spawn new generators as long as the max isn't reached
    public void SpawnGen(Vector2 dir, Vector2 pos, List <generator> genList)
    {
        generator newGen = new generator();

        newGen.dir = dir;
        newGen.pos = pos;
        genList.Add(newGen);
    }
 protected virtual generator GetGenerator(IColumnMetadata iColumnMetadata, ITableMetadata tableMetaData)
 {
     if (currentContext.TableExceptions.HasException(tableMetaData.Name, tableMetaData.Catalog, tableMetaData.Schema))
     {
         var exc = currentContext.TableExceptions.GetTableException(tableMetaData.Name, tableMetaData.Catalog, tableMetaData.Schema);
         if (exc.primarykey != null && exc.primarykey.generator != null)
         {
             generator g = new generator();
             g.@class = exc.primarykey.generator.@class;
             if (null != exc.primarykey.generator.param)
             {
                 List <param> parms = new List <param>();
                 foreach (var p in exc.primarykey.generator.param)
                 {
                     parms.Add(new param()
                     {
                         name = p.name, Text = new string[] { p.Value }
                     });
                 }
                 g.param = parms.ToArray();
             }
             return(g);
         }
     }
     logger.Info(string.Format("Table {0}: trying to infer id generator from schema", tableMetaData.Name));
     try{
         var dt         = GetCompleteColumnSchema(tableMetaData);
         int isIdentity = dt.Columns.IndexOf(ISIDENTITY);
         int colName    = dt.Columns.IndexOf(COLNAME);
         List <IColumnMetadata> cols = new List <IColumnMetadata>();
         foreach (DataRow dr in dt.Rows)
         {
             if (string.Compare(dr.ItemArray[colName].ToString(), iColumnMetadata.Name, true) == 0)
             {
                 if ((bool)dr.ItemArray[isIdentity])
                 {
                     return new generator()
                            {
                                @class = "native"
                            }
                 }
                 ;
                 else
                 {
                     return new generator()
                            {
                                @class = "assigned"
                            }
                 };
             }
         }
     }
     catch (Exception e)
     {
         logger.Warn(string.Format("Table {0}: unable to infer id generator from schema. Please consider to use configuration to specify it.", tableMetaData.Name), e);
     }
     return(null);
 }
Esempio n. 6
0
 // Moves all generators in their direciton on grid space
 public void MoveGen(List <generator> genList)
 {
     for (int i = 0; i < genList.Count; i++)
     {
         generator targetGen = genList[i];
         targetGen.pos += targetGen.dir;
         genList[i]     = targetGen;
     }
 }
Esempio n. 7
0
 // Prevents generator from moving to an edge of the grid
 public void ClampGen(List <generator> genList)
 {
     for (int i = 0; i < genList.Count; i++)
     {
         generator targetGen = genList[i];
         targetGen.pos.x = Mathf.Clamp(targetGen.pos.x, 1, gridWidth - 2);
         targetGen.pos.y = Mathf.Clamp(targetGen.pos.y, 1, gridHeight - 2);
         genList[i]      = targetGen;
     }
 }
Esempio n. 8
0
 private void WaitForm_Load(object sender, EventArgs e)
 {
     _action = generator.tgo(FormTest._mainStrand, async delegate()
     {
         while (true)
         {
             await generator.sleep(30);
             progressBar1.Value = (int)(system_tick.get_tick_ms() % 1000 / 10);
         }
     });
 }
Esempio n. 9
0
        static async Task Producer5(generator cons)
        {
            for (int i = 0; i < 10; i++)
            {
                await cons.send_msg(i);

                await generator.sleep(1000);

                await cons.send_msg((long)i);

                await generator.sleep(1000);
            }
        }
Esempio n. 10
0
 protected virtual generator GetGenerator(IColumnMetadata iColumnMetadata, ITableMetadata tableMetaData)
 {
     if (currentContext.TableExceptions.HasException(tableMetaData.Name, tableMetaData.Catalog, tableMetaData.Schema))
     {
         var exc = currentContext.TableExceptions.GetTableException(tableMetaData.Name, tableMetaData.Catalog, tableMetaData.Schema);
         if (exc.primarykey != null && exc.primarykey.generator != null)
         {
             generator g = new generator();
             g.@class = exc.primarykey.generator.@class;
             if (null != exc.primarykey.generator.param)
             {
                 List<param> parms = new List<param>();
                 foreach (var p in exc.primarykey.generator.param)
                 {
                     parms.Add(new param() { name = p.name, Text = new string[] { p.Value } });
                 }
                 g.param = parms.ToArray();
             }
             return g;
         }
     }
     logger.Info(string.Format("Table {0}: trying to infer id generator from schema",tableMetaData.Name));
     try{
         var dt = GetCompleteColumnSchema(tableMetaData);
         int isIdentity = dt.Columns.IndexOf(ISIDENTITY);
         int colName = dt.Columns.IndexOf(COLNAME);
         List<IColumnMetadata> cols = new List<IColumnMetadata>();
         foreach (DataRow dr in dt.Rows)
         {
             if (string.Compare(dr.ItemArray[colName].ToString(),iColumnMetadata.Name,true) == 0)
             {
                 if( (bool)dr.ItemArray[isIdentity] )
                     return new generator(){ @class="native" };
                 else
                     return new generator() { @class = "assigned" };
             }
         }
     }
     catch( Exception e)
     {
         logger.Warn(string.Format("Table {0}: unable to infer id generator from schema. Please consider to use configuration to specify it.", tableMetaData.Name),e);
     }
     return null;
 }
Esempio n. 11
0
            public MHKey()
            {
                generator  gen = new generator(8);
                BigInteger w   = gen.w;

                e = new List <BigInteger>();
                for (int i = 0; i < gen.a.Count; i++)
                {
                    e.Add(w.Multiply(gen.a.ElementAt(i)).Mod(gen.n)); // w*a Mod n ..
                }

                BigInteger w1  = BigInteger.ValueOf(1);
                BigInteger one = BigInteger.ValueOf(2);

                while (one.IntValue != 1)
                {
                    w1  = w1.Add(BigInteger.ValueOf(1)).Mod(gen.n);
                    one = w.Multiply(w1).Mod(gen.n);
                }
                privateKey = new MHPrivateKey(gen.a, w.ModInverse(gen.n), gen.n);
            }
    // pour dire que ça dérive de la classe éditor
    // éditeur gère ce qui se passe dans le moteur mais pas dans le jeu
    // les outils de pipeline facilite la création

    // 1 ==== PRIMARY FUNCTIONS ===
    public override void OnInspectorGUI()
    {
        // executer quand on fait qqchose dans le moteur (à chaque frame)
        DrawDefaultInspector();                  // on appelle la fonction mère et on lui dit fait comme d'hab
        generator my_target = (generator)target; // target= pté d'éditor

        if (GUILayout.Button("Add the body " + my_target.bodyName))
        {
            GameObject voxel_container = new GameObject(my_target.bodyName); // should contain all the voxels

            voxel_container.transform.parent   = my_target.transform;
            voxel_container.transform.position = my_target.position;
            voxel_container.AddComponent(typeof(VoxelsJoint));
            voxel_container.GetComponent <VoxelsJoint>().neighbors = new GameObject[my_target.x, my_target.y, my_target.z];

            for (int i = 0; i < my_target.x; i++)
            {
                for (int j = 0; j < my_target.y; j++)
                {
                    for (int k = 0; k < my_target.z; k++)
                    {
                        // instantiate the new object based on the prefab
                        voxel_container.GetComponent <VoxelsJoint>().neighbors[i, j, k] = (GameObject)PrefabUtility.InstantiatePrefab(my_target.modele);

                        // place it, accordingly to those who come before.
                        voxel_container.GetComponent <VoxelsJoint>().Place(voxel_container.GetComponent <VoxelsJoint>().neighbors[i, j, k], voxel_container.GetComponent <VoxelsJoint>().NewCoordinates(i, j, k, voxel_container.GetComponent <VoxelsJoint>().neighbors), voxel_container);

                        voxel_container.GetComponent <VoxelsJoint>().neighbors[i, j, k].tag  = "voxel";
                        voxel_container.GetComponent <VoxelsJoint>().neighbors[i, j, k].name = i.ToString() + "." + j.ToString() + "." + k.ToString(); // x then y then z
                    }
                }
            }
            //voxel_container.GetComponent<VoxelsJoint>().Init(my_target.x,my_target.y,my_target.z);
            //voxel_container.GetComponent<VoxelsJoint>().InitNeighbors();
        }
    }
Esempio n. 13
0
 GenerateExpression(generator, symbol, expression.LeftOperand);
Esempio n. 14
0
 private void FormTest_Load(object sender, EventArgs e)
 {
     _mainStrand = new control_strand(this);
     _timeAction = generator.tgo(_mainStrand, TimeAction);
 }
 internal InputGenerator(generator Generate)
 {
     this.Generate = Generate;
     Template      = _DefaultTemplate;
 }
Esempio n. 16
0
        public async Task <socket_result> accept(socket_tcp sck)
        {
            generator host = generator.self;

            return(await host.wait_result((async_result_wrap <socket_result> res) => async_accept(sck, host.async_result(res))));
        }
Esempio n. 17
0
        public async Task <socket_result> write(IList <ArraySegment <byte> > buff)
        {
            generator host = generator.self;

            return(await host.wait_result((async_result_wrap <socket_result> res) => async_write(buff, host.async_result(res))));
        }
Esempio n. 18
0
        public async Task <socket_result> connect(string ip, int port)
        {
            generator host = generator.self;

            return(await host.wait_result((async_result_wrap <socket_result> res) => async_connect(ip, port, host.async_result(res))));
        }
Esempio n. 19
0
 generator(state).Unfold(generator, stopCondition);