[erlang-questions] write the ant simulation in Erlang?
Fri Oct 10 04:54:46 CEST 2008
Richard O'Keefe wrote:
> On 10 Oct 2008, at 1:51 pm, jm wrote:
>> This was my first reaction when seeing a description of the problem.
Read the first sentence. I was not stating it was a good idea merely
sketching out an idea between doing some work. There are obviously some
problems with the approach taken, but I think using a process per square
(cell) or a subset of squares (patch) is a more natural approach for
erlang. As this approach mantains the atomic nature of the squares and
scales more easily as the cores/processes grow.
> First, I was originally talking about dividing the world
> up into *patches*, not *cells*. In an 80x80 world,
> patches might be 10x10, which is only 64 patches.
> Second, why on earth would you *name* the patch processes?
Just a simple way to find the correct process in a first cut and easier
to see what is going on. You could also prime each ant with knowledge of
which processes represent each square(s) or each patch/cell could
contain this knowledge which is what I think your thinking.
> startup() ->
> create an 80 x 80 array of processes
> all running cell/0 using spawn_link
> set up all the neighbour links
> send each cell a !go message
> Moving is a little tricky because we need to change the
> state of two cells (if doing cells) or possibly two
> patches (if doing patches).
Can you live with an ant occupying two squares at once? Then enter the
new location first before leaving the old location.
More information about the erlang-questions