public bool AddNewBallFromPlayer(GameObject newBall, GameObject collidingBall, bool isOnList = false)
    {
        bool isAdded = false;

        lock (canAddBallLock)
        {
            if (!MovementManager.specialMove)
            {
                Vector3 positionForNewBall;
                Vector3 positionForFirstBall;
                bool    isRight = MovementManager.CheckIfIsRightAndFindNewPositions(newBall, balls.Find(collidingBall), out positionForNewBall, out positionForFirstBall, balls.First);
                ballsThatCouldBeInSequence.Add(balls.Insert(newBall, collidingBall, isRight));
                ChangeBallsDirectionOnInsert(newBall, positionForFirstBall, positionForNewBall);
                MovementManager.specialMove = true;
                newBall.tag = "Ball";
                isAdded     = true;
            }
            else
            {
                if (!isOnList)
                {
                    ballsToAdd.Add(new NewBallToAdd(newBall, collidingBall));
                }
            }
        }
        return(isAdded);
    }
Ejemplo n.º 2
0
            given_empty_blist_when_one_element_is_inserted_at_zero_index_then_blist_iterator_should_return_element()
        {
            var count = 1;
            var expected = new int[count].Select(_ => _random.Next()).ToArray();

            var blist = new BList<int>();

            foreach (var item in expected)
                blist.Insert(0, item);

            CollectionAssert.AreEqual(expected, blist);
        }
Ejemplo n.º 3
0
        public void given_blist_when_item_added_then_collectionchanged_raised()
        {
            var blist = new BList<int>();

            var initial = new int[32].Select(_ => _random.Next()).ToArray();
            var expected = _random.Next();

            blist.AddRange(initial);

            NotifyCollectionChangedEventArgs args = null;
            blist.CollectionChanged += (_, a) => args = a;

            blist.Insert(16, expected);

            Assert.That(args, Is.Not.Null);
            Assert.That(args.Action, Is.EqualTo(NotifyCollectionChangedAction.Add));
            Assert.That(args.NewStartingIndex, Is.EqualTo(16));
            Assert.That(args.NewItems[0], Is.EqualTo(expected));
        }
Ejemplo n.º 4
0
            given_existing_blist_when_elements_are_inserted_at_index_zero_then_blist_iterator_should_return_correct_latest_elements
            ()
        {
            var initial = new int[512].Select(_ => _random.Next()).ToArray();
            var insertzero = new int[256].Select(_ => _random.Next()).ToArray();
            var expected = insertzero.Reverse().Concat(initial).ToArray();

            var blist = new BList<int>();

            foreach (var item in initial)
                blist.Add(item);

            foreach (var item in insertzero)
                blist.Insert(0, item);

            CollectionAssert.AreEqual(expected, blist);
        }
Ejemplo n.º 5
0
            given_existing_blist_when_elements_are_inserted_in_middle_then_blist_iterator_should_return_correct_latest_elements
            ()
        {
            var initial = new int[768].Select(_ => _random.Next()).ToArray();
            var inserts = new int[256].Select(_ => _random.Next()).ToArray();
            var expected = initial.Take(256).Concat(inserts).Concat(initial.Skip(256)).ToArray();

            var blist = new BList<int>();

            foreach (var item in initial)
                blist.Add(item);

            for (int i = 0; i < 256; i++)
                blist.Insert(256 + i, inserts[i]);

            Assert.That(blist.Count, Is.EqualTo(1024));

            CollectionAssert.AreEqual(expected, blist);
        }
Ejemplo n.º 6
0
            given_empty_blist_when_elements_are_inserted_at_zero_index_individually_then_blist_iterator_should_return_elements
            ()
        {
            var count = 1024;
            var initial = new int[count].Select(_ => _random.Next()).ToArray();
            var expected = initial.Reverse().ToArray();

            var blist = new BList<int>();

            foreach (var item in initial)
                blist.Insert(0, item);

            Assert.That(blist.Count, Is.EqualTo(count));

            CollectionAssert.AreEqual(expected, blist);
        }
Ejemplo n.º 7
0
        public void performance()
        {
            var stopwatch = new Stopwatch();

            var count = 2 << 16;

            Console.WriteLine($"Count: {count}");
            

            stopwatch.Reset();
            stopwatch.Start();
            {
                var blist = new BList<int>();

                for (int i = 0; i < count; i++)
                {
                    blist.Add(_random.Next());
                }
            }

            stopwatch.Stop();
            Console.WriteLine($"B-List - Add Last = {stopwatch.Elapsed.TotalMilliseconds:0.0}ms");

            stopwatch.Reset();
            stopwatch.Start();
            {
                var blist = new BList<int>();

                for (int i = 0; i < count; i++)
                {
                    blist.Insert(blist.Count / 2, _random.Next());
                }
            }

            stopwatch.Stop();
            Console.WriteLine($"B-List - Add middle = {stopwatch.Elapsed.TotalMilliseconds:0.0}ms");


            stopwatch.Reset();
            stopwatch.Start();
            {
                var blist = new BList<int>();

                for (int i = 0; i < count; i++)
                {
                    blist.Insert(0, _random.Next());
                }
            }

            stopwatch.Stop();
            Console.WriteLine($"B-List - Add First = {stopwatch.Elapsed.TotalMilliseconds:0.0}ms");
            

            stopwatch.Reset();
            stopwatch.Start();
            {
                var list = new List<int>();

                for (int i = 0; i < count; i++)
                {
                    list.Add(_random.Next());
                }
            }

            stopwatch.Stop();
            Console.WriteLine($"List - Add Last = {stopwatch.Elapsed.TotalMilliseconds:0.0}ms");

            stopwatch.Reset();
            stopwatch.Start();
            {
                var list = new List<int>();

                for (int i = 0; i < count; i++)
                {
                    list.Insert(list.Count / 2, _random.Next());
                }
            }

            stopwatch.Stop();
            Console.WriteLine($"List - Add middle = {stopwatch.Elapsed.TotalMilliseconds:0.0}ms");


            stopwatch.Reset();
            stopwatch.Start();
            {
                var list = new List<int>();

                for (int i = 0; i < count; i++)
                {
                    list.Insert(0, _random.Next());
                }
            }
            
            stopwatch.Stop();
            Console.WriteLine($"List - Add First = {stopwatch.Elapsed.TotalMilliseconds:0.0}ms");


            stopwatch.Reset();
            stopwatch.Start();
            {
                var list = new LinkedList<int>();

                for (int i = 0; i < count; i++)
                {
                    list.AddFirst(_random.Next());
                }
            }

            stopwatch.Stop();
            Console.WriteLine($"Linked-List - Add Last = {stopwatch.Elapsed.TotalMilliseconds:0.0}ms");

            stopwatch.Reset();
            stopwatch.Start();
            {
                var linkedlist = new LinkedList<int>();

                var last = linkedlist.AddFirst(_random.Next());

                for (int i = 0; i < count; i++)
                {
                    last = ((i & 1) == 1
                        ? linkedlist.AddAfter(last, _random.Next())
                        : linkedlist.AddBefore(last, _random.Next()));
                }
            }

            stopwatch.Stop();
            Console.WriteLine($"Linked-List - Add middle = {stopwatch.Elapsed.TotalMilliseconds:0.0}ms");

            stopwatch.Reset();
            stopwatch.Start();
            {
                var list = new LinkedList<int>();

                for (int i = 0; i < count; i++)
                {
                    list.AddLast(_random.Next());
                }
            }

            stopwatch.Stop();
            Console.WriteLine($"Linked-List - Add First = {stopwatch.Elapsed.TotalMilliseconds:0.0}ms");

        }