[erlang-questions] write the ant simulation in Erlang?

Robert Virding <>
Thu Oct 9 23:47:50 CEST 2008


I haven't really checked the Clojure code that closely but it seems like a
reasonable problem.

Do you know if it "turn based" or do the all the ants just move after their
own clocks in a parallel way?

A first approximation would be to have one process per ant and one for the
world. The only problem would be handling atomic
look-at-the-immediate-world-around-me-and-make-a-move.

The really difficult bit is displaying it. :-)

Robert

2008/10/9 Brian Zhou <>

> Let me try to reverse engineer some kind of spec:
>
> * On a world of 80x80 cells, there are 49 ants, and 35 scattered cells
> with food.
> * Initially the ants are in their home, a square from (20, 20) to (26,
> 26), facing random directions.
>
> * An ant can move ahead, turn 45 degree left, or 45 degree right, every
> 40ms.
> * Ant should not move ahead if there is another ant in the ahead cell.
> * Whenever ant make a move, it leaves a pheromone trail by increment
> pheromone amount by 1.0 in the previous cell.
>
> * For an ant without food,
> ** If ahead is not home, and there is food ahead, move ahead, take
> food and turn around;
> ** Among cells that are ahead, ahead-left (45 degree), ahead-right (45
> degree), turn/move to the one with the most (if (contain-food?) 1 0) +
> pheromone score, if all equal, turn/move randomly;
>
> * For an ant with food,
> ** If ahead is home, move ahead, drop food and turn around;
> ** Among cells that are ahead, ahead-left (45 degree), ahead-right (45
> degree), turn/move to the one with the most (if (at-home?) 1 0) +
> pheromone score, if all equal, turn/move randomly;
>
> * Every 1 second, the pheromone in all cells evaporate to 99% of the
> previous amount;
>
> * If a graphical animation is provided, the animation is refreshed every
> 100ms.
>
> * Hard-coded numbers are used above to make description easier. They
> are actually adjustable.
>
> ;dimensions of square world
> (def dim 80)
> ;number of ants = nants-sqrt^2
> (def nants-sqrt 7)
> ;number of places with food
> (def food-places 35)
> ;range of amount of food at a place
> (def food-range 100)
> ;evaporation rate
> (def evap-rate 0.99)
>
> (def animation-sleep-ms 100)
> (def ant-sleep-ms 40)
> (def evap-sleep-ms 1000)
>
> Anyone feel free to correct me if my understanding is not right.
>
> -Brian
>
> On Wed, Oct 8, 2008 at 7:46 PM, Richard O'Keefe <> wrote:
> > Bearing in mind that it really isn't practical
> > for someone in NZ to watch videos over the international net,
> > can you tell me what the ant simulation problem is?
> >
> >
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081009/541e0e04/attachment.html>


More information about the erlang-questions mailing list