/// <summary> /// 10x10 Gridlattice w/ 6 randomish wall intersections on it /// </summary> /// <returns></returns> public static GridLattice <IRectGrid> IntersectionLattice() { GridLattice <IRectGrid> data = new GridLattice <IRectGrid>(10); InitGridLattice(data); data[1, 2, Direction.East] = new RectGridCell(1, 1); data[1, 2, Direction.South] = new RectGridCell(1, 1); data[1, 5, Direction.East] = new RectGridCell(1, 1); data[1, 5, Direction.North] = new RectGridCell(1, 1); data[2, 7, Direction.West] = new RectGridCell(1, 1); data[2, 7, Direction.North] = new RectGridCell(1, 1); data[4, 2, Direction.East] = new RectGridCell(1, 1); data[4, 2, Direction.North] = new RectGridCell(1, 1); data[5, 2, Direction.West] = new RectGridCell(1, 1); data[8, 1, Direction.North] = new RectGridCell(1, 1); data[8, 1, Direction.West] = new RectGridCell(1, 1); data[8, 2, Direction.West] = new RectGridCell(1, 1); return(data); }
/// <summary> /// Returns an empty ixj gridlattice. /// </summary> /// <returns></returns> public static GridLattice <IRectGrid> EmptyGridLattice(int i, int j) { GridLattice <IRectGrid> data = new GridLattice <IRectGrid>(i, j); InitGridLattice(data); return(data); }
public static GridLattice <IRectGrid> SingleHorizEdgeGridLattice() { GridLattice <IRectGrid> data = new GridLattice <IRectGrid>(5); InitGridLattice(data); data[2, 2, Direction.South] = new RectGridCell(1, 1); return(data); }
public static GridLattice <IRectGrid> CenterCellTorusGridLattice() { GridLattice <IRectGrid> data = new GridLattice <IRectGrid>(5); InitGridLattice(data); //should also be able to do this by setting the center to a different pathgroup data[2, 2, Direction.Center] = new RectGridCell(1, 1); return(data); }
/// <summary> /// 5x5 Gridlattice w/ most of a wall blocking it. /// </summary> /// <returns></returns> public static GridLattice <IRectGrid> KeyholeApertureLattice() { GridLattice <IRectGrid> data = new GridLattice <IRectGrid>(5); InitGridLattice(data); data[0, 2, Direction.North] = new RectGridCell(1, 1); data[1, 2, Direction.North] = new RectGridCell(1, 1); //data[2, 2, Direction.North] = new RectGridCell(1, 1); data[3, 2, Direction.North] = new RectGridCell(1, 1); data[4, 2, Direction.North] = new RectGridCell(1, 1); return(data); }
/// <summary> /// Returns a circular 5x5 gridlattice. If edge data is 0, it's "empty", otherwise /// it'll be treated as a wall. /// </summary> /// <returns></returns> public static GridLattice <IRectGrid> EdgeTorusGridLattice() { GridLattice <IRectGrid> data = new GridLattice <IRectGrid>(5); InitGridLattice(data); //should also be able to do this by setting the center to a different pathgroup data[2, 2, Direction.North] = new RectGridCell(1, 1); data[2, 2, Direction.South] = new RectGridCell(1, 1); data[2, 2, Direction.East] = new RectGridCell(1, 1); data[2, 2, Direction.West] = new RectGridCell(1, 1); return(data); }
/// <summary> /// 5x5 Gridlattice w/ a wall bisecting it. /// </summary> /// <returns></returns> public static GridLattice <IRectGrid> HorizBisectedLattice() { GridLattice <IRectGrid> data = new GridLattice <IRectGrid>(5); InitGridLattice(data); data[0, 2, Direction.North] = new RectGridCell(1, 1); data[1, 2, Direction.North] = new RectGridCell(1, 1); data[2, 2, Direction.North] = new RectGridCell(1, 1); data[3, 2, Direction.North] = new RectGridCell(1, 1); data[4, 2, Direction.North] = new RectGridCell(1, 1); return(data); }
/// <summary> /// 5x5 Gridlattice w/ most of a wall blocking it. /// </summary> /// <returns></returns> public static GridLattice <IRectGrid> VertKeyholeApertureLattice() { GridLattice <IRectGrid> data = new GridLattice <IRectGrid>(5); InitGridLattice(data); data[2, 0, Direction.West] = new RectGridCell(1, 1); data[2, 1, Direction.West] = new RectGridCell(1, 1); //data[2, 2, Direction.West] = new RectGridCell(1, 1); data[2, 3, Direction.West] = new RectGridCell(1, 1); data[2, 4, Direction.West] = new RectGridCell(1, 1); return(data); }
public static GridLattice <IRectGrid> CornersLattice() { GridLattice <IRectGrid> data = new GridLattice <IRectGrid>(10); InitGridLattice(data); data[1, 1, Direction.West] = new RectGridCell(1, 1); data[1, 1, Direction.South] = new RectGridCell(1, 1); data[2, 6, Direction.West] = new RectGridCell(1, 1); data[2, 6, Direction.North] = new RectGridCell(1, 1); data[4, 6, Direction.East] = new RectGridCell(1, 1); data[4, 6, Direction.South] = new RectGridCell(1, 1); data[6, 4, Direction.North] = new RectGridCell(1, 1); data[6, 4, Direction.East] = new RectGridCell(1, 1); return(data); }
public static void InitGridLattice(GridLattice <IRectGrid> data) { for (int x = 0; x < data.Width; x++) { for (int y = 0; y < data.Height; y++) { if (x == 0) { data[x, y, Direction.West] = new RectGridCell(0, 1); } if (y == 0) { data[x, y, Direction.South] = new RectGridCell(0, 1); } data[x, y, Direction.North] = new RectGridCell(0, 1); data[x, y, Direction.East] = new RectGridCell(0, 1); data[x, y, Direction.Center] = new RectGridCell(0, 1); } } }
public void LatticeGetBoundsTest() { var result = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice()); Assert.AreEqual(1, result.Count, "Did not get 1 initial rectangles as expected"); var pathfinder = new RectifyPathfinder(result, StandardLatticeParams); var bounds = pathfinder.GetRectBordersFromPoint(new Position(0, 0)); Assert.AreEqual(3, bounds.Item2.xPos, "did not get 3 width as expected"); var altLattice = new GridLattice <IRectGrid>(10); GridLatticeTestData.InitGridLattice(altLattice); altLattice[0, 0, Direction.East] = new RectGridCell(1, 1); result = Rectify.MakeRectangles(altLattice); //cell at 0,0; the rest of the row (1,0 -> 10,0), and the rest of the grid (0,1 -> 10,10) Assert.AreEqual(3, result.Count, "Did not get 3 rectangles as expected"); var altfinder = new RectifyPathfinder(result, StandardLatticeParams); }
public void GridLatticeTest() { //run everything three times, with grids where W > H, H > W, and H == W for (int z = 3; z <= 5; z++) { var width = z; //123(45) var height = 4; //ABCD //left edge == LL //right edge == RR //top edge == NN //bottom edge == SS GridLattice <string> testLattice = new GridLattice <string>(width, height); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { testLattice[j, i] = j + GetHeightCode(i); //Each Cell should contain a string formatted e.g. 2B or 1A } } //Set the West edge for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { if (i == 0) { testLattice[i, j, Direction.West] = "LL" + testLattice[i, j]; //Each Edge should contain a string based on the two cells it borders e.g. LL1A or 1A1B } else { testLattice[i, j, Direction.West] = testLattice[i - 1, j] + testLattice[i, j]; } } } //Set the East edge for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { if (i == width - 1) { testLattice[i, j, Direction.East] = testLattice[i, j] + "RR"; //Each Edge should contain a string based on the two cells it borders e.g. LL1A or 1A1B } else { testLattice[i, j, Direction.East] = testLattice[i, j] + testLattice[i + 1, j]; } } } //Set the North edge for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { if (j == height - 1) { testLattice[i, j, Direction.North] = testLattice[i, j] + "NN"; //Each Edge should contain a string based on the two cells it borders e.g. LL1A or 1A1B } else { testLattice[i, j, Direction.North] = testLattice[i, j] + testLattice[i, j + 1]; } } } //Set the South edge for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { if (j == 0) { testLattice[i, j, Direction.South] = "SS" + testLattice[i, j]; //Each Edge should contain a string based on the two cells it borders e.g. LL1A or 1A1B } else { testLattice[i, j, Direction.South] = testLattice[i, j - 1] + testLattice[i, j]; } } } //All cells & edges set to unique values. //should have 3(width*height) + width + height unique values HashSet <string> uniqueVals = new HashSet <string>(); for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { uniqueVals.Add(testLattice[i, j]); uniqueVals.Add(testLattice[i, j, Direction.North]); uniqueVals.Add(testLattice[i, j, Direction.East]); uniqueVals.Add(testLattice[i, j, Direction.West]); uniqueVals.Add(testLattice[i, j, Direction.South]); } } Assert.AreEqual((3 * width * height + width + height), uniqueVals.Count, "Error setting or getting lattice elements for z = " + z); //for square 1,1, change its neighbors and verify that it's neighbors edges are then what we expect. testLattice[1, 1, Direction.South] = "south"; Assert.AreEqual("south", testLattice[1, 0, Direction.North]); testLattice[1, 1, Direction.North] = "north"; Assert.AreEqual("north", testLattice[1, 2, Direction.South]); testLattice[1, 1, Direction.West] = "west"; Assert.AreEqual("west", testLattice[0, 1, Direction.East]); testLattice[1, 1, Direction.East] = "east"; Assert.AreEqual("east", testLattice[2, 1, Direction.West]); } }