public void applyOn(CaveBoard board) { _grid = new OIGrid(board.rows(), board.cols()); OIGrid populated = new OIGrid(board.rows(), board.cols()); foreach (IXShape eachShape in board.rooms()) { eachShape.forEachCellAbs((row, col, value) => { populated.setCellValue(row, col, value); }); } //Cosi i corridoi si sovrappongono alle celle 0 delle room. foreach (IXShape eachShape in board.corridors()) { eachShape.forEachCellAbs((row, col, value) => { populated.setCellValue(row, col, value); }); } OIGrid inverted = populated.invert(); inverted.forEach2((row, col, value) => { if (value == 1 && inverted.existsCellNeighborValue(row, col, 0)) { _grid.setCellValue(row, col, 1); } else { _grid.setCellValue(row, col, 0); } }); }
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 + ");"); } } }
public void plotting_boardWithOneRectShape() { CaveBoard board = new CaveBoard(6, 6); IXShape room = new RectShape(new Cell(2, 2), new OIGrid(2, 2)); room.setCellValue(0, 0, XTile.FLOOR); room.setCellValue(0, 1, XTile.FLOOR); room.setCellValue(1, 0, XTile.FLOOR); room.setCellValue(1, 1, XTile.FLOOR); board.addRoom(room); int[,] expected = new int[6, 6] { { 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0 }, { 0, 1, 0, 0, 1, 0 }, { 0, 1, 0, 0, 1, 0 }, { 0, 0, 1, 1, 0, 0 }, { 0, 0, 0, 0, 0, 0 } }; ZeroOneCavePlotter plotter = new ZeroOneCavePlotter(); plotter.applyOn(board); Assert.IsTrue(XTestUtils.areEquals(expected, plotter.result())); }
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); }
public void applyOn(CaveBoard board) { _grid = new OIGrid(board.rows(), board.cols()); foreach (IXShape eachShape in board.rooms()) { eachShape.forEachCellAbs((row, col, value) => { _grid.setCellValue(row, col, value); }); } foreach (IXShape eachShape in board.corridors()) { eachShape.forEachCellAbs((row, col, value) => { _grid.setCellValue(row, col, value); }); } }
public void linkingRoomAndCorridor_case1() { CaveBoard board = new CaveBoard(40, 40); IXShape room1 = new RectShape(new Cell(0, 0), new OIGrid(5, 5)); IXShape room2 = new RectShape(new Cell(0, 0), new OIGrid(5, 5)); IXShape corr12 = new FreeShape(); board.addRoom(room1); board.addCorridor(corr12); board.addRoom(room2); Assert.IsNull(room1.getIncoming()); Assert.AreEqual(room1.getOutcoming(), corr12); Assert.AreEqual(corr12.getIncoming(), room1); Assert.AreEqual(corr12.getOutcoming(), room2); Assert.AreEqual(room2.getIncoming(), corr12); Assert.IsNull(room2.getOutcoming()); }
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 void forestgen_allSequence() { CaveGenerator gen = new CaveGenerator(); gen.setMapSize(40, 40); gen.setRoomsNumberRange(3, 3); gen.setRoomSizeRange(12, 15); gen.setCorridorLengthRange(5, 7); gen.setCorridorWidthRange(1, 3); gen.setSeed(123456); gen.setCellularFillChance(80); gen.setCellularSmoothingSteps(5); gen.setMapMargin(2); gen.setPlotter(new Forest012Plotter()); CaveBoard board = gen.asBoard(); Assert.AreEqual(5, board.all().Length); Assert.AreEqual("RectShape", board.all()[0].GetType().ToString()); Assert.AreEqual("FreeShape", board.all()[1].GetType().ToString()); Assert.AreEqual("RectShape", board.all()[2].GetType().ToString()); Assert.AreEqual("FreeShape", board.all()[3].GetType().ToString()); Assert.AreEqual("ElliShape", board.all()[4].GetType().ToString()); }
public void applyOn(CaveBoard board) { _grid = new OIGrid(board.rows(), board.cols()); OIGrid populated = new OIGrid(board.rows(), board.cols()); foreach (IXShape eachShape in board.rooms()) { eachShape.forEachCellAbs((row, col, value) => { populated.setCellValue(row, col, value); }); } //Cosi i corridoi si sovrappongono alle celle 0 delle room. foreach (IXShape eachShape in board.corridors()) { eachShape.forEachCellAbs((row, col, value) => { populated.setCellValue(row, col, value); }); } //1 DENTRO //0 FUORI OIGrid inverted = populated.invert(); //0 DENTRO //1 FUORI inverted.forEach2((row, col, value) => { if (value == 1 && inverted.existsCellNeighborValue(row, col, 0)) { _grid.setCellValue(row, col, 3); } else { _grid.setCellValue(row, col, 1); } }); //_grid //3 MURO //1 FUORI //1 DENTRO populated.forEach2((row, col, value) => { if (value == 1 && _grid.hasCellValue(row, col, 1)) { _grid.setCellValue(row, col, 0); //DENTRO } else if (value == 0 && _grid.hasCellValue(row, col, 3)) { _grid.setCellValue(row, col, 1); //MURO } else { _grid.setCellValue(row, col, 2); //FUORI } }); int edgeSize = _treeTickness; for (int i = 1; i < edgeSize; i++) { OIGrid cloned = _grid.clone(); cloned.forEach2((row, col, value) => { if (value == 2 && cloned.existsCellNeighborValue(row, col, 1)) { _grid.setCellValue(row, col, 1); //MURO } }); } }