small medium large xlarge

Generic-user-small
11 Jan 2016, 01:56
Diego Villamil (5 posts)

Dear Mazers, I wrote another post for printing the grid with unicode box characters. My second attempt to achieve this is to extend the grid with a one cell frame of “phantom” cells around the grid. With this frame of phantom cells I’d only need to run the loop once and all the edge printing will be taken care of.
The question that I have is how to implement the assignment method []= in my code.

I upload it in Github, so anybody that’s interested in it can take a look.

I’m using ruby -I. _binary.rb to run the mazes with the unicode to_s. The original is now to_s0 and my other attempt is to_s1. The error happens in line 170 of grid.rb.

Thanks a bunch.

Generic-user-small
11 Jan 2016, 15:04
Jamis Buck (30 posts)

To answer your question about how to implement the array assignment operator:

def []=(row, column, value)
  # assign value to row, column here
end

However, you may find that your overall strategy will prove harder than you think. The grid sets up the neighbors of all its cells, so adding cells (or reassigning positions) will require those neighbor connections to be carefully updated.

Good luck!

Generic-user-small
11 Jan 2016, 21:29
Diego Villamil (5 posts)

I see the problem. Mmph… I’ve thought of a few things, but as you say it’s a tough road; they all seem more complicated than what I already have.

I’ll come back if I come up with something.

Generic-user-small
13 Jan 2016, 12:58
Diego Villamil (5 posts)

Following the aux_ cells, I was able to wrap it up in one loop with no need of code-after-the-loop. This made a fake extension, but I didn’t use the method [ ]=. It’s actually more similar to my first post.

In the Github link above, there’s to_s and to_s0 methods corresponding to this box unicode, and the original from the book.

You must be logged in to comment