# Filling cells in grid by type

**URL:** <https://www.ruby-forum.com/t/filling-cells-in-grid-by-type/112729>\
**Category:** Ruby\
**Created:** [August 22, 2007, 5:23pm UTC](https://www.ruby-forum.com/t/filling-cells-in-grid-by-type/112729 "2007-08-22T17:23:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tillaart36](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@tillaart36](https://www.ruby-forum.com/u/tillaart36)\
**Post date:** [August 22, 2007, 5:23pm UTC](https://www.ruby-forum.com/t/filling-cells-in-grid-by-type/112729/1 "2007-08-22T17:23:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tillaart36](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@tillaart36](https://www.ruby-forum.com/u/tillaart36)\
**Post date:** [August 22, 2007, 7:11pm UTC](https://www.ruby-forum.com/t/filling-cells-in-grid-by-type/112729/2 "2007-08-22T19:11:38Z")

</div>

Please can no one help me?

I could really use it…thanks!

---

<div class="post-metadata">

**Author:** ![tillaart36](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@tillaart36](https://www.ruby-forum.com/u/tillaart36)\
**Post date:** [August 22, 2007, 8:38pm UTC](https://www.ruby-forum.com/t/filling-cells-in-grid-by-type/112729/3 "2007-08-22T20:38:05Z")

</div>

> 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 🙂 … 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: [Ruby Quiz - Dungeon Generation (#80)](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 🙂

HTH  
Benjohn
