private bool ForceBridgeOn(Branch b)
            {
                Point p = b.Last();

                foreach (Point d in Grid.Directions)
                {
                    Point onceOver  = Grid.NeigbourCoordinates(p, d);
                    Point twiceOver = Grid.NeigbourCoordinates(onceOver, d);
                    if (IsBridge(p, d) && !b.Contains(twiceOver))
                    {
                        b.Add(onceOver);
                        //Pokud jde o horizontální směr, zapamatuj si která barva je nahoře
                        if (d.Y == 0)
                        {
                            Cells[onceOver.X, onceOver.Y] = Cells[p.X, p.Y];
                        }
                        b.Add(twiceOver);
                        if (Cells[twiceOver.X, twiceOver.Y] == Cells[p.X, p.Y])
                        {
                            b.Solved = b.Other.Solved = true;
                        }
                        else
                        {
                            Cells[twiceOver.X, twiceOver.Y] = Cells[p.X, p.Y];
                        }
                        return(true);
                    }
                }
                return(false);
            }
    public IEnumerator TestMinionMovement_Straight()
    {
        SceneManager.LoadScene("Test_MinionMovement_Straight");
        //MinionPool.Reset();

        yield return(null);

        Node origin = new Node(0, 0);
        Path path   = new Path(origin, NODE_DIRECTION.RIGHT); //1

        Branch testBranch = path.Branches[path.OuterBranchIDs[0]];

        testBranch.Add(NODE_DIRECTION.RIGHT); //2
        testBranch.Add(NODE_DIRECTION.RIGHT); //3
        testBranch.Add(NODE_DIRECTION.RIGHT); //4

        Node startNode = testBranch.InNode;

        Assert.That(startNode.VectorLocation, Is.EqualTo(new Vector2Int(4, 0)));

        Minion minion = MinionPool.Instance.GetMinion();

        minion.Activate(startNode);

        float travelDuration = minion.MovementInterface.MoveInterval * Node.GetDistanceToOrigin(startNode) + 1f;

        yield return(new WaitForSeconds(travelDuration));

        Assert.That(minion.transform.position.RoundToVector2Int(), Is.EqualTo(origin.VectorLocation));
    }
            //Provede na větvi vynucený pohyb, pokud existuje
            private bool ForcedMove(Branch b)
            {
                Point p = b.Last();

                //Spojí dvě větve stejné barvy, pokud sousedí
                foreach (Point d in Grid.Directions)
                {
                    Point onceOver = Grid.NeigbourCoordinates(p, d);
                    if (Cells[onceOver.X, onceOver.Y] == Cells[p.X, p.Y] && !b.Contains(onceOver) && !IsWall(p, d))
                    {
                        if (b.Other.Last() == onceOver)
                        {
                            b.Add(onceOver);
                            b.Solved = b.Other.Solved = true;
                            return(true);
                        }
                    }
                }
                //Provede pohyb, pokud je z daného místa jediný možný
                List <Point> possibleDirs = Grid.Directions.Where(d => IsEmpty(p, d) && !IsBridge(p, d) && !IsWall(p, d)).ToList();

                if (possibleDirs.Count == 1)
                {
                    Point d  = possibleDirs[0];
                    Point p1 = Grid.NeigbourCoordinates(p, d);
                    Cells[p1.X, p1.Y] = Cells[p.X, p.Y];
                    b.Add(p1);
                    ForceBridgeOn(b);
                    return(true);
                }
                return(false);
            }
    public void Test_Path_Init_GetNodesAt()
    {
        NODE_DIRECTION initDir = NODE_DIRECTION.UP_LEFT_RIGHT;
        Path           path    = new Path(origin, initDir);

        foreach (int id in path.OuterBranchIDs)
        {
            Branch outerBranch = path.Branches[id];
            switch (origin.DirectionOf(outerBranch.InNode))
            {
            case NODE_DIRECTION.LEFT:
                outerBranch.Add(NODE_DIRECTION.UP);
                outerBranch.Add(NODE_DIRECTION.RIGHT);
                break;

            case NODE_DIRECTION.RIGHT:
                outerBranch.Add(NODE_DIRECTION.UP);
                outerBranch.Add(NODE_DIRECTION.LEFT);
                break;

            default:
                break;
            }
        }

        Assert.That(path.GetNodesAt(2, 3).Length, Is.EqualTo(initDir.GetDirections().ToArray().Length));
    }
    public void Test_BranchAdd_Closed()
    {
        Node   o = new Node(2, 2);
        Branch b = new Branch(1, o, NODE_DIRECTION.UP);

        b.Add(NODE_DIRECTION.UP_LEFT_RIGHT);

        Assert.Throws <BranchException>(() => b.Add(NODE_DIRECTION.UP));
    }
Exemple #6
0
        public void GeenDubbeleTest()
        {
            var boom = new Branch <int>(10);

            boom.Add(5);
            boom.Add(5);
            Assert.AreEqual(2, boom.Count);
            Assert.AreEqual(5, boom[0]);
            Assert.AreEqual(10, boom[1]);
        }
Exemple #7
0
        static void Main()
        {
            IUnit root = new Branch("US (Root)");
            IUnit ny   = new Office("A (Unit)");
            IUnit ca   = new Office("B (Unit)");

            if (!root.IsLeaf)
            {
                root.Add(ny);
                root.Add(ca);
            }

            IUnit rootHawaii = new Branch("Canada Branch (Branch)");

            if (!root.IsLeaf)
            {
                root.Add(rootHawaii);
            }

            IUnit branchUk = new Branch("UK Branch (Branch)");
            IUnit ldnc     = new Office("C Office (Unit)");
            IUnit ldnw     = new Office("D Office (Unit)");

            if (!branchUk.IsLeaf)
            {
                branchUk.Add(ldnc);
                branchUk.Add(ldnw);
            }
            if (!root.IsLeaf)
            {
                root.Add(branchUk);
            }

            IUnit dummy = new Office("D Office");

            if (!dummy.IsLeaf)
            {
                ldnc.Add(dummy);
            }

            root.GetChild(0);

            if (!root.IsLeaf)
            {
                root.Remove(rootHawaii);
            }
            if (!branchUk.IsLeaf)
            {
                branchUk.Remove(ldnc);
            }
            Console.WriteLine("Remove Hawaii branch and London City office");
            root.GetChild(0);

            Console.ReadKey();
        }
Exemple #8
0
            private bool BalanceBranch2(Branch left)
            {
                var right = (Branch)TopNode;

                if (left.KeyCount + right.KeyCount < tree.maxKeyCount)
                {
                    // Coalesce left: move pivot and right sibling nodes.
                    left.AddKey(GetPivot());

                    for (int ix1 = 0; ; ++ix1)
                    {
                        left.Add(right.GetChild(ix1));
                        if (ix1 >= right.KeyCount)
                        {
                            break;
                        }
                        left.AddKey(right.GetKey(ix1));
                    }
                    left.AdjustWeight(+right.Weight);
                    TiltLeft(+right.Weight);

                    // Pivot must still be removed.
                    return(true);
                }

                // Branch underflow?
                if (tree.IsUnderflow(left.ChildCount))
                {
                    // Balance branches to keep ratio.  Rotate thru the pivot.
                    int shifts = (left.KeyCount + right.KeyCount - 1) / 2 - left.KeyCount;
                    left.AddKey(GetPivot());

                    int delta = 0;
                    for (int ix2 = 0; ; ++ix2)
                    {
                        left.Add(right.GetChild(ix2));
                        delta += right.GetChild(ix2).Weight;

                        if (ix2 >= shifts)
                        {
                            break;
                        }

                        left.AddKey(right.GetKey(ix2));
                    }

                    SetPivot(right.GetKey(shifts));
                    right.Remove(0, shifts + 1);
                    left.AdjustWeight(+delta);
                    right.AdjustWeight(-delta);
                    TiltLeft(delta);
                }

                return(false);
            }
        public void BinaryTreeBranchDoesntContrainNumberDeep()
        {
            //Arrange
            Branch <int> tree = new Branch <int>(5);

            //Act
            tree.Add(3);
            tree.Add(7);

            //Arrange
            Assert.IsFalse(tree.Contains(4));
        }
        public void BinaryTreeBranchDoesContrainNumberDeep()
        {
            //Arrange
            Branch <int> tree = new Branch <int>(5);

            //Act
            tree.Add(3);
            tree.Add(7);
            tree.Add(9);
            tree.Add(4);

            //Arrange
            Assert.AreEqual(true, tree.Contains(4));
        }
        public void BinaryTreeBranchCount()
        {
            //Arrange
            Branch <int> tree = new Branch <int>(5);

            //Act
            tree.Add(3);
            tree.Add(7);
            tree.Add(9);
            tree.Add(4);

            //Arrange
            Assert.AreEqual(5, tree.Count);
        }
        public void BinaryTreeBranchDepth5AddsReturn()
        {
            //Arrange
            Branch <int> tree = new Branch <int>(5);

            //Act
            tree.Add(4);
            tree.Add(3);
            tree.Add(2);
            tree.Add(1);

            //Arrange
            Assert.AreEqual(5, tree.Depth);
        }
Exemple #13
0
        private void Search(int StartX, int StartY, int TargetX, int TargetY)
        {
            foreach (var item in Map)
            {
                item.IsMoved = false;
            }
            BranchList.Clear();
            OverBranch = null;
            SearchEnd  = false;
            int    MaxSearchNum = MapSizeX * MapSizeY;
            Branch branch       = branchPools.GetItem(null);

            branch.Endx = TargetX;
            branch.Endy = TargetY;
            branch.Add(Map[StartX, StartY]);
            BranchList.Add(branch);
            int Count = 0;

            for (int i = 0; i < MaxSearchNum; i++)
            {
                if (SearchEnd)
                {
                    return;
                }
                //步进
                Count = BranchList.Count;
                for (int j = 0; j < Count; j++)
                {
                    GoNext(BranchList[j]);
                }
            }
        }
    // Use this for initialization
    public void Start()
    {
        // Build the path out to the Init Widths in the init directions.
        _path = new Path(new Node(Origin.x, Origin.y), InitDirection);

        // Create the initial bounding rect
        Vector2Int offset = new Vector2Int(InitXWidth, InitYWidth);
        Rect       bound  = new Rect(Origin - offset, offset + offset + Vector2Int.one);

        bool building = true;

        while (building)
        {
            building = false;

            foreach (int i in _path.OuterBranchIDs)
            {
                Branch b = _path.Branches[i];
                if (bound.Contains(b.InNode.VectorLocation))
                {
                    // if the branch in-node is in the bounding rect, set the building flag to true and add another node.
                    // This logic will cause the termination of the outer while loop when all outer branches have in-nodes
                    // outside of the bounding rect.
                    building = true;

                    NODE_DIRECTION dir = b.InNode.OutNode.DirectionOf(b.InNode);
                    b.Add(dir);
                }
            }
        }
    }
    public void Test_BranchAdd_Multi_Closed()
    {
        Node   o = new Node(2, 2);
        Branch b = new Branch(1, o, NODE_DIRECTION.UP);

        b.Add(NODE_DIRECTION.UP_LEFT_RIGHT);

        Assert.That(!b.Open);
    }
    public void Test_BranchAdd_Multi_InNode()
    {
        Node   o = new Node(2, 2);
        Branch b = new Branch(1, o, NODE_DIRECTION.UP);

        b.Add(NODE_DIRECTION.UP_LEFT_RIGHT);
        Vector2Int ex = new Vector2Int(2, 3);

        Assert.That(b.InNode.VectorLocation, Is.EqualTo(ex));
    }
Exemple #17
0
 public void OnCallStart(Call call)
 {
     for (int i = 0; i < call.Options.Count; i++)
     {
         var button      = ImageTextButtonFactory.Create(call.Options[i].Description, Vector2.Zero, call.Options[i].Go);
         var smartButton = new SmartControl(button, (int)ClickUIPriorities.Pad);
         _choices.Add(smartButton);
         _grid.AddSpatial(smartButton, button.Transform, i + 1, 1);
         Branch.Add(smartButton.Branch);
     }
 }
    public void Test_BranchAdd_Multi_Return()
    {
        Node   o = new Node(2, 2);
        Branch b = new Branch(1, o, NODE_DIRECTION.UP);

        NODE_DIRECTION[] act = b.Add(NODE_DIRECTION.UP_LEFT_RIGHT);

        NODE_DIRECTION[] ex = { NODE_DIRECTION.UP, NODE_DIRECTION.LEFT, NODE_DIRECTION.RIGHT };

        Assert.That(act, Is.EqualTo(ex));
    }
        public void BinaryTreeBranchIEnumerableLowest()
        {
            //Arrange
            Branch <int> tree = new Branch <int>(5);

            tree.Add(4);
            tree.Add(3);
            tree.Add(2);
            tree.Add(1);
            tree.Add(6);

            int[] values = { 5, 4, 3, 2, 1, 6 };
            int   min;

            //act
            min = tree.Min();


            //Arrange
            Assert.AreEqual(1, min);
        }
Exemple #20
0
        /// <summary>
        /// Gets the branches details.
        /// </summary>
        /// <param name="countryId">The country identifier.</param>
        /// <param name="cultureInfo">The culture information.</param>
        /// <returns></returns>
        public async Task GetBranchesDetails(int countryId, string cultureInfo)
        {
            try
            {
                SetActivityIndicatorBlurred(true);
                ActOpacity      = 1;
                MainStackLayout = false;
                PackingCygestPageLayoutOpacity = 0.4;
                Status = "Loading data...";
                var connected = CrossConnectivity.Current.IsConnected;

                if (connected)
                {
                    Branch = await _branchService.GetBranchDetailsAsync(countryId, cultureInfo, BrandId);

                    if (Branch.Count == 0 && _appViewModel.DefaultedCultureInfo != "fr-FR")
                    {
                        BranchModel tempBranch = new BranchModel
                        {
                            Id   = 0,
                            Code = "Unknown",
                            Name = "Unknown"
                        };
                        Branch.Add(tempBranch);
                    }
                    else
                    {
                        BranchModel tempBranch = new BranchModel
                        {
                            Id   = 0,
                            Code = "Inconnu",
                            Name = "Inconnu"
                        };
                        Branch.Add(tempBranch);
                    }

                    SetActivityIndicatorBlurred(false);
                    MainStackLayout = true;
                    PackingCygestPageLayoutOpacity = 1;
                    Status = "";
                }
            }
            catch (Exception e)
            {
                await _pageService.DisplayAlert(LblError, LblNoConnection, LblOk);

                DatabaseAccessAsync da = new DatabaseAccessAsync();
                da.InsertException(new PackingCygestExceptionModel
                {
                    Message = e.Message, StackTrace = e.StackTrace, TimeSpan = DateTime.Today.ToString(System.Globalization.CultureInfo.CurrentCulture), MethodName = e.Source
                });
            }
        }
        public void BinaryTreeWaardeToevoegenTweedeMaalLager()
        {
            //Arrange
            Branch <int> tree = new Branch <int>(4);

            //Act
            tree.Add(3);

            //Arrange
            Assert.IsInstanceOfType(tree.LeftChild, typeof(Branch <int>));
            Assert.AreEqual(3, (tree.LeftChild as Branch <int>).Value);
        }
        public void BinaryTreeBranchAbstraction()
        {
            //Arrange
            Branch <int> tree = new Branch <int>(4);

            //Act
            tree.Add(3);

            //Arrange
            Assert.IsInstanceOfType(tree.LeftChild, typeof(Branch <int>));
            Assert.AreEqual(3, (tree.LeftChild as Branch <int>).Value);
        }
Exemple #23
0
    public IEnumerator Test_TowerAttacks_MinionsDieCorrectly()
    {
        SceneManager.LoadScene("Test_TowerAttacks_Aggro");
        yield return(null);

        GameObject tower    = GameObject.Find("test_tower");
        TowerAggro towerAgg = tower.GetComponentInChildren <TowerAggro>();

        Node origin = new Node(0, 0);
        Path path   = new Path(origin, NODE_DIRECTION.RIGHT); //1

        Branch testBranch = path.Branches[path.OuterBranchIDs[0]];

        testBranch.Add(NODE_DIRECTION.RIGHT); //2
        testBranch.Add(NODE_DIRECTION.RIGHT); //3
        testBranch.Add(NODE_DIRECTION.RIGHT); //4
        testBranch.Add(NODE_DIRECTION.RIGHT); //5
        testBranch.Add(NODE_DIRECTION.RIGHT); //6
        testBranch.Add(NODE_DIRECTION.RIGHT); //7
        testBranch.Add(NODE_DIRECTION.RIGHT); //8
        testBranch.Add(NODE_DIRECTION.RIGHT); //9
        testBranch.Add(NODE_DIRECTION.RIGHT); //10

        Node startNode = testBranch.InNode;

        Minion minion = MinionPool.Instance.GetMinion();

        minion.Activate(startNode);

        float secondMinionSpawnDelay = 2.0f;

        yield return(new WaitForSeconds(secondMinionSpawnDelay));

        Minion minion2 = MinionPool.Instance.GetMinion();

        minion2.Activate(startNode);

        float travelDuration = minion.MovementInterface.MoveInterval * Node.GetDistanceToOrigin(startNode) + 1f - secondMinionSpawnDelay;

        yield return(new WaitForSeconds(travelDuration));

        Assert.That(towerAgg.Targets.Count, Is.EqualTo(0));
        Assert.That(!minion.Alive);
    }
 public Models.Address.Abstract.BaseAssembly Populate(Models.Address.Abstract.BaseAssembly root)
 {
     for (int i = 0; i < 5; i++)
     {
         Branch x = new Branch("Name " + i.ToString());
         for (int j = 0; j < 5; j++)
         {
             x.Add(new Leaf("Name " + j.ToString()));
         }
         root.Add(x);
     }
     return(root);
 }
        public void BinaryTreeBranchIEnumerableLoop()
        {
            //Arrange
            Branch <int> tree = new Branch <int>(5);

            tree.Add(4);
            tree.Add(3);
            tree.Add(2);
            tree.Add(1);
            tree.Add(6);

            int count = 0;

            int[] values = { 1, 2, 3, 4, 5, 6 };

            //Assert
            foreach (var item in tree)
            {
                Assert.AreEqual(values[count], item, $"{count} failed");
                count++;
            }
        }
Exemple #26
0
 void MoveTo(Branch branch, int x, int y)
 {
     branch.Add(Map[x, y]);
     if (isEnd(x, y, branch.Endx, branch.Endy))
     {
         SearchEnd  = true;
         OverBranch = branch;
         return;
     }
     if (!BranchList.Contains(branch))
     {
         BranchList.Add(branch);
     }
 }
    public void Test_Path_Branch_PostOuterBranchIDCount()
    {
        NODE_DIRECTION initDir = NODE_DIRECTION.UP, branchDir = NODE_DIRECTION.UP_LEFT_RIGHT;
        Path           path         = new Path(origin, initDir);
        int            initBranchId = path.OuterBranchIDs[0];

        Branch initBranch = path.Branches[initBranchId];

        initBranch.Add(branchDir);

        path.Branch(initBranchId);

        Assert.That(path.OuterBranchIDs.Count, Is.EqualTo(3));
    }
    public void Test_Path_Branch_PostOuterBranchIDGone()
    {
        NODE_DIRECTION initDir = NODE_DIRECTION.UP, branchDir = NODE_DIRECTION.UP_LEFT_RIGHT;
        Path           path         = new Path(origin, initDir);
        int            initBranchId = path.OuterBranchIDs[0];

        Branch initBranch = path.Branches[initBranchId];

        initBranch.Add(branchDir);

        path.Branch(initBranchId);

        Assert.That(path.OuterBranchIDs, !Contains.Item(initBranchId));
    }
 private static void UnFlattenHelper <T>(Dictionary <int, List <int> > skeleton, T[] meat, int parentIndex, Branch <T> parent)
 {
     if (skeleton.ContainsKey(parentIndex))
     {
         List <int> parentList = skeleton[parentIndex];
         for (int i = 0; i < parentList.Count; i++)
         {
             int j = parent.Add(meat[parentList[i]]);
             UnFlattenHelper(skeleton, meat, parentList[i], parent.Get(j));
         }
     }
     else
     {
         //pass, this node has no children and will die alone.
     }
 }
Exemple #30
0
        private Node FillBranches(Branch branch, IElementBase previousElement, IElementBase element, List <IElementBase> passedElements)
        {
            branch.Add(element);
            passedElements.Add(element); // мб сократить кол во вызовов add

            foreach (var pin in element.Pins)
            {
                if (!previousElement.Equals(pin.ConnectedPin.Element))
                {
                    if (pin.ConnectedPin.Element is Node)
                    {
                        branch.Node_2 = pin.ConnectedPin.Element as Node;
                        return(pin.ConnectedPin.Element as Node);
                    }
                    else
                    {
                        return(FillBranches(branch, element, pin.ConnectedPin.Element, passedElements));
                    }
                }
            }
            throw new InvalidOperationException(); // Схема не замкнута?
        }