// public Trigger(uint FirstDigit, uint SecondDigit) { First = new ClosePrime(FirstDigit); Second = new ClosePrime(SecondDigit); PingAttempts = 0; MatchingDigits = 0; }
//This method is used when you create a queue without any parameters, making it //not dependent on ClosePrime instantiation to work. //Preconditions: Queue was created using the default (no parameters) constructor. //Postconditions: Will update the initiallized status along with creating //closeprime objects with hidden digits passed in as a parameter. public bool Construct(uint size, Queue <uint> digits) { if (!Initallized) { if (size > MaxCapicity) { size = size % 11; } if (size != (uint)digits.Count) { size = (uint)digits.Count; } CurSize = size; for (uint i = 0; i < CurSize; i++) { uint dig = digits.Dequeue(); ClosePrime add = new ClosePrime(dig); queue.Enqueue(add); } Initallized = true; return(true); } return(false); }
//constructors //Preconditions:None //Postconditions: Creates 2 randomized numbers for closeprime objects, //since we require both objects for Trigger functionality. public Trigger() { Trigger.FirstDig = (uint)rand.Next(); Trigger.SecondDig = (uint)rand.Next(); First = new ClosePrime(GetFirstDig()); Second = new ClosePrime(GetSecondDig()); PingAttempts = 0; MatchingDigits = 0; }
//Preconditions: The queue isn't at max capacity. //Postconditions: Queue will have 1 more closeprime object. public bool Add(uint NewDigit) { if (Initallized && CurSize < MaxCapicity) { ClosePrime x = new ClosePrime(NewDigit); queue.Enqueue(x); return(true); } return(false); }
//Preconditions:None //Postconditions: The queue will be created with up to 10 closeprime objects, with positive hidden digits. public MultiQ(uint size, Queue <uint> digits) { if (size > MaxCapicity) { size = size % 11; } if (size != (uint)digits.Count) { size = (uint)digits.Count; } CurSize = size; for (uint i = 0; i < CurSize; i++) { uint dig = digits.Dequeue(); ClosePrime add = new ClosePrime(dig); queue.Enqueue(add); } MaxPinged = 0; MinPinged = 40000; TotalPinged = 0; Initallized = true; }
//Preconditions: For a non-zero output the queue must have at least 1 closeprime //object on it. Pinging a value of 0 is fine because the closePrime class will update it to 5. //Postconditions: It will update the data members. public uint[] Ping(uint PingNum) { uint[] values = new uint[2]; uint value; if (Initallized && CurSize > 0) { SetTotal(GetTotal() + 1); //I created a list to determine the minimum and maximum return values of this ping along //with updating the overall maximum, cumulative and minimum pinged values. List <uint> Returnvalues = new List <uint>((int)CurSize); for (int i = 0; i < CurSize; i++) { ClosePrime x = queue.Dequeue(); if (x.GetStatus() == 1) { x.Revive(); } value = x.Ping(PingNum); if (value > GetMaxPinged()) { SetMaxPinged(value); } if (value < GetMinPinged()) { SetMinPinged(value); } SetTotal(GetTotal() + value); //Since it's a queue (FIFO) dequeing everything and enqueuing works well. queue.Enqueue(x); Returnvalues.Add(value); } values[0] = Returnvalues.Min(); values[1] = Returnvalues.Max(); } return(values); }