Filling cells in grid by type

Hi all…

I have a question i wanted to ask. I have a ruby file which represents a
piece of land which has to be developed by different types of land-uses.
For the moment the program does make a grid like structure of 21x21
cells. I then make all the cells of type 0 (no type of land-use). Then i
make 2 columns and 1 row type 3, which represents a road type land-use.
I also calculate the shortest distances for each cell to these roads.

I now need to fill the other cells (which are type 0) for one part with
type 1 (housing) and the other remaining cells with type 2
(green/parks). How do i do this the easiest way?

I have attached the file so you can check it out to get a better idea of
the whole…

Please help me as I don’t have too much experience with programming, let
alone ruby programming…

Greets

Please can no one help me?

I could really use it…thanks!

type 1 (housing) and the other remaining cells with type 2
(green/parks). How do i do this the easiest way?

I have attached the file so you can check it out to get a better idea of
the whole…

Please help me as I don’t have too much experience with programming, let
alone ruby programming…

Hi. I’ve had a very quick look through your code.

When I’ve done things like this in the past, I’ve found it’s easier to
use a map for the storage of the grid. You can index that with (x,y)
tupples, which is very convenient. Also, you’ve got handling in there
for indexing misses, and handling for the default background. A map will
probably let you eliminate a lot of this, and simply default to a
background cell type.

I’m not quite getting what you’re trying to achieve though :slight_smile: … I
pressume that you want to automatically assign roles to land cells? If
you didn’t, then you could simply parse in the land configuration from
an ASCII text file. Even if you do want to do automatic assignement,
setting up from a text file might be a nice way to go? It would let you
get rid of your column and row classes. In fact, I would get rid of
these and implement them as “painting” like methods in the land storage
class.

Erm - I used some slightly similar code to this for a ruby quiz. You can
find it at: http://rubyquiz.com/quiz80.html, for what it’s worth. Also,
I’m not sure if you are, but you may like to considder test driven
development for your project :slight_smile:

HTH
Benjohn

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs