private int GetSurroundingWallCount(int row, int col, IXShape shape) { int wallCount = 0; for (int neighbourX = row - 1; neighbourX <= row + 1; neighbourX++) { for (int neighbourY = col - 1; neighbourY <= col + 1; neighbourY++) { if (shape.isCellValid(neighbourX, neighbourY)) { if (neighbourX != row || neighbourY != col) { if (shape.hasCellValue(neighbourX, neighbourY, XTile.WALL)) { wallCount++; } } } else { wallCount++; } } } return(wallCount); }
public static void printForTest(CaveBoard board) { ZeroOneTwoFillerCavePlotter plotter = new ZeroOneTwoFillerCavePlotter(); plotter.applyOn(board); print(plotter.result(), true); String currName = null; String prevName = null; for (int i = 0; i < board.all().Length; i++) { IXShape current = board.all()[i]; prevName = currName; if (i % 2 == 0) { int roomIndex = i / 2 + 1; currName = "room" + (roomIndex); } else { currName = "corr" + i + "" + (i + 1); } current.accept(new PrepareForTestShapeVisitor(currName)); if (prevName != null) { System.Console.WriteLine(currName + ".setIncoming(" + prevName + ");"); System.Console.WriteLine(prevName + ".setOutcoming(" + currName + ");"); } } }
private void RandomFillMap(int row, int col, IXShape shape) { int value = (intInRangePicker.drawBetween(0, 100) < randomFillPercent) ? XTile.FLOOR : XTile.WALL; //int value = (intInRangePicker.Next(0, 100) < randomFillPercent) ? XTile.FLOOR : XTile.WALL; shape.setCellValue(row, col, value); }
public void applyOn(IXShape shape) { shape.forEachCell(RandomFillMap); for (int i = 0; i < smoothSteps; i++) { SmoothMap(shape); } }
private void printSetMethod(IXShape aShape) { aShape.forEachCell2((row, col, value) => { if (value == 1) { String result = _varName + ".setCellValue(" + row + ", " + col + ", XTile.FLOOR);"; System.Console.WriteLine(result); } }); }
public void addRoom(IXShape aRoom) { if (_roomsAndCorrs.Count != 0) { IXShape prevCorr = _roomsAndCorrs[_roomsAndCorrs.Count - 1]; prevCorr.setOutcoming(aRoom); aRoom.setIncoming(prevCorr); } _rooms.Add(aRoom); _roomsAndCorrs.Add(aRoom); }
public void addCorridor(IXShape corr) { if (_roomsAndCorrs.Count != 0) { IXShape prevRoom = _roomsAndCorrs[_roomsAndCorrs.Count - 1]; prevRoom.setOutcoming(corr); corr.setIncoming(prevRoom); } _corrs.Add(corr); _roomsAndCorrs.Add(corr); }
public bool collidesWith(IXShape other) { Cell[] cells = _topLeftVertex.cells(bottomRightVertex()); foreach (Cell each in cells) { if (other.containsCell(each)) { return(true); } } return(false); }
public CaveBoard asBoard() { checkConstraints(); Board board = _dunGen.asBoard(); ShapeCellularAutomaton roomAlgo = new ShapeCellularAutomaton(_seed, _cellularFillChance, _cellularSmoothingStep); CustomSeededPickerStrategy shapePicker = new CustomSeededPickerStrategy(_seed); CaveBoard result = new CaveBoard(board.rows(), board.cols()); List <IXShape> onlyRooms = new List <IXShape>(); _logger.info("Rooms: " + board.rooms().Length); foreach (Room each in board.rooms()) { Cell leftVert = each.topLeftVertex(); int rows = each.height(); int cols = each.width(); APolyShape currentRoom; //Select a shape for the Room if (shapePicker.drawBetween(0, 100) < 50) { currentRoom = new RectShape(leftVert, new OIGrid(rows, cols)); } else { currentRoom = new ElliShape(leftVert, new OIGrid(rows, cols)); } _logger.info("Shape type: " + currentRoom.GetType()); roomAlgo.applyOn(currentRoom); _logger.info("Shape regions before clean: " + currentRoom.regionsNumber()); if (!currentRoom.hasRegions()) { _logger.warning("No Region found. Room will be skipped!!!"); continue; } currentRoom.deleteRegionsButTheBiggest(); _logger.info("Shape regions after clean: " + currentRoom.regionsNumber()); onlyRooms.Add(currentRoom); if (onlyRooms.Count > 1) { IXShape previousRoom = onlyRooms[onlyRooms.Count - 2]; int corrIndex = onlyRooms.Count - 2; Corridor corr = board.corridors()[corrIndex]; int corridorSection = corr.isVertical() ? corr.width() : corr.height(); result.addCorridor(CaveCorridorFactory.createCorrShape(previousRoom, currentRoom, corridorSection)); } result.addRoom(currentRoom); } return(result); }
private Cell[] absCellsFacingShape(IXShape aShape) { List <Cell> result = new List <Cell>(); forEachEdgeCellAbs((row, col, value) => { Cell cell = new Cell(row, col); if (aShape.hasAbsCellFacing(cell)) { result.Add(cell); } }); return(result.ToArray()); }
private void SmoothMap(IXShape shape) { shape.forEachCell((row, col, sameShape) => { int neighbourWallTiles = GetSurroundingWallCount(row, col, shape); if (neighbourWallTiles > 4) { shape.setCellValue(row, col, XTile.WALL); } else if (neighbourWallTiles < 4) { shape.setCellValue(row, col, XTile.FLOOR); } }); }
public virtual void visit(IXShape aShape) { if (aShape is APolyShape) { visit(aShape as APolyShape); } else if (aShape is FreeShape) { visit(aShape as FreeShape); } else { throw new NotImplementedException("Missing case for: " + aShape.GetType()); } }
public static FreeShape createCorrShape(IXShape roomA, IXShape roomB, int corrWidth) { CellPair pair = roomA.shortestCellPair(roomB); List <Cell> line = GetLine(pair.cell1, pair.cell2); FreeShape corrAtoB = new FreeShape(); foreach (Cell each in line) { List <Cell> vCells = DrawCircle(each, corrWidth); //To avoid cell overlapping between rooms with corridor foreach (Cell vEach in vCells) { if (!roomA.hasCellAbsValue(vEach, XTile.FLOOR) && !roomB.hasCellAbsValue(vEach, XTile.FLOOR)) { corrAtoB.add(vEach); } } } return(corrAtoB); }
public static void printForTest(int seed, params APolyShape[] rooms) { ShapeCellularAutomaton auto = new ShapeCellularAutomaton(seed, 75, 4); CaveBoard board = new CaveBoard(50, 50); for (int i = 0; i < rooms.Length; i++) { APolyShape currRoom = rooms[i]; auto.applyOn(currRoom); currRoom.deleteRegionsButTheBiggest(); if (i > 0) { IXShape prevRoom = rooms[i - 1]; IXShape corr = CaveCorridorFactory.createCorrShape(prevRoom, currRoom, 2); board.addCorridor(corr); } board.addRoom(currRoom); } printForTest(board); }
public CellPair shortestCellPair(IXShape aShape) { List <Cell> myEdge = edge(); List <Cell> yourEdge = aShape.edge(); double shortestPath = 0; Cell cell1Sel = null; Cell cell2Sel = null; bool firstTime = true; foreach (Cell myCell in myEdge) { Cell myCellAbs = myCell.plus(topLeftVertex()); foreach (Cell yourCell in yourEdge) { Cell yourCellAbs = yourCell.plus(aShape.topLeftVertex()); double magn = myCellAbs.magnetude(yourCellAbs); if (firstTime) { shortestPath = magn; firstTime = false; cell1Sel = myCellAbs; cell2Sel = yourCellAbs; } else if (magn < shortestPath) { shortestPath = magn; cell1Sel = myCellAbs; cell2Sel = yourCellAbs; } } } if (firstTime) { return(null); } return(new CellPair(cell1Sel, cell2Sel)); }
public override void _visit(IXShape shape) { shape.forEachCellAbs((x, y, value) => { this.grid.setCellValue(x, y, value); }); }
public virtual void _visit(IXShape aShape) { }
public CellPair shortestCellPair(IXShape other) { throw new NotImplementedException(); }
public void setOutcoming(IXShape outcoming) { _outcoming = outcoming; }
public void setIncoming(IXShape incoming) { _incoming = incoming; }
public bool collidesWith(IXShape each) { throw new NotImplementedException(); }