Ejemplo n.º 1
0
        private static void TestNeighbours(HexBoardNeighbours testBoard, Location testLoc, IEnumerable<Location[]> neighbourGroups)
        {
            TestOnBoard(testBoard, testLoc);

            foreach (Location[] neighbours in neighbourGroups)
            {
                Location neighbour2 = neighbours[0];
                Location between1 = neighbours[1];
                Location between2 = neighbours[2];

                TestOnBoard(testBoard, neighbour2);
                TestOnBoard(testBoard, between1);
                TestOnBoard(testBoard, between2);

                // that the betweens are neighbours of start, end eand each other
                Assert.IsTrue(testBoard.AreNeighbours(between1, between2));

                Assert.IsTrue(testBoard.AreNeighbours(testLoc, between1));
                Assert.IsTrue(testBoard.AreNeighbours(testLoc, between2));

                Assert.IsTrue(testBoard.AreNeighbours(neighbour2, between1));
                Assert.IsTrue(testBoard.AreNeighbours(neighbour2, between2));

                // but not neighbours of each other
                Assert.IsFalse(testBoard.AreNeighbours(testLoc, neighbour2));
            }
        }
Ejemplo n.º 2
0
        private static void TestNeighbour2Triplet(Cell cell, Cell[] triplet)
        {
            Assert.AreEqual(3, triplet.Length);
            NoNullsInCellArray(triplet);

            var testBoard = new HexBoardNeighbours(BoardSize);
            var testLoc = cell.Location;
            var neighbour2 = triplet[0].Location;
            var between1 = triplet[1].Location;
            var between2 = triplet[2].Location;

            Assert.IsTrue(testBoard.AreNeighbours(between1, between2));

            Assert.IsTrue(testBoard.AreNeighbours(testLoc, between1));
            Assert.IsTrue(testBoard.AreNeighbours(testLoc, between2));

            Assert.IsTrue(testBoard.AreNeighbours(neighbour2, between1));
            Assert.IsTrue(testBoard.AreNeighbours(neighbour2, between2));

            // but not neighbours to each other
            Assert.IsFalse(testBoard.AreNeighbours(testLoc, neighbour2));
        }
Ejemplo n.º 3
0
        private static void TestNeighbours(HexBoardNeighbours testBoard, Location testLoc, IEnumerable<Location> neighbours)
        {
            TestOnBoard(testBoard, testLoc);

            Location offBoard = new Location(testBoard.BoardSize, testBoard.BoardSize - 1);

            foreach (Location neighbour in neighbours)
            {
                // check is on board
                TestOnBoard(testBoard, neighbour);

                // check that the cells are actuallly neighbours
                Assert.IsTrue(testBoard.AreNeighbours(testLoc, neighbour));

                // not neighbours with off-board cell
                Assert.IsFalse(testBoard.AreNeighbours(testLoc, offBoard));

                // not neighbours with self
                Assert.IsFalse(testBoard.AreNeighbours(testLoc, testLoc));
            }
        }
Ejemplo n.º 4
0
        private static void DoTestNeighbour(Cell cell, Cell neibCell, HexBoard board)
        {
            Assert.IsTrue(cell.Location.ManhattanDistance(neibCell.Location) < 3, "Neigbour is too far away");

            var neighboursTest = new HexBoardNeighbours(BoardSize);

            Assert.IsTrue(neighboursTest.AreNeighbours(cell.Location, neibCell.Location));

            // reflexive. If B is a neighbour of A, then B's neighbours must include A
            var neibs = board.Neighbours(neibCell);
            int index = Array.IndexOf(neibs, cell);
            Assert.IsTrue(index >= 0, "Cell is not neighbour's neighbour");
        }