[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Filling cells in grid by type

Joop Van den tillaart

8/22/2007 3:24:00 PM

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

Attachments:
http://www.ruby-...attachment/149/testgri...

--
Posted via http://www.ruby-....

2 Answers

benjohn

8/22/2007 6:35:00 PM

0

> 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...

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: http://rubyquiz.com/q..., 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


>
> Greets
>
> Attachments:
> http://www.ruby-...attachment/149/testgri...
>
> --
> Posted via http://www.ruby-....
>
>



Joop Van den tillaart

8/22/2007 7:04:00 PM

0

Please can no one help me?

I could really use it...thanks!
--
Posted via http://www.ruby-....