Example #1
0
            public Blockchain(string Data, string Blocktype = "root", int complexity = 0)
            {
                _complexity       = complexity;
                block._complexity = complexity;

                this.Chain = new List <block>()
                {
                    new block
                    {
                        index         = 0,
                        timestamp     = DateTime.Now.Ticks,
                        previous_hash = new byte[0], //block.GetHash("genesis"),
                        data          = Data,        //!! Data is not stored !!
                        blocktype     = Blocktype
                    }
                };


                block oGenesis = Chain.First();

                if (string.IsNullOrEmpty(Data))
                {
                    oGenesis.data = "";
                }
                oGenesis.nonce = Mine(0, Blocktype, new byte[0]);
                oGenesis.calc_hash();

                //File.WriteAllText(@"c:\temp\data\" + Base32Encoding.ToString(oGenesis.data) + ".json", Data);
            }
Example #2
0
 public ResultHelper AddBlock(BlockDto blockDto)
 {
     try
     {
         if (IsThere(blockDto))
         {
             return(new ResultHelper(false, 0, ResultHelper.IsThereItem));
         }
         block item = new block();
         item.BlockID = blockDto.BlockID;
         item.BuildID = blockDto.BuildID;
         item.Name    = blockDto.Name;
         item.Gps     = blockDto.Gps;
         using (UnitOfWork unitOfWork = new UnitOfWork())
         {
             unitOfWork.GetRepository <block>().Insert(item);
             unitOfWork.saveChanges();
             return(new ResultHelper(true, item.BlockID, ResultHelper.SuccessMessage));
         }
     }
     catch (Exception ex)
     {
         return(new ResultHelper(false, 0, ResultHelper.UnSuccessMessage));
     }
 }
    private void DestroyBlock()
    {
        if (IsRayHitBlock(out RaycastHit hit))
        {
            block block = hit.transform.GetComponent <block>();
            if (hitBlock == null)
            {
                hitBlock = block;
            }
            if (hitBlock != block)
            {
                StopDestroyBlock();
                hitBlock = block;
            }
            Debug.Log("update");
            if (!animator.GetBool("isHit"))
            {
                Debug.Log("true");
                animator.SetBool("isHit", true);
            }

            hitBlock.healthPoint--;
            if (hitBlock.healthPoint <= 0f)
            {
                Destroy(hitBlock.gameObject);
            }
        }
    }
Example #4
0
    public void MoveOneBlockOneStep(block b, Direction dir)
    {
        Vector3 delta  = GetMoveDelta(dir);
        Vector3 target = b.transform.position + delta;

        if (!CheckWithin(target))
        {
            return;
        }
        block tgt = GetBlock(target.x, target.y);

        if (tgt == null)
        {
            b.MoveOnePixel(dir);
            MoveOneBlockOneStep(b, dir);
        }
        else
        {
            if (tgt.GetSpriteNum() == b.GetSpriteNum())
            {
                tgt.LevelUp();
                RemoveBlock(b);
            }
            return;
        }
    }
        private void encrypt(block b)
        {
            byte[] iv = new byte[16];

            //if this image is scrubbed with a value that's not 00 we must restore the IV value that creates the sequence of events when decrypting scrubbed data
            if (b.IsScrubbed && b.ScrubByte != 0 && !_forcedHashes)
            {
                iv.Clear(0, iv.Length, b.ScrubByte);
            }

            b.Aes.IV = iv; //takes as copy

            using (ICryptoTransform cryptor = b.Aes.CreateEncryptor())
            {
                cryptor.TransformBlock(_dec, b.Offset, 0x400, _enc, b.Offset);
            }

            Array.Copy(_enc, b.Offset + 0x3d0, iv, 0, 16);
            b.Aes.IV = iv;

            using (ICryptoTransform cryptor = b.Aes.CreateEncryptor())
            {
                cryptor.TransformBlock(_dec, b.DataOffset, 0x7c00, _enc, b.DataOffset);
            }

            b.IsDirty = false;
        }
Example #6
0
        public override void visit(while_node wn)
        {
            var b = HasStatementVisitor <yield_node> .Has(wn);

            if (!b)
            {
                return;
            }

            var gotoBreak    = goto_statement.New;
            var gotoContinue = goto_statement.New;

            ReplaceBreakContinueWithGotoLabelVisitor replaceBreakContinueVis = new ReplaceBreakContinueWithGotoLabelVisitor(gotoContinue, gotoBreak);

            wn.statements.visit(replaceBreakContinueVis);

            ProcessNode(wn.statements);

            statement if0;

            //if (wn.expr is ident && (wn.expr as ident).name.ToLower() == "true")
            //    if0 = gotoBreak;
            //else
            if0 = new if_node(un_expr.Not(wn.expr), gotoBreak);
            var lb2 = new labeled_statement(gotoContinue.label, if0); // continue
            var lb1 = new labeled_statement(gotoBreak.label);         // break

            ReplaceStatement(wn, SeqStatements(lb2, wn.statements, gotoContinue, lb1));

            // в declarations ближайшего блока добавить описание labels
            block bl = listNodes.FindLast(x => x is block) as block;

            bl.defs.Add(new label_definitions(gotoBreak.label, gotoContinue.label));
        }
        /// <summary>
        /// Traverse all paths to wall of the same color as key
        /// </summary>
        /// <param name="key">Green or Yellow Key</param>
        /// <param name="x">Current  position x</param>
        /// <param name="y">Current position y</param>
        public void FindWall(block key, int x, int y)
        {
            // Depth First Search to find all walkable paths.
            // TODO: Exceptions
            // TODO: case when wall is consecutive blocks - one blocking the other.
            // FIX: Do not work in case of wall of Keys <exmaple Loop.lvl>
            // ... possible solution [Flags]

            int[,] directions =
            {
                { 1, 0, -1, 0 },               // x
                { 0, 1,  0,-1 }                // y
            };

            // mark current position as visited
            this.MarkAsWalked(x, y);

            for (int i = 0; i < directions.GetLength(1); i++)
            {
                int row = x + directions[0, i]; // next
                int col = y + directions[1, i]; // steps

                if (isWalkable(row, col))
                {
                    this.FindWall(key, row, col);
                }
                else if (this.gameMap[row, col] == key + 1)
                {
                    // if wall is the same color as Key mark it as visited as well.
                    // TODO: implement function checking consecutive blocks of the same color.
                    this.gameMap[row, col] = block.Marker;
                }
            }
        }
    private void MakeBlock(int3 pos, block type, byte dir, int index = -1, bool loading = false)
    {
        GameObject blockInstance = Instantiate(type.model, pos.ToVector(), Quaternion.identity);

        blockInstance.transform.rotation = Quaternion.LookRotation(blockDirections [dir].ToVector());
        blockInstance.GetComponent <Renderer> ().material.color = type.color;
        blockData instance = new blockData(type, pos, dir, blockInstance, index);

        blocksInScene.Add(pos, instance);
        if (type.name == "button")
        {
            instance.index = buttonCount;
            buttonCount++;
        }
        else
        {
            Instantiate(backCollider, pos.ToVector(), Quaternion.identity).transform.SetParent(blockInstance.transform);
        }
        if (type.name == "door" && !loading)
        {
            currentDoor  = instance;
            line.enabled = true;
            connecting   = true;
        }
    }
Example #9
0
        static void ProcessLevelBlocks(Level lvl)
        {
            try {
                if (lvl.blockqueue.Count < 1)
                {
                    return;
                }
                bulkSender.level = lvl;
                int count = blockupdates;
                if (lvl.blockqueue.Count < blockupdates || !lvl.HasPlayers())
                {
                    count = lvl.blockqueue.Count;
                }

                for (int c = 0; c < count; c++)
                {
                    block item = lvl.blockqueue[c];
                    bulkSender.Add(item.index, item.type, item.extType);
                    bulkSender.CheckIfSend(false);
                }
                bulkSender.CheckIfSend(true);
                lvl.blockqueue.RemoveRange(0, count);
            } catch (Exception e)  {
                Server.s.ErrorCase("error:" + e);
                Server.s.Log(String.Format("Block cache failed for map: {0}. {1} lost.", lvl.name, lvl.blockqueue.Count));
                lvl.blockqueue.Clear();
            }
        }
Example #10
0
    public mazegenerator()
    {
        quadtable = new block [100,100];

          	for(int i = 0; i < 2000; i+=20)
                {
             		for(int j = 0; j < 2000; j+=20)
                        {

                        block currentsquare = new block(19,19,i,j,"earth");

                        quadtable[i/20,j/20] = currentsquare;

                        }
                }
         room newroom = new room(20,20,6,4);
         rooms.Add(newroom);
         foreach (Vector2 wall in newroom.walls)
                    {
                    quadtable[(int)wall.x,(int)wall.y] = new block(19,19,wall.x*20,wall.y*20,"wall");
                    }

        foreach (Vector2 floor in newroom.floortiles)
                    {
                    quadtable[(int)floor.x,(int)floor.y] = new block(19,19,floor.x*20,floor.y*20,"floor");
                    }
    }
Example #11
0
        private block get_body(ICSharpCode.NRefactory.Ast.BlockStatement body)
        {
            block blck = new block();

            blck.source_context = get_source_context(body);
            statement_list sl = new statement_list();

            sl.source_context = blck.source_context;
            blck.program_code = sl;
            foreach (ICSharpCode.NRefactory.Ast.INode stmt in body.Children)
            {
                if (stmt is ICSharpCode.NRefactory.Ast.LocalVariableDeclaration)
                {
                    get_var_statement(sl, stmt as ICSharpCode.NRefactory.Ast.LocalVariableDeclaration);
                }
                //else if (stmt is ICSharpCode.NRefactory.Ast.ForStatement)
                //	get_for_statement(sl,stmt as ICSharpCode.NRefactory.Ast.ForStatement);
                else if (stmt is ICSharpCode.NRefactory.Ast.WithStatement)
                {
                    get_with_statement(sl, stmt as ICSharpCode.NRefactory.Ast.WithStatement);
                }
                else if (stmt is ICSharpCode.NRefactory.Ast.BlockStatement)
                {
                    get_body(sl, stmt as ICSharpCode.NRefactory.Ast.BlockStatement);
                }
                //else if (stmt is ICSharpCode.NRefactory.Ast.SwitchStatement)
                //	get_switch_statement(sl, stmt as ICSharpCode.NRefactory.Ast.SwitchStatement);
                else if (stmt is ICSharpCode.NRefactory.Ast.ForNextStatement)
                {
                    get_fornext_statement(sl, stmt as ICSharpCode.NRefactory.Ast.ForNextStatement);
                }
            }
            return(blck);
        }
Example #12
0
        private void get_body(statement_list sl, ICSharpCode.NRefactory.Ast.BlockStatement stmt)
        {
            block block_stmt = new block();

            block_stmt.source_context = get_source_context(stmt);
            sl.subnodes.Add(get_statement_list(stmt));
        }
            public static procedure_definition CreateFunctionDefinitionNode(method_name methName, formal_parameters formalPars, bool ofObject, bool classKeyword, statement procBody, type_definition returnType, SourceContext sc)
            {
                procedure_definition procDef = new procedure_definition();

                function_header procHeader = new function_header();

                procHeader.name           = methName;
                procHeader.source_context = sc;
                if (procHeader.name.meth_name is template_type_name)
                {
                    procHeader.template_args = (procHeader.name.meth_name as template_type_name).template_args;
                    ident id = new ident(procHeader.name.meth_name.name);
                    procHeader.name.meth_name = id;
                }
                procHeader.parameters    = formalPars;
                procHeader.of_object     = ofObject;
                procHeader.class_keyword = classKeyword;
                procHeader.return_type   = returnType;

                statement_list stmtList = new statement_list();

                stmtList.subnodes.Add(procBody);

                block bl = new block(null, null);

                bl.program_code = stmtList;

                procDef.proc_header = procHeader;
                procDef.proc_body   = (proc_block)bl;

                return(procDef);
            }
Example #14
0
        public static procedure_definition BuildShortProcFuncDefinitionNoSC(procedure_header header, statement st)
        {
            var stlist = new statement_list(st, st.source_context);
            var b      = new block(null, stlist, st.source_context);

            return(new procedure_definition(header, b, true, BuildGenSC));
        }
 private void setScrubbedBlockInfo(block b)
 {
     if (_hasEnc)
     {
         int  end = b.DataOffset;
         byte byt = _enc[b.Offset];
         if (byt == 0 || byt == 0xff)
         {
             bool scrubbed = true;
             for (int i = end - 0x400; i < end; i++)
             {
                 if (_enc[i] != byt)
                 {
                     scrubbed = false;
                     break;
                 }
             }
             if (b.IsUsed)
             {
                 b.IsScrubbed = scrubbed;
                 b.ScrubByte  = byt;
             }
         }
         else
         {
             b.IsScrubbed = false;
         }
     }
 }
Example #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            string type = ""; string comm = ""; string[] dimarray = new string[2]; string maxPixelValue = ""; int width = 0; int height = 0; Image img = new Image(800, 600);

            readImage(ref type, ref comm, ref maxPixelValue, ref width, ref height, ref img);

            block[,] Yblocks   = new block[height / 8, width / 8];
            block[,] UVblocks  = new block[height / 8, width / 8];
            block[,] YUVblocks = new block[height / 8, width / 8];

            encoding(width, height, img, ref Yblocks, ref UVblocks);

            upSampling(width, height, ref YUVblocks, Yblocks, UVblocks);
            block[,] dctblock = dctTransform(YUVblocks, width, height);
            quantize(ref dctblock, width, height);

            int[] entropyEncodedArray = entropyEncoding(dctblock, width, height);
            block[,] entropyDecodedBlocks = entropyDecoding(width, height, entropyEncodedArray);

            deQuantize(ref entropyDecodedBlocks, width, height);
            block[,] invDCT = dctInvTransform(entropyDecodedBlocks, width, height);

            Image decoded             = decoding(width, height, invDCT);

            //for lab1 Image decoded = decoding(width, height, Yblocks, UVblocks);

            saveImage(type, comm, maxPixelValue, width, height, decoded);
            MessageBox.Show("Done");
        }
Example #17
0
        public override void visit(repeat_node rn)
        {
            var b = HasStatementVisitor <yield_node> .Has(rn);

            if (!b)
            {
                return;
            }

            var gotoContinue = goto_statement.New;
            var gotoBreak    = goto_statement.New;

            ReplaceBreakContinueWithGotoLabelVisitor replaceBreakContinueVis = new ReplaceBreakContinueWithGotoLabelVisitor(gotoContinue, gotoBreak);

            rn.statements.visit(replaceBreakContinueVis);

            ProcessNode(rn.statements);

            var gotoContinueIfNotCondition = new if_node(un_expr.Not(rn.expr), gotoContinue);
            var continueLabeledStatement   = new labeled_statement(gotoContinue.label, new statement_list(rn.statements, gotoContinueIfNotCondition));

            var breakLabeledStatement = new labeled_statement(gotoBreak.label);


            ReplaceStatement(rn, SeqStatements(gotoContinue, continueLabeledStatement, breakLabeledStatement));

            // в declarations ближайшего блока добавить описание labels
            block bl = listNodes.FindLast(x => x is block) as block;

            bl.defs.Add(new label_definitions(gotoContinue.label, gotoBreak.label));
        }
Example #18
0
        public override void visit(for_node fn)
        {
            ProcessNode(fn.statements);
            var b = HasStatementVisitor <yield_node> .Has(fn);

            if (!b)
            {
                return;
            }

            var gt1 = goto_statement.New;
            var gt2 = goto_statement.New;

            var endtemp = new ident(newVarName());
            var ass1    = new var_statement(fn.loop_variable, fn.type_name, fn.initial_value);
            var ass2    = new var_statement(endtemp, fn.type_name, fn.finish_value);


            var if0 = new if_node(bin_expr.Greater(fn.loop_variable, fn.finish_value), gt1);
            var lb2 = new labeled_statement(gt2.label, if0);
            var lb1 = new labeled_statement(gt1.label);
            var Inc = new procedure_call(new method_call(new ident("Inc"), new expression_list(fn.loop_variable)));

            ReplaceStatement(fn, SeqStatements(ass1, ass2, lb2, fn.statements, Inc, gt2, lb1));

            // в declarations ближайшего блока добавить описание labels
            block bl = listNodes.FindLast(x => x is block) as block;

            bl.defs.Add(new label_definitions(gt1.label, gt2.label));
        }
Example #19
0
        public void upSampling(int width, int height, ref block[,] YUVblocks, block[,] Yblocks, block[,] UVblocks)
        {
            for (int i = 0; i < height / 8; i++)
            {
                for (int j = 0; j < width / 8; j++)
                {
                    //for Y block just copy elements because it wasn't subsampled
                    block YUVblock = new block(8, 8, new Point(i * 8, j * 8));
                    for (int k = 0; k < 8; k++)
                    {
                        for (int l = 0; l < 8; l++)
                        {
                            YUVblock.pixelMatrix[k, l].r = Yblocks[i, j].pixelMatrix[k, l].r;
                        }
                    }

                    //for U and V block apply upSampling because was 4:2:0 subsampled
                    for (int k = 0; k < 4; k++)
                    {
                        for (int l = 0; l < 4; l++)
                        {
                            YUVblock.pixelMatrix[k * 2, l * 2].g = YUVblock.pixelMatrix[k * 2 + 1, l * 2].g = YUVblock.pixelMatrix[k * 2, l * 2 + 1].g = YUVblock.pixelMatrix[k * 2 + 1, l * 2 + 1].g =
                                UVblocks[i, j].pixelMatrix[k, l].g; //u block
                            YUVblock.pixelMatrix[k * 2, l * 2].b = YUVblock.pixelMatrix[k * 2 + 1, l * 2].b = YUVblock.pixelMatrix[k * 2, l * 2 + 1].b = YUVblock.pixelMatrix[k * 2 + 1, l * 2 + 1].b =
                                UVblocks[i, j].pixelMatrix[k, l].b; //v block
                        }
                    }
                    YUVblocks[i, j] = YUVblock;
                }
            }
        }
Example #20
0
            /*public block NewBlock(string Data, block ParentBlock, string BlockType = "")
             * {
             *  var oNew = new block()
             *  {
             *      index = ParentBlock.index + 1,
             *      timestamp = DateTime.Now.Ticks,
             *      previous_hash = ParentBlock.hash,
             *      data = block.GetHash(Data),
             *      blocktype = BlockType
             *  };
             *  //oNew.hash = block.GetHash(oNew.index.ToString() + oNew.timestamp.ToString() + oNew.proof.ToString() + oNew.previous_hash.ToString() + oNew.data.ToString());
             *  oNew.calc_hash();
             *  Chain.Add(oNew);
             *
             *  return oNew;
             * }*/

            public block UseBlock(string Data, block FreeBlock)
            {
                /*if(!validateChain()) //Chain not Valid
                 *  return FreeBlock;*/

                //Check if FreeBlock is valid..
                var oParent = Chain.FirstOrDefault(t => t.hash == FreeBlock.previous_hash);

                if (oParent != null)
                {
                    /*if(!FreeBlock.validate(oParent.nonce))
                     * {
                     *  Console.WriteLine("Invalid Block: \n" + JsonConvert.SerializeObject(FreeBlock));
                     *  return FreeBlock;
                     * }*/
                }
                else
                {
                    Console.WriteLine("Invalid Block: \n" + JsonConvert.SerializeObject(FreeBlock));
                    return(FreeBlock);
                }


                if (FreeBlock.data != null | FreeBlock.hash != null | FreeBlock.signature != null) //it's not a free Block
                {
                    return(FreeBlock);
                }

                //FreeBlock.index = oParent.index + 1;
                FreeBlock.data      = Data;
                FreeBlock.timestamp = DateTime.Now.Ticks;
                FreeBlock.calc_hash();

                return(FreeBlock);
            }
Example #21
0
    /// <summary>
    /// Returns backwards from final block to first block and put them in correct order.
    /// Stack is used to reverse order from final-first to first-final
    /// </summary>
    /// <param name="now">Now.</param>
    /// <param name="roadToTake">Road to take.</param>
    static void DrawToBeforeLine(block now, ref Stack roadToTake)
    {
        if (now.previous != null)
        {
            // draw a debug line, will not show in build
            Debug.DrawLine(
                new Vector3(
                    now.position.y,
                    -now.position.x,
                    -5
                    ) + MapCreate.PositionStarter,
                new Vector3(
                    now.previous.position.y,
                    -now.previous.position.x,
                    -5
                    ) + MapCreate.PositionStarter,
                Color.cyan,
                10000
                );
            // push the road to take
            roadToTake.Push(now.position);

            // recursive, we stop when we the previous is null => we arrived to first block
            DrawToBeforeLine(now.previous, ref roadToTake);
        }
    }
Example #22
0
            public block MineNewBlock(block ParentBlock, string Blocktype = "")
            {
                if (string.IsNullOrEmpty(Blocktype)) //Use ParentBlock.blocktype if Blocktype is empty
                {
                    Blocktype = ParentBlock.blocktype;
                }

                if (Chain.Count(t => t.previous_hash == ParentBlock.hash & t.blocktype == Blocktype) == 0) //only on Blocktype tree allowed
                {
                    int iIndex = Chain.Max(t => t.index) + 1;

                    var oNew = new block()
                    {
                        index         = iIndex,
                        timestamp     = DateTime.Now.Ticks,
                        previous_hash = ParentBlock.hash,
                        blocktype     = Blocktype,
                        nonce         = Mine(ParentBlock.nonce, Blocktype, ParentBlock.hash)
                    };

                    Chain.Add(oNew);

                    return(oNew);
                }

                return(new block());
            }
        public WiiPartitionGroupEncryptionState(int maxSize, byte[] key, byte[] h3Table)
        {
            if (maxSize % 0x8000 != 0)
            {
                throw new HandledException("Max group size is not a multiple of 0x8000");
            }

            _h3Table = h3Table;
            _maxSize = maxSize;
            _blocks  = new block[maxSize / 0x8000];

            PartitionHashTable h1 = null;
            PartitionHashTable h2 = new PartitionHashTable(8);

            for (int i = 0; i < _blocks.Length; i++)
            {
                if (i % 8 == 0)                     //share the h2 hash table across 8 blocks
                {
                    h1 = new PartitionHashTable(8); //8 lots of 8 blocks = 64 blocks
                }

                _blocks[i] = new block(i, h1, h2, key);
            }

            _unusedBlankHash = _blocks[0].Sha1.ComputeHash(new byte[0x400]);
        }
Example #24
0
        public double Cmp2(int block1, int block2, int dir, block curtexture)
        {
            List <double> vect1 = new List <double>();
            List <double> vect2 = new List <double>();

            if (dir == 0)
            {
                for (int i = kernel - overlap; i < kernel; i++)
                {
                    for (int j = 0; j < kernel; j++)
                    {
                        double num = texture[block1].value[i, j, 0] + texture[block1].value[i, j, 1] + texture[block1].value[i, j, 2];
                        num /= 3;
                        vect1.Add(num);
                    }
                }

                for (int i = 0; i < overlap; i++)
                {
                    for (int j = 0; j < kernel; j++)
                    {
                        double num = texture[block2].value[i, j, 0] + texture[block2].value[i, j, 1] + texture[block2].value[i, j, 2];
                        num /= 3;
                        vect2.Add(num);
                    }
                }
            }
            else if (dir == 1)
            {
                for (int i = 0; i < kernel; i++)
                {
                    for (int j = kernel - overlap; j < kernel; j++)
                    {
                        double num = texture[block1].value[i, j, 0] + texture[block1].value[i, j, 1] + texture[block1].value[i, j, 2];
                        num /= 3;
                        vect1.Add(num);
                    }
                }

                for (int i = 0; i < kernel; i++)
                {
                    for (int j = 0; j < overlap; j++)
                    {
                        double num = texture[block2].value[i, j, 0] + texture[block2].value[i, j, 1] + texture[block2].value[i, j, 2];
                        num /= 3;
                        vect2.Add(num);
                    }
                }
            }

            double ans = 0;

            for (int i = 0; i < vect1.Count; i++)
            {
                ans += Math.Sqrt(Math.Pow(vect1[i] - vect2[i], 2));
            }

            return(ans * alpha);
        }
Example #25
0
        public ActionResult DeleteConfirmed(int id)
        {
            block block = db.blocks.Find(id);

            db.blocks.Remove(block);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #26
0
 public Piece(block shape_index, Color blockColor , Vector2 position)
 {
     this.blockColor = blockColor;
     this.pos = position;
     this.BLOCK = shape_index;
     this.shape = make_shape((int)shape_index);
     this.bounding_box = calculate_bounding_box();
 }
 public blockData(block blockType, int3 position, byte direction, GameObject obj, int index = -1)
 {
     this.blockType = blockType;
     this.position  = position;
     this.direction = direction;
     this.obj       = obj;
     this.index     = index;
 }
        public procedure_definition lambda(function_lambda_definition _function_lambda_definition)
        {
            procedure_definition _func_def     = new procedure_definition();
            method_name          _method_name1 = new method_name(null, null, new ident(_function_lambda_definition.lambda_name), null);
            //parsertools.create_source_context(_method_name1, _method_name1.meth_name, _method_name1.meth_name);
            function_header _function_header1 = new function_header();

            object rt1 = new object();

            _function_header1.name = _method_name1;
            if (_function_header1.name.meth_name is template_type_name)
            {
                _function_header1.template_args = (_function_header1.name.meth_name as template_type_name).template_args;
                ident id = new ident(_function_header1.name.meth_name.name);
                //parsertools.create_source_context(id, _function_header1.name.meth_name, _function_header1.name.meth_name);
                _function_header1.name.meth_name = id;
            }

            formal_parameters fps = new PascalABCCompiler.SyntaxTree.formal_parameters();

            _function_header1.parameters = _function_lambda_definition.formal_parameters;//fps;

            /*SyntaxTree.named_type_reference _named_type_reference = new SyntaxTree.named_type_reference();
             * SyntaxTree.ident idtype = new SyntaxTree.ident("object");
             * _named_type_reference.source_context = idtype.source_context;
             * _named_type_reference.names.Add(idtype);
             * rt1 = _named_type_reference;
             * _function_header1.return_type = (SyntaxTree.type_definition)_named_type_reference;*/
            _function_header1.return_type = _function_lambda_definition.return_type;

            _function_header1.of_object     = false;
            _function_header1.class_keyword = false;
            token_info _token_info = new token_info("function");
            //_token_info.source_context = parsertools.GetTokenSourceContext();
            //parsertools.create_source_context(_function_header1, _token_info, _token_info);

            block          _block1 = new block(null, null);
            statement_list sl1     = new statement_list();

            sl1.subnodes.Add(_function_lambda_definition.proc_body);
            _block1.program_code  = sl1;
            _func_def.proc_header = _function_header1;
            _func_def.proc_body   = (proc_block)_block1;
            if (_function_lambda_definition.defs != null)
            {
                if (((block)_func_def.proc_body).defs == null)
                {
                    ((block)_func_def.proc_body).defs = new declarations();
                }
                for (int l = 0; l < _function_lambda_definition.defs.Count; l++)
                {
                    ((block)_func_def.proc_body).defs.defs.Add(_function_lambda_definition.defs[l] as procedure_definition);
                }
            }
            _function_lambda_definition.proc_definition = _func_def;
            //parsertools.create_source_context(_func_def, _function_header1, _function_header1);
            return(_func_def);
        }
 private void commitHashCache(block b)
 {
     b.H0Table.CopyAll(_dec, b.Offset);                                  //31 20 byte hashes
     Array.Clear(_dec, b.Offset + 0x26c, 0x280 - 0x26c);                 //0x26c 31 20 byte hashes
     b.H1Table.CopyAll(_dec, b.Offset + 0x280);                          //8 20 byte hashes
     Array.Clear(_dec, b.Offset + 0x280 + 0xA0, 0x340 - (0x280 + 0xA0)); //0xA0 8 20 byte hashes
     b.H2Table.CopyAll(_dec, b.Offset + 0x340);                          //8 20 byte hashes
     Array.Clear(_dec, b.Offset + 0x340 + 0xA0, 0x400 - (0x340 + 0xA0));
 }
Example #30
0
 public bool addNewBlock(block block)
 {
     if (isValidNewBlock(getLastBlock(), block))
     {
         listBlock.Add(block);
         return(true);
     }
     return(false);
 }
Example #31
0
 public ActionResult Edit([Bind(Include = "index,previousHash,hash,timestamp,data")] block block)
 {
     if (ModelState.IsValid)
     {
         db.Entry(block).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(block));
 }
Example #32
0
        public string calculateHash(block bl)
        {
            var input = bl.index + bl.previousHash + bl.timestamp.ToString() + bl.data + "";

            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            var    md5        = MD5.Create();
            var    hash       = md5.ComputeHash(inputBytes);

            return(BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant());
        }
Example #33
0
        public void Add(int type, string value, int what, string notes)
        {
            block b = new block();
            b.Type = type;
            b.Value = value;
            b.What = what;
            b.Notes = notes;
            b.Date = DateTime.UtcNow;

            db_mysql.blocks.Add(b);
            db_mysql.SaveChanges();
        }
Example #34
0
    public long numWays(int width, int height, string[] bad)
    {
        long[,] dp = new long[width + 1, height + 1];
        block[] blocks = new block[bad.Length];
        for (int i = 0; i < bad.Length; ++i)
        {
            blocks[i] = new block(bad[i]);
        }
        dp[0,0] = 1;

        for (int i = 1; i <= width; ++i)
        {
            if (isBad(i, 0, i - 1, 0,blocks))
            {
                dp[i, 0] = 0;
            }
            else
            {
                dp[i, 0] =  dp[i-1,0];
            }
        }
        for (int i = 1; i <= height; ++i)
        {
            if (isBad(0,i,0,i-1, blocks))
            {
                dp[0, i] = 0;
            }
            else
            {
                dp[0, i] = dp[0,i - 1];
            }
        }

        for (int i = 1; i <= width; ++i)
        {
            for (int j = 1; j <= height; ++j)
            {
                long aa=0, bb=0;
                if (!isBad(i, j, i - 1, j, blocks))
                {
                    aa = dp[i - 1, j];
                }
                if (!isBad(i, j, i , j-1, blocks))
                {
                    bb = dp[i, j-1];
                }
                dp[i, j] = aa + bb;
            }
        }
        return dp[width, height];
    }
Example #35
0
    private bool isBad(int a,int b, int c,int d, block [] blocks)
    {
        foreach (block bb in blocks)
        {
            if (a == bb.a&&b==bb.b&&c==bb.c&&d==bb.d)
            {
                return true;
            }
            else if (a == bb.c && b == bb.d && c == bb.a && d == bb.b)
            {
                return true;

            }

        }
        return false;
    }
		public virtual void visit(block _block)
		{
			DefaultVisit(_block);
		}
Example #37
0
    private void Update()
    {
        if(_state == State.main)
        {
            if (Input.GetMouseButtonDown (0) && _select){
                RaycastHit hit;
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if ( Physics.Raycast (ray,out hit,100.0f)) {
                    Debug.Log("You selected the " + hit.transform.name); // ensure you picked right object
                    if(hit.transform.tag == "block")
                    {
                        _block = hit.transform.gameObject.GetComponent<block>();
                        ChangeState(State.letter);
                        _select = false;
                    }
                }
            }
        }

        if(_state == State.shooting)
        {
            if ( Input.GetMouseButtonDown (0) && _shooting)
            {
                print("shoot");
                _bullet.gameObject.GetComponent<Rigidbody>().isKinematic = false;
                _bullet.gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(-1f,0.5f,1f) * _force);
                ChangeState(State.main);
                _shooting = false;
            }
        }
    }
Example #38
0
        public void workFrame(int number, Player p, String name,int dir)
        {
            block pos1 = new block();// startblock for imgprint and scinema
            block pos2 = new block();//endblock for imgprint
            block pos3 = new block();//endblock for savecinema
            switch (dir)
            {
                case 1: //1 = 0,0,0 nach 1,0,0
                    pos1.x = 0;
                    pos1.y = 0;
                    pos1.z = 0;
                    pos2.x = 1;
                    pos2.y = 0;
                    pos2.z = 0;
                    pos3.x = (ushort)(picWidth - 1);
                    pos3.y = (ushort)(picHeight-1);
                    pos3.z = 1;
                    break;
                case 2: //2= 0,0,0 nach 0,1,0
                    pos1.x = 1;
                    pos1.y = 0;
                    pos1.z = 0;
                    pos2.x = 1;
                    pos2.y = 0;
                    pos2.z = 1;
                    pos3.x = 0;
                    pos3.y = (ushort)(picHeight - 1);
                    pos3.z = (ushort)(picWidth - 1);
                    break;
                case 3: //3= 1,0,0 nach 0,0,0
                    pos1.x = (ushort)(picWidth - 1);
                    pos1.y = 0;
                    pos1.z = 1;
                    pos2.x = (ushort)(picWidth - 2);
                    pos2.y = 0;
                    pos2.z = 1;
                    pos3.x = 0;
                    pos3.y = (ushort)(picHeight - 1);
                    pos3.z = 0;
                    break;
                case 4: // 4 = 0,1,0 nach 0,0,0
                    pos1.x = 0;
                    pos1.y = 0;
                    pos1.z = (ushort)(picWidth - 1);
                    pos2.x = 0;
                    pos2.y = 0;
                    pos2.z = (ushort)(picWidth - 2);
                    pos3.x = 1;
                    pos3.y = (ushort)(picHeight - 1);
                    pos3.z = 0;
                    break;
                default:

                    break;
            }
            cuboid.Use(p, "air");
            cuboid.Blockchange1(p, 0, 0, 0, 1);
            cuboid.Blockchange2(p, (ushort)(picWidth - 1), (ushort)(picHeight - 1), (ushort)(picWidth - 1), 1);
            //System.Threading.Thread.Sleep(3000);
            imgprnt.Use(p, number.ToString());
            imgprnt.Blockchange1(p, pos1.x, pos1.y, pos1.z, 1);
            imgprnt.Blockchange2(p, pos2.x, pos2.y, pos2.z, 1);
            //had to send the blockchanges manual.
            //printed the image in the level...
            while (imgprnt.working)
            {
                System.Threading.Thread.Sleep(100);
            }
            scin.Use(p, name);
            scin.Blockchange1(p, pos1.x, pos1.y, pos1.z, 1);
            scin.Blockchange2(p, pos3.x, pos3.y, pos3.z, 1);
        }
		internal ParsedAssemblyQualifiedName(string AssemblyQualifiedName)
		{
			int index = -1;
			block rootBlock = new block();
			{
				int bcount = 0;
				block currentBlock = rootBlock;
				for (int i = 0; i < AssemblyQualifiedName.Length; ++i)
				{
					char c = AssemblyQualifiedName[i];
					if (c == '[')
					{
						++bcount;
						var b = new block() { iStart = i + 1, level = bcount, parentBlock = currentBlock };
						currentBlock.innerBlocks.Add(b);
						currentBlock = b;
					}
					else if (c == ']')
					{
						currentBlock.iEnd = i - 1;
						if (AssemblyQualifiedName[currentBlock.iStart] != '[')
						{
							currentBlock.parsedAssemblyQualifiedName = new ParsedAssemblyQualifiedName(AssemblyQualifiedName.Substring(currentBlock.iStart, i - currentBlock.iStart));
							if (bcount == 2)
								this.GenericParameters.Add(currentBlock.parsedAssemblyQualifiedName);
						}
						currentBlock = currentBlock.parentBlock;
						--bcount;
					}
					else if (bcount == 0 && c == ',')
					{
						index = i;
						break;
					}
				}
			}

			this.TypeName = AssemblyQualifiedName.Substring(0, index);

			this.CSharpStyleName = new Lazy<string>(
				() =>
				{
					return this.LanguageStyle("<", ">");
				});

			this.VBNetStyleName = new Lazy<string>(
				() =>
				{
					return this.LanguageStyle("(Of ", ")");
				});

			this.AssemblyDescriptionString = AssemblyQualifiedName.Substring(index + 2);

			{
				List<string> parts = AssemblyDescriptionString.Split(',')
																 .Select(x => x.Trim())
																 .ToList();
				this.Version = LookForPairThenRemove(parts, "Version");
				this.Culture = LookForPairThenRemove(parts, "Culture");
				this.internalKeyToken = LookForPairThenRemove(parts, "internalKeyToken");
				if (parts.Count > 0)
					this.ShortAssemblyName = parts[0];
			}

			this.AssemblyNameDescriptor = new Lazy<AssemblyName>(
				() => new System.Reflection.AssemblyName(this.AssemblyDescriptionString));

			this.FoundType = new Lazy<Type>(
				() => TypeFromAssemblyQualifiedName(AssemblyQualifiedName));
		}
 l.textures.ChangeEdge(block);
Example #41
0
            //嘗試解析, 成功回傳 true, 並作成執行物件輸出到 obj
            //失敗回傳 false, obj 返回 null
            public static bool TryParse(string[] program, out IRunnable obj)
            {
                //先把 program 複製下來
                string[] lines = program;

                //如果 lines 是合法的區塊就創建並返回 true 和相應的物件
                if (IsBlock(lines))
                {
                    obj = new block(lines);
                    return true;
                }

                //否則返回 false 和 null
                obj = null;
                return false;
            }
Example #42
0
		public virtual void post_do_visit(block _block)
		{
		}
Example #43
0
		public virtual void pre_do_visit(block _block)
		{
		}
Example #44
0
		public override void visit(block _block)
		{
			DefaultVisit(_block);
			pre_do_visit(_block);
			visit(block.defs);
			visit(block.program_code);
			post_do_visit(_block);
		}
        private void Parse(string AssemblyQualifiedName)
        {
            int index = -1;
            block rootBlock = new block();

            int bcount = 0;
            block currentBlock = rootBlock;
            for (int i = 0; i < AssemblyQualifiedName.Length; ++i)
            {
                char c = AssemblyQualifiedName[i];
                if (c == '`')
                {
                    string count = string.Empty;
                    for (int j = i + 1; j < AssemblyQualifiedName.Length; j++)
                    {
                        char c2 = AssemblyQualifiedName[j];
                        if (char.IsDigit(c2))
                            count += c2;
                        else
                            break;
                    }
                    int _count = 0;
                    if (int.TryParse(count, out _count))
                    {
                        this.IsGeneric = true;
                        this.GenericRank = _count;
                    }
                }

                if (c == '[')
                {
                    if (AssemblyQualifiedName[i + 1] == ']') // Array type.
                        i++;
                    else
                    {
                        ++bcount;
                        var b = new block() { iStart = i + 1, level = bcount, parentBlock = currentBlock };
                        currentBlock.innerBlocks.Add(b);
                        currentBlock = b;
                    }
                }
                else if (c == ']')
                {
                    currentBlock.iEnd = i - 1;
                    if (AssemblyQualifiedName[currentBlock.iStart] != '[')
                    {
                        currentBlock.parsedAssemblyQualifiedName = new ParsedAssemblyQualifiedName(AssemblyQualifiedName.Substring(currentBlock.iStart, i - currentBlock.iStart));
                        if (bcount == 2)
                            this._genericParameters.Add(currentBlock.parsedAssemblyQualifiedName);
                    }
                    currentBlock = currentBlock.parentBlock;
                    --bcount;
                }
                else if (bcount == 0 && c == ',')
                {
                    index = i;
                    break;
                }
            }

            this.TypeName = AssemblyQualifiedName.Substring(0, index);

            if (this.TypeName.EndsWith("&"))
            {
                this.TypeName = this.TypeName.Substring(0, this.TypeName.Length - 1);
                this.IsRef = true;
            }

            if (this.TypeName.EndsWith("*"))
            {
                this.TypeName = this.TypeName.Substring(0, this.TypeName.Length - 1);
                this.IsPointer = true;
            }

            this.CSharpStyleName = new Lazy<string>(() => { return this.LanguageStyle("<", ">"); });

            this.VBNetStyleName = new Lazy<string>(() => { return this.LanguageStyle("(Of ", ")"); });

            this.AssemblyDescriptionString = AssemblyQualifiedName.Substring(index + 2);

            {
                List<string> parts = AssemblyDescriptionString.Split(',').Select(x => x.Trim())
                                                                         .ToList();
                this.Version = LookForPairThenRemove(parts, "Version");
                this.Culture = LookForPairThenRemove(parts, "Culture");
                this.Path = LookForPairThenRemove(parts, "Path");
                this.PublicKeyToken = LookForPairThenRemove(parts, "PublicKeyToken");
                if (parts.Count > 0)
                    this.ShortAssemblyName = parts[0];
            }

            this.AssemblyNameDescriptor = new Lazy<AssemblyName>(
                () => new System.Reflection.AssemblyName(this.AssemblyDescriptionString));

            this.FoundType = new Lazy<Type>(
                () =>
                {
                    var searchedType = Type.GetType(AssemblyQualifiedName);
                    if (searchedType != null)
                        return searchedType;
                    foreach (var assem in Assemblies.Value)
                    {
                        searchedType =
                            assem.GetType(AssemblyQualifiedName);
                        if (searchedType != null)
                            return searchedType;
                    }
                    return null; // Not found.
                });
        }
Example #46
0
		public override void visit(block _block)
		{
			executer.visit(_block);
			if (_block.defs != null)
				this.visit((dynamic)_block.defs);
			if (_block.program_code != null)
				this.visit((dynamic)_block.program_code);
		}
Example #47
0
		public virtual void visit(block _block)
		{
		}