// Run updates for all actors until it is the Player's turn to act again. public void Run() { do { // TODO: Not certain if this is a correct implementation. However, it fixes an issue // where the first input after Game.NewGame() is "eaten" since Clear() is called, but // _stopping doesn't get set to false until Update() - which forces it to return false if (_stopping) { _eventSet.Clear(); _stopping = false; } // No one is currently ready, so continually apply energy recovery to all entities in the // system, until the queue has at least one entity to execute. while (_eventSet.Count == 0) { foreach (ISchedulable entity in _entities.ToList()) { // Everyone gains some energy entity.Energy += Data.Constants.DEFAULT_REFRESH_RATE; // Entities with sufficient energy are placed into the turn queue. if (entity.Energy >= entity.ActivationEnergy) { _eventSet.Add(entity); } } } foreach (ISchedulable entity in _entities) { // Manage other stuff tied to Actor speeds if (entity is DelayAttack attack && attack.Lifetime > 0) { var blend = Colors.EnemyThreat.Blend(Colors.FloorBackground, (double)attack.Energy / attack.ActivationEnergy); foreach (Loc point in attack.Targets) { Game.Threatened.Set(point.X, point.Y, blend); Game.Animations.Add(new FlashAnimation(Game.StateHandler.CurrentLayer, point.X, point.Y, blend)); } } } } while (Update()); }
public void ClearMaxHeap_LeavesCountOfZero(List <int> data) { // Arrange var heap = new MaxHeap <int>(data); // Act heap.Clear(); // Assert Assert.Empty(heap); }
public void TestClear() { MaxHeap <int> maxHeap = new MaxHeap <int>(); maxHeap.Add(1); maxHeap.Add(2); maxHeap.Add(3); maxHeap.Clear(); Assert.AreEqual(0, maxHeap.Count); maxHeap.Peek(); }
public void ClearingHeapsSetsSizeToZero() { MinHeap <int> minHeap = new MinHeap <int>(IntComparer); MaxHeap <int> maxHeap = new MaxHeap <int>(IntComparer); foreach (int element in elements) { maxHeap.Add(element); minHeap.Add(element); } maxHeap.Clear(); minHeap.Clear(); Assert.AreEqual(0, maxHeap.Size); Assert.AreEqual(0, minHeap.Size); }
public int[] MaxSlidingWindow2(int[] nums, int k) { var N = nums.Length; var result = new int[N - k + 1]; var maxHeap = new MaxHeap(); var j = 0; for (var i = 0; i <= (N - k); i++) { PopulateMaxHeap(maxHeap, i, k, nums); var maxInCurrentWindow = maxHeap.PeekMax(); result[j++] = maxInCurrentWindow; maxHeap.Clear(); } return(result); }
public void Clear() { testMaxHeap.Insert(9); testMaxHeap.Insert(8); testMaxHeap.Insert(7); testMaxHeap.Insert(2); testMaxHeap.Clear(); Dictionary <Int32, DoublyLinkedTreeNode <Int32> > allNodes = GetAllNodes(testMaxHeap); Assert.AreEqual(0, allNodes.Count); testMaxHeap.Insert(1); allNodes = GetAllNodes(testMaxHeap); Assert.AreEqual(1, allNodes.Count); Assert.IsNull(allNodes[1].ParentNode); Assert.IsNull(allNodes[1].LeftChildNode); Assert.IsNull(allNodes[1].RightChildNode); }