Ejemplo n.º 1
0
        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()}");
        }
Ejemplo n.º 2
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()}");
        }
Ejemplo n.º 3
0
        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()}");
        }
    private void SetupInitialBoard()
    {
        HexagonNet <Bubble> bubbleNet = new HexagonNet <Bubble>();
        var rows    = GenerateNRowsOfRandomBubbles(4);
        var nullRow = GenerateNullRow();

        foreach (var row in rows)
        {
            bubbleNet.AddBottomRow(row);
        }
        bubbleNet.AddBottomRow(nullRow);

        GameBoard.Net = bubbleNet;
    }
        /// <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);
        }
Ejemplo n.º 6
0
        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}");
        }