public void CreateTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(5); Assert.IsNotNull(testBoard); Assert.AreEqual(5, testBoard.BoardSize); }
private void InitNeighbours() { HexBoardNeighbours neighboursCalc = new HexBoardNeighbours(this.Size); // init the cached neighbours arrays this.neighbours = new Cell[this.Size, this.Size][]; this.neighbours2 = new Cell[this.Size, this.Size][][]; this.playerXBetweenEdge = new Cell[this.Size, this.Size][]; this.playerYBetweenEdge = new Cell[this.Size, this.Size][]; foreach (Cell cell in this.cells) { Location[] neigbourLocations = neighboursCalc.Neighbours(cell.Location); this.neighbours[cell.X, cell.Y] = this.GetCellAt(neigbourLocations); Location[][] neighbour2Locations = neighboursCalc.Neighbours2(cell.Location); this.neighbours2[cell.X, cell.Y] = this.GetCellsAt(neighbour2Locations); Location[] localPlayerXBetweenEdge = neighboursCalc.BetweenEdge(cell.Location, true); this.playerXBetweenEdge[cell.X, cell.Y] = this.GetCellAt(localPlayerXBetweenEdge); Location[] localPlayerYBetweenEdge = neighboursCalc.BetweenEdge(cell.Location, false); this.playerYBetweenEdge[cell.X, cell.Y] = this.GetCellAt(localPlayerYBetweenEdge); } }
public void IsOnBoardTrueTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(5); Assert.IsTrue(testBoard.IsOnBoard(new Location(0, 0))); Assert.IsTrue(testBoard.IsOnBoard(new Location(2, 2))); Assert.IsTrue(testBoard.IsOnBoard(new Location(0, 4))); Assert.IsTrue(testBoard.IsOnBoard(new Location(4, 0))); Assert.IsTrue(testBoard.IsOnBoard(new Location(4, 4))); }
public void IsOnBoardFalseTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(5); Assert.IsFalse(testBoard.IsOnBoard(new Location(-1, -1))); Assert.IsFalse(testBoard.IsOnBoard(new Location(2, -1))); Assert.IsFalse(testBoard.IsOnBoard(new Location(0, 5))); Assert.IsFalse(testBoard.IsOnBoard(new Location(5, 0))); Assert.IsFalse(testBoard.IsOnBoard(new Location(-1, 5))); }
public void NeighboursNearOriginTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(10); Location inValue = new Location(1, 1); Location[][] outValue = testBoard.Neighbours2(inValue); Assert.IsNotNull(outValue); Assert.AreEqual(4, outValue.Length); TestNeighbours(testBoard, inValue, outValue); }
public void NeighboursMiddleTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(10); Location inValue = new Location(5, 5); Location[][] outValue = testBoard.Neighbours2(inValue); Assert.IsNotNull(outValue); Assert.AreEqual(6, outValue.Length); TestNeighbours(testBoard, inValue, outValue); }
public void NeighboursFarTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(10); Location inValue = new Location(9, 9); Location[] outValue = testBoard.Neighbours(inValue); Assert.IsNotNull(outValue); Assert.AreEqual(2, outValue.Length); Assert.AreEqual(2, testBoard.NeighbourCount(inValue)); TestNeighbours(testBoard, inValue, outValue); }
public void NeighboursOffTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(5); Location inValue = new Location(5, 0); Location[][] outValue = testBoard.Neighbours2(inValue); Assert.IsNotNull(outValue); Assert.AreEqual(0, outValue.Length); }
private static void TestOnBoard(HexBoardNeighbours testBoard, Location neighbour) { Assert.IsTrue(testBoard.IsOnBoard(neighbour)); Assert.GreaterOrEqual(neighbour.X, 0); Assert.GreaterOrEqual(neighbour.Y, 0); Assert.Less(neighbour.X, testBoard.BoardSize); Assert.Less(neighbour.Y, testBoard.BoardSize); }
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)); } }
private Location RandomNeighbour(Location loc) { HexBoardNeighbours neighbourFinder = new HexBoardNeighbours(this.BoardSize); Location[] neighbours = neighbourFinder.Neighbours(loc); return this.RandomElement(neighbours); }
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)); } }
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)); }
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"); }