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 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); }
private Location RandomNeighbour(Location loc) { HexBoardNeighbours neighbourFinder = new HexBoardNeighbours(this.BoardSize); Location[] neighbours = neighbourFinder.Neighbours(loc); return this.RandomElement(neighbours); }
public void NeighboursOffTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(5); Location inValue = new Location(5, 0); Location[] outValue = testBoard.Neighbours(inValue); Assert.IsNotNull(outValue); Assert.AreEqual(0, outValue.Length); Assert.AreEqual(0, testBoard.NeighbourCount(inValue)); }