private static List <GridSpot> waveExpansion(GridSpot curr, GridSpot end, List <GridSpot> path, int marker) { if (curr.Coord().Equals(end.Coord())) //Found endpoint { path.Add(curr); //End point return(path); } List <pGridSpot> neighbors = getNeighbors(curr); foreach (pGridSpot neighbor in neighbors) { if (neighbor == null) { } //No neighbor, collapse the branch else { neighbor.mark = marker; copyMap.addTile(neighbor); //Add marked tile to the temp map stack.Add(neighbor); //Add marked tile to the bottom of the stack } } while (stack.Count > 0) { marker += 1; pGridSpot next = stack[0]; stack.Remove(next); if (next.Coord().Equals(end.Coord())) { waveExpansion(next, end, path, marker); //Go one more time return(path); } else { waveExpansion(next, end, path, marker); } } return(path); }
void populateMap() { for (int x = 0; x < columns; x++) { for (int y = 0; y < rows; y++) { GridSpot spot = map.getTile(x, y); Instantiate(spot.initSpot(), spot.Coord(), Quaternion.identity); } } }
bool isEdge(GridSpot spot) { int x = (int)spot.Coord().x; int y = (int)spot.Coord().y; if (x == xLoci && y == yLoci) { return(true); } else if (x == xLoci && y == yLoci + height - 1) { return(true); } else if (x == xLoci + width - 1 && y == yLoci + height - 1) { return(true); } else if (x == xLoci + width - 1 && y == yLoci) { return(true); } else if (x >= xLoci && y == yLoci) { return(true); } else if (x >= xLoci && y == yLoci + height - 1) { return(true); } else if (x == xLoci && y >= yLoci) { return(true); } else if (x == xLoci + width - 1 && y >= yLoci) { return(true); } return(false); }
private static pGridSpot getNeigh(GridSpot curr, Vector3 toLook) { int x = (int)(curr.Coord().x + toLook.x); int y = (int)(curr.Coord().y + toLook.y); if (x < 0 || x >= BoardManager.rows || y < 0 || y >= BoardManager.columns) { return(null); } System.Type tile = copyMap.getTile(x, y).GetType(); if (!(tile == typeof(pGridSpot)) && !(tile == typeof(RoomSpot)) && !(tile == typeof(WallSpot))) { return(new pGridSpot(copyMap.getTile(x, y))); //If this point hasn't been visited } else { return(null); //If this point has been visited } }
public pGridSpot(GridSpot spot) : base(spot.Coord(), spot.initSpot(), spot.Changeable) { mark = -1; //-1 means its unmarked }
public void addTile(GridSpot coord) { map[(int)coord.Coord().x, (int)coord.Coord().y] = coord; }
public GridSpot getTile(GridSpot coord) { return(map[(int)coord.Coord().x, (int)coord.Coord().y]); }