protected override void OnEnabled()
        {
            base.OnEnabled();

            ChatMessages = new LimitedQueue <Tuple <string, string, string> >(SettingsSystem.CurrentSettings.ChatBuffer);
            SetupRoutine(new RoutineDefinition(100, RoutineExecution.Update, ProcessReceivedMessages));
        }
    // Token: 0x06001C0D RID: 7181 RVA: 0x0008EE20 File Offset: 0x0008D020
    private IEnumerator StartNewSpeedhackDetection()
    {
        yield return(new WaitForSeconds(5f));

        CheatDetection.SyncSystemTime();
        LimitedQueue <float> timeDifference = new LimitedQueue <float>(5);

        for (;;)
        {
            yield return(new WaitForSeconds(5f));

            if (GameState.Current.HasJoinedGame)
            {
                timeDifference.Enqueue((float)this.GameTime / (float)this.RealTime);
                CheatDetection.SyncSystemTime();
                if (timeDifference.Count == 5)
                {
                    float avg = this.averageSpeedHackResults(timeDifference);
                    if (avg != -1f)
                    {
                        if ((double)avg >= 0.75)
                        {
                            break;
                        }
                        timeDifference.Clear();
                    }
                }
            }
        }
        AutoMonoBehaviour <CommConnectionManager> .Instance.Client.Lobby.Operations.SendSpeedhackDetectionNew(timeDifference.ToList <float>());

        yield break;
    }
Beispiel #3
0
        public void LimitedQueue_SizeAndCountLimit()
        {
            LimitedQueue <SizedItem> queue = new LimitedQueue <SizedItem>();

            queue.CountLimit = 3;
            queue.SizeLimit  = 10;

            queue.Enqueue(new SizedItem(0, 1));
            queue.Enqueue(new SizedItem(1, 1));
            queue.Enqueue(new SizedItem(2, 1));
            queue.Enqueue(new SizedItem(3, 1));
            Assert.AreEqual(3, queue.Count);
            Assert.AreEqual(3, queue.Size);
            Assert.AreEqual(1, queue.Dequeue().Value);
            Assert.AreEqual(2, queue.Dequeue().Value);
            Assert.AreEqual(3, queue.Dequeue().Value);
            Assert.AreEqual(0, queue.Count);
            Assert.AreEqual(0, queue.Size);

            queue.CountLimit = queue.CountLimit + 1;
            queue.Enqueue(new SizedItem(0, 3));
            queue.Enqueue(new SizedItem(1, 3));
            queue.Enqueue(new SizedItem(2, 3));
            queue.Enqueue(new SizedItem(3, 3));
            Assert.AreEqual(3, queue.Count);
            Assert.AreEqual(9, queue.Size);
            Assert.AreEqual(1, queue.Dequeue().Value);
            Assert.AreEqual(2, queue.Dequeue().Value);
            Assert.AreEqual(3, queue.Dequeue().Value);
            Assert.AreEqual(0, queue.Count);
            Assert.AreEqual(0, queue.Size);
        }
        //public static Dictionary<string, FlushDetector> _flushers = new Dictionary<string, FlushDetector>();

        private static LimitedQueue <ChatMessage> GetOrCreateRoomHistory(string id)
        {
            LimitedQueue <ChatMessage> h = null;

            if (!String.IsNullOrEmpty(id))
            {
                id = id.ToLower();


                if (_history.ContainsKey(id))
                {
                    h = _history[id];
                }
                else
                {
                    //Try get from cache
                    if (CacheHandler.Instance.Exists(CacheKey(id)))
                    {
                        h = CacheHandler.Instance.Retrieve <LimitedQueue <ChatMessage> >(CacheKey(id));
                    }
                    else
                    {
                        h = new LimitedQueue <ChatMessage>(100);
                    }

                    h.Limit = 100;
                    _history.Add(id, h);
                }
            }

            return(h);
        }
Beispiel #5
0
        public void LimitedQueue_Basic()
        {
            LimitedQueue <int> queue;

            try
            {
                queue = new LimitedQueue <int>(0);
                Assert.Fail("Expected ArgumentException");
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(ArgumentException));
            }

            queue = new LimitedQueue <int>(5);
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);
            Assert.AreEqual(5, queue.Count);

            queue.Enqueue(6);
            Assert.AreEqual(5, queue.Count);

            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(i + 2, queue.Dequeue());
            }
        }
Beispiel #6
0
        public void LimitedQueue_CountLimit()
        {
            LimitedQueue <PlainItem> queue = new LimitedQueue <PlainItem>();

            queue.CountLimit = 3;
            queue.Enqueue(new PlainItem(0));
            queue.Enqueue(new PlainItem(1));
            queue.Enqueue(new PlainItem(2));
            Assert.AreEqual(3, queue.Count);
            Assert.AreEqual(0, queue.Dequeue().Value);
            Assert.AreEqual(1, queue.Dequeue().Value);
            Assert.AreEqual(2, queue.Dequeue().Value);
            Assert.AreEqual(0, queue.Count);

            queue.Enqueue(new PlainItem(0));
            queue.Enqueue(new PlainItem(1));
            queue.Enqueue(new PlainItem(2));
            queue.Enqueue(new PlainItem(3));
            Assert.AreEqual(3, queue.Count);
            Assert.AreEqual(1, queue.Dequeue().Value);
            Assert.AreEqual(2, queue.Dequeue().Value);
            Assert.AreEqual(3, queue.Dequeue().Value);
            Assert.AreEqual(0, queue.Count);

            queue.Enqueue(new PlainItem(0));
            queue.Enqueue(new PlainItem(1));
            queue.Enqueue(new PlainItem(2));
            queue.CountLimit = 2;
            Assert.AreEqual(2, queue.Count);
            Assert.AreEqual(1, queue.Dequeue().Value);
            Assert.AreEqual(2, queue.Dequeue().Value);
        }
Beispiel #7
0
        private bool MonitorCast()
        {
            // Monitor the cast and break when either the player
            // moved or casting has been finished.
            var position    = _fface.Player.Position;
            var castHistory = new LimitedQueue <short>(100);
            var prior       = _fface.Player.CastPercentEx;

            while (!castHistory.RepeatsN(30).Any())
            {
                if (prior == _fface.Player.CastPercentEx)
                {
                    castHistory.AddItem(_fface.Player.CastPercentEx);
                }

                // Has moved
                if (position.X != _fface.Player.PosX ||
                    position.Y != _fface.Player.PosY ||
                    position.Z != _fface.Player.PosZ)
                {
                    return(false);
                }

                prior = _fface.Player.CastPercentEx;

                Thread.Sleep(100);
            }

            // Report success
            if (castHistory.RepeatsN(30).Any(x => x.Equals(100)))
            {
                return(true);
            }
            return(false);
        }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Taskstate"/> class.
 /// </summary>
 /// <param name="character">The character.</param>
 /// <param name="options">The options.</param>
 public Taskstate(Character character, Options options)
 {
     Character             = character;
     Options               = options;
     PreviousChestIndieces = new LimitedQueue <int>(3);
     _timer.Elapsed       += Update;
     DominionSergeantIndex = -1;
 }
Beispiel #9
0
 // Use this for initialization
 void Start()
 {
     text       = GetComponentInChildren <Text> ();
     image      = GetComponent <Image> ();
     panelColor = image.color;
     textColor  = text.color;
     queue      = new LimitedQueue <string> (SizeQueue);
     text.text  = "";
 }
        public TuringNoveltyScorer(NoveltySearchParameters parameters)
        {
            _params  = parameters;
            _archive = new LimitedQueue <Behaviour <TGenome> >(_params.ArchiveLimit);

            _pMin              = _params.PMin;
            _generation        = 0;
            _reportInterval    = _params.ReportInterval;
            _knnTotalTimeSpent = 0;
        }
Beispiel #11
0
        public static void TestEnqueue()
        {
            LimitedQueue <int> queue = new LimitedQueue <int>(3);

            queue.Add(1);
            queue.Add(2);
            queue.Add(3);
            Assert.AreEqual(queue.Count, 3);
            queue.Add(4);
            Assert.AreEqual(queue.Count, 3);
        }
        public void LimitedQueueLimitA()
        {
            LimitedQueue<int> q = new LimitedQueue<int>(3);

            q.Enqueue(1);
            q.Enqueue(2);
            q.Enqueue(3);
            q.Enqueue(4);

            Assert.AreEqual(2, q.Dequeue());
        }
Beispiel #13
0
 public void TestEnqueue()
 {
     var queue = new LimitedQueue<int>(2);
     Assert.AreEqual(2, queue.Limit);
     queue.Enqueue(1);
     Assert.AreEqual(1, queue.Count);
     queue.Enqueue(2);
     Assert.AreEqual(2, queue.Count);
     queue.Enqueue(3);
     Assert.AreEqual(2, queue.Count);
 }
Beispiel #14
0
        public void LimitedQueueLimitA()
        {
            LimitedQueue <int> q = new LimitedQueue <int>(3);

            q.Enqueue(1);
            q.Enqueue(2);
            q.Enqueue(3);
            q.Enqueue(4);

            Assert.AreEqual(2, q.Dequeue());
        }
Beispiel #15
0
        public void TestEnqueue()
        {
            var queue = new LimitedQueue <int>(2);

            Assert.AreEqual(2, queue.Limit);
            queue.Enqueue(1);
            Assert.AreEqual(1, queue.Count);
            queue.Enqueue(2);
            Assert.AreEqual(2, queue.Count);
            queue.Enqueue(3);
            Assert.AreEqual(2, queue.Count);
        }
 public PlayarStatisistics(Guid id, PlayarName name)
 {
     Id = id;
     Name = name;
     Score = InitialScore;
     ScoreHistory = new LimitedQueue<Tuple<double, Activity>>(KeepLatestResults);
     Offensive = new GamePercentage();
     Defensive = new GamePercentage();
     Total = new GamePercentage();
     _winning = new Streak(5);
     _loosing = new Streak(5);
 }
 public PlayarStatisistics(Guid id, PlayarName name)
 {
     Id           = id;
     Name         = name;
     Score        = InitialScore;
     ScoreHistory = new LimitedQueue <Tuple <double, Activity> >(KeepLatestResults);
     Offensive    = new GamePercentage();
     Defensive    = new GamePercentage();
     Total        = new GamePercentage();
     _winning     = new Streak(5);
     _loosing     = new Streak(5);
 }
Beispiel #18
0
 public MachineAgent(Agent creator, string name, bool debug, DirectoryAgent directoryAgent, Machine machine, WorkTimeGenerator workTimeGenerator) : base(creator, name, debug)
 {
     _directoryAgent   = directoryAgent;
     ProgressQueueSize = 1;                     // TODO COULD MOVE TO MODEL for CONFIGURATION, May not required anymore
     Queue             = new List <WorkItem>(); // ThenBy( x => x.Status)
     ProcessingQueue   = new LimitedQueue <WorkItem>(1);
     Machine           = machine;
     WorkTimeGenerator = workTimeGenerator;
     ItemsInProgess    = false;
     RegisterService();
     QueueLength = 45; // plaing forecast
 }
Beispiel #19
0
        public static List<string> ReadLastLines(string fileName, int linesCount = 10) {
            string line;

            var queue = new LimitedQueue<string>(linesCount);
            var shareMode = FileShare.ReadWrite | FileShare.Delete;
            using (var s = new FileStream(fileName, FileMode.Open, FileAccess.Read, shareMode))
            using (var reader = new StreamReader(s)) {
                while ((line = reader.ReadLine()) != null) {
                    queue.Enqueue(reader.ReadLine());
                }
            }
            return queue.ToList();
        }
Beispiel #20
0
 public CustomMessageData(string Name, Action <byte[], Client> OnMessageReceived, bool ShouldStoreData, int QueueLimit = 1)
 {
     this.ShouldStoreData   = ShouldStoreData;
     this.Name              = Name;
     this.OnMessageReceived = OnMessageReceived;
     if (ShouldStoreData)
     {
         StoredData = new LimitedQueue <byte[]>(QueueLimit);
     }
     else
     {
         StoredData = null;
     }
 }
Beispiel #21
0
 public MapleClient(Socket session)
 {
     SClient = new CClientSocket(this, session);
     Host    = SClient.Host;
     Port    = SClient.Port;
     ServerConsole.Info(String.Format("{0}:{1} Connnected", Host, Port));
     Channel         = 1;
     Connected       = true;
     LastPacketsSent = new LimitedQueue <PacketWriter>(10);
     CheatTracker    = new OffenceTracker()
     {
         Client = this
     };
 }
Beispiel #22
0
        /// <summary>
        /// Add an item(s) to the LZ77 queue
        /// </summary>
        /// <typeparam name="T">Type of the data being addeded</typeparam>
        /// <param name="data">Data to take the data from</param>
        /// <param name="queue">Queue of data to add to</param>
        /// <param name="startPosition">Position to start adding from</param>
        /// <param name="count">Count of items to copy</param>
        /// <returns>Ending position</returns>
        private static int AddQueueItems <T>(ref T[] data, ref LimitedQueue <T> queue, int startPosition, int count)
        {
            // Create a copy of the start position
            var endPosition = startPosition;

            // Iterate over it, adding the data items required
            for (var i = 0; i < count; i++, endPosition++)
            {
                queue.Enqueue(data[startPosition + i]);
            }

            // Return the end position
            return(endPosition);
        }
Beispiel #23
0
        //public Surface[][] SurfacePrediction = new Surface[Settings.PredictionLength][];
        public TankPlus(long id)
        {
            Id = id;

            for (int i = 0; i < Settings.BufferSize; ++i)
            {
                AngleHistory[i] = new LimitedQueue<double>(Settings.BufferSize - i, 0);
                SpeedHistory[i] = new LimitedQueue<double>(Settings.BufferSize - i, 0);
                OrientationHistory[i] = new LimitedQueue<double>(Settings.BufferSize - i, 0);
            }

            //for (int i = 0; i < Settings.PredictionLength; ++i)
            //    SurfacePrediction[i] = new Surface[4];
        }
        public static void Add(ChatMessage message)
        {
            LimitedQueue <ChatMessage> h = GetOrCreateRoomHistory(message.RoomID);

            if (h != null)
            {
                message.CreationDate = Data.Repository.CurrentDate;
                h.Add(message);

                Task.Run(() => {
                    CacheHandler.Instance.Replace <LimitedQueue <ChatMessage> >(CacheKey(message.RoomID), h, null);
                });
            }
        }
Beispiel #25
0
        public void AddingItemsBehindLimitRemovesFirstIn()
        {
            LimitedQueue <int> q = new LimitedQueue <int>(3);

            Assert.AreEqual(0, q.Count);
            q.Enqueue(1);
            Assert.AreEqual(1, q.Count);
            q.Enqueue(2);
            Assert.AreEqual(2, q.Count);
            q.Enqueue(3);
            Assert.AreEqual(3, q.Count);
            q.Enqueue(4);
            Assert.AreEqual(3, q.Count);
            Assert.IsFalse(q.Contains(1));
        }
Beispiel #26
0
        public void LimitedQueue_Basic()
        {
            LimitedQueue <int> queue = new LimitedQueue <int>();

            Assert.AreEqual(0, queue.Count);
            queue.Enqueue(0);
            Assert.AreEqual(1, queue.Count);
            queue.Enqueue(1);
            Assert.AreEqual(2, queue.Count);

            Assert.AreEqual(0, queue.Dequeue());
            Assert.AreEqual(1, queue.Dequeue());
            queue.Clear();
            Assert.AreEqual(0, queue.Count);
        }
        public void LimitedQueueLimitB()
        {
            LimitedQueue<int> q = new LimitedQueue<int>(10);

            q.Enqueue(1);
            q.Enqueue(2);
            q.Enqueue(3);
            q.Enqueue(4);
            q.Enqueue(5);
            q.Enqueue(6);
            q.Enqueue(7);

            q.Limit = 2;

            Assert.AreEqual(6, q.Dequeue());
        }
Beispiel #28
0
 public USocket(uint id)
 {
     this.id         = id;
     netState        = NetState.None;
     sequence        = 0;
     ack             = 0;
     ackbit          = 0;
     quantics        = new Dictionary <byte, Packet>();
     cacheSend       = new List <Packet>();
     cacheReceived   = new List <Packet>();
     cacheLost       = new List <byte>();
     lastConnectTime = lastReceviedTime = DateTime.MinValue;
     connectTimes    = 0;
     sends           = new LimitedQueue <Packet>(10);
     receives        = new LimitedQueue <Packet>(10);
 }
Beispiel #29
0
        public void LimitedQueueLimitB()
        {
            LimitedQueue <int> q = new LimitedQueue <int>(10);

            q.Enqueue(1);
            q.Enqueue(2);
            q.Enqueue(3);
            q.Enqueue(4);
            q.Enqueue(5);
            q.Enqueue(6);
            q.Enqueue(7);

            q.Limit = 2;

            Assert.AreEqual(6, q.Dequeue());
        }
Beispiel #30
0
        static void Main()
        {

            var queue = new LimitedQueue<int>(3);

            for (var i = 0; i < Environment.ProcessorCount; i++)
            {
                var worker = new WorkingThread(i, queue);

                ThreadPool.QueueUserWorkItem(_ =>
                {
                    worker.DoWork();
                });
            }

            Console.ReadLine();
        }
Beispiel #31
0
        public void LimitedQueue_Dispose()
        {
            LimitedQueue <Test> queue;
            Test item1 = new Test(1);
            Test item2 = new Test(2);
            Test item3 = new Test(3);

            queue = new LimitedQueue <Test>(2);
            queue.Enqueue(item1);
            queue.Enqueue(item2);
            queue.Enqueue(item3);

            Assert.AreEqual(2, queue.Count);
            Assert.IsTrue(item1.Disposed);
            Assert.IsFalse(item2.Disposed);
            Assert.IsFalse(item2.Disposed);
        }
Beispiel #32
0
        private string ToMultiLineString(LimitedQueue <LogModel> logMessages)
        {
            var result = new StringBuilder();

            var copy = logMessages.ToList();

            foreach (var logMessage in copy)
            {
                if (logMessage == null)
                {
                    continue;
                }
                result.Append($"{logMessage.LogLevel} {logMessage.Message}{Environment.NewLine}");
            }

            return(result.ToString());
        }
Beispiel #33
0
        public MovementClass1(string s)
        {
            base.name = s;
            this.setTreshold(.2d, 0.5d);
            myQueue = new LimitedQueue <GMVector>(_queueLength);

            myAverages = new LimitedQueue <gRMSAverage>(_queueLength);

            //need at least 3 seconds recording size, but only record crossing values
            myCrossUPs   = new LimitedQueue <gRMSAverage>(_queueLength);
            myCrossDOWNs = new LimitedQueue <gRMSAverage>(_queueLength);

            myGmin = 0.2d;         //was 0.9d but we get a deltaAverage of about around 0.14
            myTmin = 10;           // 15 is equal to 0.75 seconds if samples per seconds is 20

            _treshCountRMS = 2000; //should be 3000 for 60 samples in 3 seconds at 20 samples/second,
                                   //BUT we only see ~2 samples per second

            basicLogger("Movement1 Class\r\nx\ty\tz\ttick\tdeltaG");
        }
        public MovementClass1(string s)
        {
            base.name = s;
            this.setTreshold(.2d, 0.5d);
            myQueue = new LimitedQueue<GMVector>(_queueLength);

            myAverages = new LimitedQueue<gRMSAverage>(_queueLength);

            //need at least 3 seconds recording size, but only record crossing values
            myCrossUPs = new LimitedQueue<gRMSAverage>(_queueLength);
            myCrossDOWNs = new LimitedQueue<gRMSAverage>(_queueLength);

            myGmin = 0.2d; //was 0.9d but we get a deltaAverage of about around 0.14
            myTmin = 10; // 15 is equal to 0.75 seconds if samples per seconds is 20

            _treshCountRMS = 2000;  //should be 3000 for 60 samples in 3 seconds at 20 samples/second,
                                 //BUT we only see ~2 samples per second

            basicLogger("Movement1 Class\r\nx\ty\tz\ttick\tdeltaG");
        }
Beispiel #35
0
    private void Awake()
    {
        groundQueue = new LimitedQueue <bool>(groundedBufferSize);

        virtualController = GetComponent <VirtualController>();
        currentMove       = idleMove;
        idleMove.EnterState(this);
        accelRatePerSec = maxSpeed / timeZeroToMax;
        decelRatePerSec = -maxSpeed / timeMaxToZero;

        timeToJumpApex = jumpHeight / 10;
        gravity        = -(2 * jumpHeight) / Mathf.Pow(timeToJumpApex, 2);

        minimumJumpVelocity = Mathf.Abs(gravity) * timeToJumpApex;

        normalGravity       = gravity;
        jumpSlider.maxValue = maxJumpBoost;

        audioObj = GameObject.FindGameObjectWithTag("audio");
    }
Beispiel #36
0
        public void LimitedQueue_AutoDispose()
        {
            LimitedQueue <PlainDisposable> queue = new LimitedQueue <PlainDisposable>();
            PlainDisposable v0 = new PlainDisposable(0);
            PlainDisposable v1 = new PlainDisposable(1);
            PlainDisposable v2 = new PlainDisposable(2);
            PlainDisposable v3 = new PlainDisposable(3);

            Assert.IsFalse(queue.AutoDispose);
            queue.CountLimit = 3;

            queue.Enqueue(v0);
            queue.Enqueue(v1);
            queue.Enqueue(v2);
            queue.Enqueue(v3);
            Assert.AreEqual(3, queue.Count);

            Assert.IsFalse(v0.IsDisposed);
            Assert.AreEqual(1, queue.Dequeue().Value);
            queue.Clear();
            Assert.IsFalse(v1.IsDisposed);
            Assert.IsFalse(v2.IsDisposed);
            Assert.IsFalse(v3.IsDisposed);

            queue.AutoDispose = true;

            queue.Enqueue(v0);
            queue.Enqueue(v1);
            queue.Enqueue(v2);
            queue.Enqueue(v3);
            Assert.AreEqual(3, queue.Count);

            Assert.IsTrue(v0.IsDisposed);
            Assert.AreEqual(1, queue.Dequeue().Value);
            queue.Clear();
            Assert.IsFalse(v1.IsDisposed);
            Assert.IsTrue(v2.IsDisposed);
            Assert.IsTrue(v3.IsDisposed);
        }
Beispiel #37
0
        public void LimitedQueue_AutoDisposeSized()
        {
            LimitedQueue <SizedDisposable> queue = new LimitedQueue <SizedDisposable>();
            SizedDisposable v0 = new SizedDisposable(0, 3);
            SizedDisposable v1 = new SizedDisposable(1, 3);
            SizedDisposable v2 = new SizedDisposable(2, 3);
            SizedDisposable v3 = new SizedDisposable(3, 3);

            Assert.IsFalse(queue.AutoDispose);
            queue.SizeLimit = 10;

            queue.Enqueue(v0);
            queue.Enqueue(v1);
            queue.Enqueue(v2);
            queue.Enqueue(v3);
            Assert.AreEqual(3, queue.Count);

            Assert.IsFalse(v0.IsDisposed);
            Assert.AreEqual(1, queue.Dequeue().Value);
            queue.Clear();
            Assert.IsFalse(v1.IsDisposed);
            Assert.IsFalse(v2.IsDisposed);
            Assert.IsFalse(v3.IsDisposed);

            queue.AutoDispose = true;

            queue.Enqueue(v0);
            queue.Enqueue(v1);
            queue.Enqueue(v2);
            queue.Enqueue(v3);
            Assert.AreEqual(3, queue.Count);

            Assert.IsTrue(v0.IsDisposed);
            Assert.AreEqual(1, queue.Dequeue().Value);
            queue.Clear();
            Assert.IsFalse(v1.IsDisposed);
            Assert.IsTrue(v2.IsDisposed);
            Assert.IsTrue(v3.IsDisposed);
        }
 private void Awake()
 {
     inputQueue = new LimitedQueue <bool>(inputQueueSize);
 }
Beispiel #39
0
		public void ManageInventory()
		{
			bool runInventory = true;
			//Queue commands = new Queue();
			
			LimitedQueue<string> messageBoard = new LimitedQueue<string>(15);
			List<string> commands = new List<string>();
			
			while (runInventory)
			{
				Console.Clear();
				Console.Write(this.ToString());
				Console.WriteLine();
				Console.WriteLine("To strip item, write 'strip #of_equipment'\n" +
					"To equip item, wrire 'equip #of_equipment'\n" +
					"To drop item from inventory, write 'drop #of_equipment'\n" +
				    "To use the item, write 'use #of_equipment'\n" +
					"To go back to game, press Escape\n");
				
				foreach (string s in messageBoard)
				{
					Console.WriteLine(s);
				}
				
				string response = commands.ListThroughCommands();
				commands.Add(response);
				messageBoard.Enqueue(response);
				string[] words = response.Split(' ');
				int n;
				switch (words[0])
				{
				case "close":
				{
					runInventory = false;
					break;
				}
				case "strip":
				{
					try
					{
						n = int.Parse(words[1]);
						messageBoard.Enqueue(this.StripItem(this.equiped.bag[n-1]));
					}
					catch
					{
						messageBoard.Enqueue("Something wrong with your output");
					}
					break;
				}
				case "equip":
				{
					try
					{
						n = int.Parse(words[1]);
						messageBoard.Enqueue(this.EquipItem(this.bag.bag[n-1], true));
					}
					catch
					{
						messageBoard.Enqueue("Something wrong with your output");
					}
					break;
				}
				case "drop":
				{
					try
					{
						n = int.Parse(words[1]);
						Location loc = ThisGame.dungeon.location[this.X,this.Y];
						if (loc.CanDropItemOnto())
						{
							Item i = this.bag.bag[n-1];
							messageBoard.Enqueue(this.DropItem(i));
							ThisGame.dungeon.location[this.X,this.Y].DropItemOnLocation(i);
							ThisGame.dungeon.location[this.X,this.Y].UpdateSymbol();
						}
					}
					catch
					{
						messageBoard.Enqueue("Something wrong with your output");
					}
					break;
				}
				case "use":
				{
					try
					{
						n = int.Parse(words[1]);
						Item i = this.bag.bag[n-1];
						messageBoard.Enqueue(i.Use());
					}
					catch
					{
						messageBoard.Enqueue("Something wrong with your output");
					}
					break;
				}
				default:
				{
					messageBoard.Enqueue("Can not recognize the command");
					break;
				}
				}
			
			}
			
		}
Beispiel #40
0
        public override void VoluntaryAction(Player p)
        {
            bool lootChest = true;

            LimitedQueue<string> messageBoard = new LimitedQueue<string>(10);
            List<string> commands = new List<string>();

            while (lootChest)
            {
                Console.Clear();
                Console.WriteLine(this.message);
                Console.Write(this.Content.ToString());
                Console.WriteLine();
                Console.WriteLine("YOUR INVENTORY");
                Console.Write(p.bag.ToString());
                Console.WriteLine();

                Console.WriteLine("To pick item, write 'pick #of_equipment' or write 'pick all' to take everything\n" +
                    "To drop item from inventory, write 'drop #of_equipment'\n" +
                    "To go back to game, press Escape\n");

                foreach (string s in messageBoard)
                {
                    Console.WriteLine(s);
                }

                string response = commands.ListThroughCommands();
                commands.Add(response);
                messageBoard.Enqueue(response);
                string[] words = response.Split(' ');
                int n;
                switch (words[0])
                {
                case "close":
                {
                    lootChest = false;
                    break;
                }
                case "pick":
                {
                    try
                    {
                        if (words[1] == "all")
                        {
                            if (p.bag.maxsize - p.bag.Count() - this.Content.Count() < 0)
                            {
                                messageBoard.Enqueue("You don't have enough space to take all items in your bag.");
                                break;
                            }
                            foreach (Item i in this.Content.bag)
                            {
                                p.PickItem(i);
                            }
                            this.Content.RemoveAll();
                            messageBoard.Enqueue("All items has been taken");
                        } else {
                            n = int.Parse(words[1]);
                            if (p.bag.maxsize - p.bag.Count() > 0)
                            {
                                p.PickItem(this.Content.bag[n-1]);
                                messageBoard.Enqueue(this.Content.bag[n-1].Name);
                                this.Content.Remove(this.Content.bag[n-1]);
                            }
                            else
                                messageBoard.Enqueue("You don't have enough space to take all items in your bag.");
                        }
                    }
                    catch
                    {
                        messageBoard.Enqueue("Something wrong with your command");
                    }
                    break;
                }
                case "drop":
                {
                    try
                    {
                        n = int.Parse(words[1]);
                        this.Content.Add(p.bag.GetItem(p.bag.bag[n-1].Name));
                        messageBoard.Enqueue(p.bag.bag[n-1].Name);
                        p.DropItem(p.bag.bag[n-1]);
                    }
                    catch
                    {
                        messageBoard.Enqueue("Something wrong with your command");
                    }
                    break;
                }
                default:
                {
                    messageBoard.Enqueue("Can not recognize the command");
                    break;
                }
                }

            }
        }
Beispiel #41
0
 public MemoryStorage(int capacity)
 {
     _queue = new LimitedQueue<SyslogMessage>(capacity);
 }
Beispiel #42
0
        private void UpdateComponents(ref LimitedQueue<double>[] history, ref double[] valuePrediction)
        {
            for (int i = 1; i < Settings.BufferSize; ++i)
                history[i].Enqueue(history[i - 1].Last - history[i - 1].Penultimate);

            double[] tmpValues = new double[Settings.BufferSize];
            int tmpBufferSizeMinusOne = Settings.BufferSize - 1;

            for (int i = 0; i < tmpBufferSizeMinusOne; ++i)
            {
                double tmpSum = 0;

                foreach (double tmpValue in history[i])
                    tmpSum += tmpValue;

                tmpValues[i] = tmpSum / history[i].Limit;
            }

            tmpValues[tmpBufferSizeMinusOne] = 0;

            for (int i = 0; i < Settings.PredictionLength; ++i)
            {
                valuePrediction[i] = tmpValues[0];

                for (int j = tmpBufferSizeMinusOne; j > 0; --j)
                    tmpValues[j - 1] += tmpValues[j];
            }
        }
 public void Uninitialize()
 {
     queue = null;
 }
Beispiel #44
0
        private bool MonitorCast()
        {
            // Monitor the cast and break when either the player
            // moved or casting has been finished.
            var position = _fface.Player.Position;
            var castHistory = new LimitedQueue<short>(100);
            var prior = _fface.Player.CastPercentEx;

            while (!castHistory.RepeatsN(30).Any())
            {
                if (prior == _fface.Player.CastPercentEx)
                    castHistory.AddItem(_fface.Player.CastPercentEx);

                // Has moved
                if (position.X != _fface.Player.PosX ||
                    position.Y != _fface.Player.PosY ||
                    position.Z != _fface.Player.PosZ) return false;

                prior = _fface.Player.CastPercentEx;

                Thread.Sleep(100);
            }

            // Report success
            if (castHistory.RepeatsN(30).Any(x => x.Equals(100))) return true;
            return false;
        }
Beispiel #45
0
 public SemaphoreGesture()
 {
     _history = new LimitedQueue<Semaphore>(_historyCount);
 }
 public WorkingThread(int id, LimitedQueue<int> queue)
 {
     ThreadId = id;
     _queue = queue;
 }
        public void LimitedQueueLimitC()
        {
            LimitedQueue<string> q = new LimitedQueue<string>(10);

            Assert.AreEqual(10, q.Limit);
        }
 public void Initialize()
 {
     queue = new LimitedQueue<FileSystemInfo> ();
     ScanDirectory (directory);
 }
Beispiel #49
0
 public ClapGesture()
 {
     _history = new LimitedQueue<Hands>(PointCount);
 }
 public PrintingCalculator()
 {
     RunningCalculations = new LimitedQueue<string>();
     RunningCalculations.Limit = 20;
     RunningTotal = 0;
 }
Beispiel #51
0
        public void Run(int timeLimit)
        {
            int startTime = Environment.TickCount;
            int iterationStartTime = 0;
            int iterationTime = 0;
            int maxIterationTime = 0;
            int[] initialSolution = null;
            double initialFitness = 0;
            int[] currentSolution = null;
            double currentFitness = 0;
            int[] nextSolution = null;
            double nextFitness = 0;
            Tuple<int, int> nextTabu = null;
            int[] neighbor = null;
            double neighborFitness = 0;

            LimitedQueue<Tuple<int,int>> tabuList = new LimitedQueue<Tuple<int, int>>(TabuListLength);

            currentSolution = InitialSolution();
            initialSolution = new int[currentSolution.Length];
            currentSolution.CopyTo(initialSolution, 0);
            currentFitness = Fitness(currentSolution);

            BestFitness = currentFitness;
            BestSolution = currentSolution;

            while (Environment.TickCount - startTime < timeLimit - maxIterationTime) {
                iterationStartTime = Environment.TickCount;
                int count = 0;
                nextSolution = null;
                nextFitness = int.MaxValue;
                nextTabu = null;
                bool success = false;

                // Finding the next movement.
                Tuple<int, int> tabu = new Tuple<int, int>(-1, -1);
                Tuple<int, int> lastTabu = new Tuple<int, int>(-1, -1);

                while (count < NeighborChecks){
                    count ++;
                    neighbor = GetNeighbor(currentSolution);
                    tabu = GetTabu(currentSolution, neighbor);
                    if(!tabuList.Contains(tabu) && tabu != lastTabu) {
                        neighborFitness = Fitness(neighbor);
                        if (nextFitness > neighborFitness) {
                            nextSolution = neighbor;
                            nextFitness = neighborFitness;
                            nextTabu = tabu;
                            success = true;
                        }
                        if (currentFitness > nextFitness) {
                            break;
                        }
                    }
                }
                if (!success) {
                    nextSolution = initialSolution;
                    nextFitness = initialFitness;
                }

                // Aspiration.
                if (BestFitness > nextFitness) {
                    tabuList.Clear();
                    BestSolution = nextSolution;
                    BestFitness = nextFitness;
                }

                tabuList.Enqueue(nextTabu);
                currentSolution = nextSolution;
                currentFitness = nextFitness;

                iterationTime = Environment.TickCount - iterationStartTime;
                maxIterationTime = (maxIterationTime < iterationTime) ? iterationTime : maxIterationTime;
            }
        }
Beispiel #52
0
 public TraceListener()
 {
     this.StringQueue = new LimitedQueue<string>(MAX_CACHED_MESSAGES);
 }