small medium large xlarge

16 Feb 2015, 09:06
Wari Wahab (6 posts)

Hi there, I’m actually trying out to see if I can just use Go as a replacement for the Ruby code, which I can find it challenging, the fact that the types are not declared, and I have to piece that in myself, but I do find myself confused at the Btree portion of chapter 2 (yes, I’m just slowly reading).

In the code of binary_tree.rb there is this line:

neighbors « cell.north if cell.north —

This does cause my maze to look bad. I have to use south as the neighbor to get a correct looking maze, as done in my btree implementation

In my mind, it would make sense, as I thought of 0,0 to be the top, left corner of the grid.

I have not run the ruby code yet, and I’m just wondering why the code in the book is done the way it is.


16 Feb 2015, 21:22
Jamis Buck (30 posts)

It should work either way, north or south, as long as you are consistently choosing from the same set of directions. If you always choose between north and east at each cell, you’ll get a north-easterly textured maze with solid corridors on the north and east sides. Choosing between south and east would give you a south-easterly textured maze, with corridors on the south and east instead.

I’m curious what you mean when you say that choosing north causes the maze to “look bad”. I wonder if it might suggest that the code which is configuring the adjacent cells (Grid#configure_cells in the Ruby implementation) is misconfiguring the northern neighbor somehow? If you don’t mind sharing your Grid implementation, I could take a look. It might also help to see what one of the resulting mazes looks like.

17 Feb 2015, 01:35
Wari Wahab (6 posts)

Yup, looks like I made a booboo here. Fixed in this particular commit

Basically it’s the Cell.Link() portion of the code, when bidirectional links are concern, I’ve swapped from cell, to the self, etc. It made southwise btree algo somewhat ok, but never seem to be able to make north wise corridors.

When I say it looked bad, just think of it as a maze with no north/south corridors :)

Thanks for pointing me in the right direction.

17 Feb 2015, 01:58
Jamis Buck (30 posts)

Wonderful! I’m glad you figured it out. I’ve spent more time than I care to admit troubleshooting issues like this in my own maze code. :)

You must be logged in to comment