public bool IsValid() { lock (_lock) { if (Blocks.Any(x => !x.IsValid())) { return(false); } for (int i = 1; i < Blocks.Count; i++) { BlockNode currentBlock = Blocks[i]; BlockNode previousBlock = Blocks[i - 1]; if (currentBlock.Digest != currentBlock.Digest) { return(false); } if (currentBlock.PreviousHash != previousBlock.Digest) { return(false); } } return(true); } }
public void FromMapData(MapData mapData) { Turn = mapData.Turn; Walls = mapData.Walls.Select(item => new Position(item[0], item[1])).ToList(); Blocks = mapData.Blocks.Select(item => new Position(item[0], item[1])).ToList(); Players = mapData.Players; Me = mapData.Players.Find(p => p.Name == Consts.MyName); Bombs = mapData.Bombs; Items = mapData.Items; Fires = mapData.Fires.Select(item => new Position(item[0], item[1])).ToList(); MinX = Walls.Select(item => item.x).Min(); int MaxX = Walls.Select(item => item.x).Max(); SizeX = MaxX - MinX + 1; MinY = Walls.Select(item => item.y).Min(); int MaxY = Walls.Select(item => item.y).Max(); SizeY = MaxY - MinY + 1; logger.Debug($"MinX: {MinX}, SizeX: {SizeX}, MinY {MinY}, SizeY {SizeY}"); var ary2 = Enumerable.Range(MinY, SizeY).Select(y => { return(Enumerable.Range(MinX, SizeX).Select(x => { var cell = new Cell() { X = x, Y = y, Wall = Walls.Any(w => w.x == x && w.y == y), Block = Blocks.Any(b => b.x == x && b.y == y), AnyPlayer = Players.Any(p => p.pos.x == x && p.pos.y == y && p.Name != Consts.MyName), MyPosition = Players.Any(p => p.pos.x == x && p.pos.y == y && p.Name == Consts.MyName), Bomb = Bombs.Find(b => b.pos.x == x && b.pos.y == y), Item = Items.Any(i => i.pos.x == x && i.pos.y == y), Fire = Fires.Any(f => f.x == x && f.y == y) }; var pos = new Position(x, y); return new KeyValuePair <Position, Cell>(pos, cell); })); }).SelectMany(e => e); CellDict = new CellDict(ary2, MinX, SizeX, MinY, SizeY); SetAboutToFire(); SetFallingWall(); CellDict.SetDistance(Me.pos); CellDict.Log(); }
public void Remove(MCEntity e) { if (Blocks.Any(p => p.Code == e.Code)) { var i = Blocks.Single(p => p.Code == e.Code); Blocks.Remove(i); } if (Items.Any(p => p.Code == e.Code)) { var i = Items.Single(p => p.Code == e.Code); Items.Remove(i); } }
private void Update() { if (rb.bodyType == RigidbodyType2D.Static) { return; } if (Input.GetButtonUp("Down")) { fall.StopFalling(); } if (fall.IsFalling) { return; } if (FallTimer >= FallDelay) { FallTimer = 0f; rb.MovePosition((Vector2)transform.position + Vector2.down); } else { FallTimer += Time.deltaTime; if (Input.GetButtonDown("Right") && !Blocks.Any(x => x.GetNeighbor(Vector3.right).transform?.gameObject.layer == StaticLayer)) { Move(Vector2.right); } if (Input.GetButtonDown("Left") && !Blocks.Any(x => x.GetNeighbor(Vector3.left).transform?.gameObject.layer == StaticLayer)) { Move(Vector2.left); } if (Input.GetButton("Down")) { fall.StartFalling(); } if (Input.GetButtonDown("Up")) { Rotate(); } } }
public void InsertBlock(Block block) { if ( Blocks.Any() && !block.Header.HashPrevious.IsEqual( Blocks.Last().Header.Hash)) { throw new ProtocolException( string.Format( "Headerchain out of order in blockArchive {0}.", Index)); } Blocks.Add(block); CountBytes += block.Buffer.Length; }
public void Start() { if (HasFinished || !Blocks.Any()) { return; } _dispatcherTimer.Start(); StartNextBlock(); ButtonStartStopText = AppResources.ButtonStop; ButtonStartStopBackground = Common.RedColorBrush; //if (!HasStarted) // _orignalTime = RemainingTime; // keep the original time in memory so we can substract later //else HasStarted = true; PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; }
public string ToBase64() { if (!Blocks.Any()) { return(""); } MemoryStream stream = new MemoryStream(); using (BinaryWriter streamWriter = new BinaryWriter(stream)) { streamWriter.Write(Version); int count = Blocks.Count(); streamWriter.Write(count); foreach (Block block in Blocks) { block.SaveToStream(streamWriter); } } return(Convert.ToBase64String(stream.ToArray())); }
public override void Update(GameTime gt) { if (Mouse.LeftMouseDown && Mouse.CanPress) { if (PlayHitbox.Contains(Mouse.Position)) { Manager.SwitchScene(new SceneGame()); } else if (BlockCreationHitbox.Contains(Mouse.Position)) { Manager.SwitchScene(new SceneBlockCreation()); } } Blocks.ForEach(x => x.Update(gt)); Mouse.DrawMouse = !Blocks.Any(x => x.SafeHitbox.Contains(Mouse.Position)); base.Update(gt); }
public int BlocksAboveReady() { if (Blocks.Any(block => block.Ready)) { int blocksOverReady = 0; foreach (var block in Blocks.Reverse()) { if (block.Ready) { blocksOverReady = 0; } else { blocksOverReady++; } } return(blocksOverReady); } else { return(0); } }
public bool ContainsPair(int index) { return(Blocks.Any(b => b.IsPair && b.Index == index)); }
public bool ContainsShuntsu(int index) { return(Blocks.Any(b => b.IsShuntsu && b.Index == index)); }
private bool CanOkExecute() { return(Blocks.Any(b => b.IsSelected)); }
public bool ShouldSerializeBlocks() => Blocks?.Any() ?? false;
public bool ContainsDueBelow(TimeStamp due) { return(Blocks.Any(block => block.Due.MilliSeconds < due.MilliSeconds)); }
internal void ScanBlocks(List <Instruction> instructions) { ExitBlock = new Block(instructions.Count) { End = instructions.Count }; int currentAddr = 0; var block = GetOrCreateBlockAt(currentAddr); Stack <int> workList = new Stack <int>(); workList.Push(currentAddr); while (workList.Count > 0) { currentAddr = workList.Pop(); block = GetOrCreateBlockAt(currentAddr); NEXT: Instruction label = null; Instruction branch = null; for (int i = currentAddr + 1; i < instructions.Count; i++) { var ins = instructions[i]; if (label == null && ins.JumpedFrom != null) { if (ins.Line > currentAddr) { label = ins; } } if (branch == null && (ins.OpCode.IsJump() || ins.OpCode == OpCode.RET)) { branch = ins; } if (label != null && branch != null) { break; } } //if (label == null) //{ // //should reach end now // block.End = instructions.Count - 1; // continue; //} var addrAfterBranch = branch.Line + 1; if (label != null && label.Line < addrAfterBranch) //Take from start to label as a straight block { block.End = label.Line - 1; currentAddr = label.Line; var nextBlock1 = GetOrCreateBlockAt(currentAddr); nextBlock1.From.TryAdd(block); block.To.TryAdd(nextBlock1); block = nextBlock1; goto NEXT; } block.End = addrAfterBranch - 1; //current block: before branch if (branch.OpCode == OpCode.RET) { ExitBlock.From.TryAdd(block); block.To.TryAdd(ExitBlock); continue; } var gotoLine = ((JumpData)branch.Data).Goto.Line; // ReSharper disable once SimplifyLinqExpression if (!Blocks.Any(b => b.Start == gotoLine)) { workList.Push(gotoLine); //stashed block: created, process later } var nextBlock = GetOrCreateBlockAt(gotoLine); nextBlock.From.TryAdd(block); block.To.TryAdd(nextBlock); if (!branch.OpCode.IsJump(true)) { continue; } nextBlock = GetOrCreateBlockAt(addrAfterBranch); //next block: right after branch (if not jumped) nextBlock.From.TryAdd(block); block.To.TryAdd(nextBlock); block = nextBlock; currentAddr = block.Start; goto NEXT; } Blocks.TryAdd(ExitBlock); Blocks.Sort((b1, b2) => b1.Start - b2.Start); foreach (var bl in Blocks) { bl.From.Sort((b1, b2) => b1.Start - b2.Start); bl.To.Sort((b1, b2) => b1.Start - b2.Start); } if (Blocks.Count > 0) { //TJS2 is a simple language, the entry block is always the start block EntryBlock = Blocks[0]; } }
public bool Intersects(IWireframe frame) { return(frame != null && Blocks.Any(b => frame.Intersects(b))); }
public bool ShouldSerializeAttachments() => Blocks?.Any() ?? false;
public bool Intersects(int x, int y, int z, int h) { return(Blocks.Any(b => b.Intersects(x, y, z, h))); }