Arun Menon
2 min readMay 22, 2017

--

Excellent write-up. The room generation with this algorithm is quick and the lines of codes is surprisingly short. I am currently enrolled at Free Code Camp and am now at this project stage.

I don’t have too much experience in the intense array/object manipulation that games usually require. My early efforts at the initial board/rooms generation was getting unwieldy (and with the odd unexpected bugs) so i decided to look around and research a bit. Most of the write-ups, as you noted as well, are not exactly geared for novices. I found your article as well as an equally good write-up (the pseudo-code) at http://www.roguebasin.com/index.php?title=Dungeon-Building_Algorithm and an interesting implementation at http://codepen.io/honmanyau/pen/MpNoXW

My early efforts had something along the lines of the following (very, very rough)pseudo-code(the actual lines of code is rather high):

//setup global vars..to be wrapped as objects
var maxTries = 1000;
var initialRandomNumOfDoors = _.random([0,3])
var tries = 0;
var direction = getRandomDirection();
var x = getInitalX;
var y = getInitialY;
….more global vars

while (numofRoomsCreated<totalRoomsRequired || tries < maxTries):

var width = getWidth();
var height = getHeight();

createRoom(x,y,width,height,direction){
if(checkForEmptyArea(x,y,width,height,direction)){
createCorridor()
createRoomFloorAndWalls()//an object with info like walls/width/height/x/y
createRandomDoors() //on the walls based on direction
setxandy() //for next iteration (from doors)
setDirection!=currentDirection
numOfRoomCreated++;
room.push(createdRoom)//push the created room to rooms[]
tries++
}
else {

var diffDirection = new direction;
createRoom(x,y,width,height,diffDirection){
}
}
}

But there were bugs. I changed my approach/logic but really wasn’t happy with the outcome. I finally decide to use an existing algorithm for now (with an intent to return later) just for the initial room generation operation.

I wonder if its ok if i use your approach in my implementation. I like the versatility and compactness of the algorithm. I seem to be improving my own grasp of the intricacies of the problems and solutions — and javascript — while i attempt to use it along my thought flow.

Again, thanks for the great write-up. I did read the follow-up posts and they are equally good as well. I would be using a different approach - using MobX for now and perhaps later refactor to a Redux store(am new to both. MobX, thus far in my early usage, fits in nicely and is very, very quick and performant. Have some vanilla Flux knowledge and perhaps that might help with the Redux refactor later).

--

--