public void HexagonNet_GetNeighbourFor_ReturnsCorrectNeighbour()
        {
            // arrange
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(2).SetHexagonNet(net),
                new BubbleNode(3).SetHexagonNet(net),
                new BubbleNode(4).SetHexagonNet(net),
                new BubbleNode(5).SetHexagonNet(net)
            };
            var topRow = new HexagonNetRow <Bubble>(bubblesForTopRow);

            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(6).SetHexagonNet(net),
                new BubbleNode(7).SetHexagonNet(net),
                new BubbleNode(8).SetHexagonNet(net),
                new BubbleNode(9).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(11).SetHexagonNet(net)
            };
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);

            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(12).SetHexagonNet(net),
                new BubbleNode(13).SetHexagonNet(net),
                new BubbleNode(14).SetHexagonNet(net),
                new BubbleNode(15).SetHexagonNet(net),
                new BubbleNode(16).SetHexagonNet(net),
                new BubbleNode(17).SetHexagonNet(net)
            };
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(topRow);
            net.AddBottomRow(middleRow);
            net.AddBottomRow(bottomRow);

            var secondNodeMiddleRow = middleRow.Nodes[1];

            // act
            var secondNodeMiddleRow_LowerLeftNeighbour  = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.LowerLeft);
            var secondNodeMiddleRow_LowerRightNeighbour = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.LowerRight);
            var secondNodeMiddleRow_LeftNeighbour       = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.Left);
            var secondNodeMiddleRow_RightNeighbour      = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.Right);
            var secondNodeMiddleRow_UpperLeftNeighbour  = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.UpperLeft);
            var secondNodeMiddleRow_UpperRightNeighbour = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.UpperRight);

            // assert
            Assert.AreEqual(13, secondNodeMiddleRow_LowerLeftNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
            Assert.AreEqual(14, secondNodeMiddleRow_LowerRightNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
            Assert.AreEqual(6, secondNodeMiddleRow_LeftNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
            Assert.AreEqual(8, secondNodeMiddleRow_RightNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
            Assert.AreEqual(1, secondNodeMiddleRow_UpperLeftNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
            Assert.AreEqual(2, secondNodeMiddleRow_UpperRightNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
        }
Example #2
0
 /// <summary>
 /// Update neighbours of all nodes in the given row.
 /// </summary>
 /// <param name="row"></param>
 private void UpdateNeighboursForAllNodes(HexagonNetRow <T> row)
 {
     foreach (var node in row)
     {
         UpdateNeighboursFor(node);
     }
 }
Example #3
0
    /// <summary>
    /// Set a completely setup row at its Index.
    /// </summary>
    /// <param name="row"></param>
    private void SetCompleteRow(HexagonNetRow <T> row)
    {
        PositionNodesWithinNet(row);
        net.Add(row.Index, row);

        UpdateNeighboursForAllNodes(row);
    }
Example #4
0
 private void InitializeNet(HexagonNetRow <T> firstRow)
 {
     firstRow.Shifted = false;
     firstRow.Index   = 0;
     SetCompleteRow(firstRow);
     TopRow    = firstRow;
     BottomRow = firstRow;
 }
Example #5
0
        public void GameBoard_MergeBubbles_EvenMoreSimilarAtTheTopValid()
        {
            // arrange
            // arrange
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net)
            };
            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net)
            };
            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net)
            };

            var topRow    = new HexagonNetRow <Bubble>(bubblesForTopRow);
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(topRow);
            net.AddBottomRow(middleRow);
            net.AddBottomRow(bottomRow);

            var gameBoard = new GameBoard(net);

            var startBubble = net.BottomRow.Nodes[3];

            var expectedNetToString =
                $" 10 10 10 10 10 10{Environment.NewLine}" +
                $" 10 10 null null 10 10{Environment.NewLine}" +
                $" null null null 3 null null{Environment.NewLine}";

            // act
            gameBoard.MergeBubbles(startBubble);

            // assert

            Assert.AreEqual(expectedNetToString, net.ToString(), $"Actual HexagonNet as string: {Environment.NewLine}{net.ToString()}");
        }
Example #6
0
 /// <summary>
 /// Position nodes of the given row within the net by assigning them a correct IHexagonNetRow.Position index.
 /// </summary>
 public void PositionNodesWithinNet(HexagonNetRow <T> row)
 {
     for (int i = 0; i < 6; i++)
     {
         if (row.Nodes[i] != null)
         {
             row.Nodes[i].Position = new Vector2Int(row.Index, i);
         }
     }
 }
    private HexagonNetRow <Bubble>[] GenerateNRowsOfRandomBubbles(int n)
    {
        HexagonNetRow <Bubble>[] rows = new HexagonNetRow <Bubble> [n];

        for (int i = 0; i < n; i++)
        {
            rows[i] = GenerateRowOfRandomBubbles();
        }

        return(rows);
    }
        public void HexagonNet_ChangingNeighbours_ChangesNeighbourNodesInNet()
        {
            // arrange
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(2).SetHexagonNet(net),
                new BubbleNode(3).SetHexagonNet(net),
                new BubbleNode(4).SetHexagonNet(net),
                new BubbleNode(5).SetHexagonNet(net)
            };
            var topRow = new HexagonNetRow <Bubble>(bubblesForTopRow);

            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(6).SetHexagonNet(net),
                new BubbleNode(7).SetHexagonNet(net),
                new BubbleNode(8).SetHexagonNet(net),
                new BubbleNode(9).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(11).SetHexagonNet(net)
            };
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);

            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(12).SetHexagonNet(net),
                new BubbleNode(13).SetHexagonNet(net),
                new BubbleNode(14).SetHexagonNet(net),
                new BubbleNode(15).SetHexagonNet(net),
                new BubbleNode(16).SetHexagonNet(net),
                new BubbleNode(17).SetHexagonNet(net)
            };
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(topRow);
            net.AddBottomRow(middleRow);
            net.AddBottomRow(bottomRow);

            var secondNodeMiddleRow = middleRow.Nodes[1];

            var expectedNet         = HexagonNetTestHelper.GenerateTestNet3Rows(0, 1, -1000, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
            var expectedNetToString = expectedNet.ToString();

            // act
            secondNodeMiddleRow.GetNeighbour(Neighbours.UpperRight).Value.Exponent = -1000;

            // assert
            Assert.AreEqual(expectedNetToString, net.ToString(), $"Actual HexagonNet as string: {Environment.NewLine}{net.ToString()}");
        }
Example #9
0
    /// <summary>
    /// Replaces the BottomRow with the newBottomRow.
    /// </summary>
    /// <param name="newBottomRow"></param>
    public void AddBottomRow(HexagonNetRow <T> newBottomRow)
    {
        if (BottomRow == null)
        {
            InitializeNet(newBottomRow);
            return;
        }

        newBottomRow.Shifted = !BottomRow.Shifted;
        newBottomRow.Index   = BottomRow.Index + 1;
        SetCompleteRow(newBottomRow);
        BottomRow = newBottomRow;
    }
Example #10
0
    /// <summary>
    /// Replaces the TopRow with the newTopRow.
    /// </summary>
    /// <param name="newTopRow"></param>
    public void AddTopRow(HexagonNetRow <T> newTopRow)
    {
        if (TopRow == null)
        {
            InitializeNet(newTopRow);
            return;
        }

        newTopRow.Shifted = !TopRow.Shifted;
        newTopRow.Index   = TopRow.Index - 1;
        SetCompleteRow(newTopRow);
        TopRow = newTopRow;
    }
    private HexagonNetRow <Bubble> GenerateNullRow()
    {
        HexagonNetRow <Bubble> row = new HexagonNetRow <Bubble>(new BubbleNode[]
        {
            new BubbleNode(null),
            new BubbleNode(null),
            new BubbleNode(null),
            new BubbleNode(null),
            new BubbleNode(null),
            new BubbleNode(null),
        });

        return(row);
    }
    private HexagonNetRow <Bubble> GenerateRowOfRandomBubbles()
    {
        HexagonNetRow <Bubble> row = new HexagonNetRow <Bubble>(new BubbleNode[]
        {
            new BubbleNode(bubbleExponentRandomizer.Next(9) + 1),
            new BubbleNode(bubbleExponentRandomizer.Next(9) + 1),
            new BubbleNode(bubbleExponentRandomizer.Next(9) + 1),
            new BubbleNode(bubbleExponentRandomizer.Next(9) + 1),
            new BubbleNode(bubbleExponentRandomizer.Next(9) + 1),
            new BubbleNode(bubbleExponentRandomizer.Next(9) + 1),
        });

        return(row);
    }
Example #13
0
    public void RemoveBottomRow()
    {
        // Remove current
        if (BottomRow != null)
        {
            net.Remove(BottomRow.Index);
        }

        // Assign new
        if (net.Keys.Count > 0)
        {
            BottomRow = net[BottomRow.Index - 1];
            UpdateNeighboursForAllNodes(BottomRow);
        }
    }
        /// <summary>
        /// Generate a HexagonNet and add three rows to it with Bubbles, whose exponents are specified in parameters.
        /// </summary>
        /// <param name="exponents"></param>
        /// <returns></returns>
        public static HexagonNet <Bubble> GenerateTestNet3Rows(params int[] exponents)
        {
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(exponents[0]).SetHexagonNet(net),
                new BubbleNode(exponents[1]).SetHexagonNet(net),
                new BubbleNode(exponents[2]).SetHexagonNet(net),
                new BubbleNode(exponents[3]).SetHexagonNet(net),
                new BubbleNode(exponents[4]).SetHexagonNet(net),
                new BubbleNode(exponents[5]).SetHexagonNet(net)
            };
            var topRow = new HexagonNetRow <Bubble>(bubblesForTopRow);

            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(exponents[6]).SetHexagonNet(net),
                new BubbleNode(exponents[7]).SetHexagonNet(net),
                new BubbleNode(exponents[8]).SetHexagonNet(net),
                new BubbleNode(exponents[9]).SetHexagonNet(net),
                new BubbleNode(exponents[10]).SetHexagonNet(net),
                new BubbleNode(exponents[11]).SetHexagonNet(net)
            };
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);

            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(exponents[12]).SetHexagonNet(net),
                new BubbleNode(exponents[13]).SetHexagonNet(net),
                new BubbleNode(exponents[14]).SetHexagonNet(net),
                new BubbleNode(exponents[15]).SetHexagonNet(net),
                new BubbleNode(exponents[16]).SetHexagonNet(net),
                new BubbleNode(exponents[17]).SetHexagonNet(net)
            };
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(topRow);
            net.AddBottomRow(middleRow);
            net.AddBottomRow(bottomRow);

            return(net);
        }
        public void HexagonNet_EnumeratedThrough_ValuesShouldBeSortedByKeys()
        {
            // arrange
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(-1).SetHexagonNet(net),
                new BubbleNode(-1).SetHexagonNet(net),
                new BubbleNode(-1).SetHexagonNet(net),
                new BubbleNode(-1).SetHexagonNet(net),
                new BubbleNode(-1).SetHexagonNet(net),
                new BubbleNode(-1).SetHexagonNet(net)
            };
            var topRow = new HexagonNetRow <Bubble>(bubblesForTopRow);

            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(0).SetHexagonNet(net)
            };
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);

            var bubblesForLowerMiddleRow = new BubbleNode[]
            {
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net)
            };
            var lowerMiddleRow = new HexagonNetRow <Bubble>(bubblesForLowerMiddleRow);

            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net)
            };
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(middleRow);
            net.AddTopRow(topRow);
            net.AddBottomRow(lowerMiddleRow);
            net.AddBottomRow(bottomRow);

            var expectedNetAsString =
                " -1 -1 -1 -1 -1 -1" + Environment.NewLine +
                " 0 0 0 0 0 0" + Environment.NewLine +
                " 1 1 1 1 1 1" + Environment.NewLine +
                " null null null null null null" + Environment.NewLine;

            // act
            string netAsString = net.ToString();

            // assert
            Assert.AreEqual(expectedNetAsString, netAsString, $"HexagonNet as string: {Environment.NewLine}{netAsString}");
        }