swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing arguments in a list


From: Ken Cline
Subject: Re: Passing arguments in a list
Date: Wed, 16 Jul 1997 10:41:59 -0400 (EDT)

Vinicius,

First, I'm not sure why your message is dated 10 May; did
you really send it 2 monthes ago?  I'll presume that that
just a mistake.

It looks to me as if you are trying to access a list member
at "Start".  "Start" doesn't point to a valid member of a
list, but instead is a special pointer location.  (This is
also true for "End".)

So, in your "step" method, you might try:

   -step {
      // look for a place to move
      index = [moves begin: [self getZone]];
      [index setLoc: Start];

-->   [index next];
      for (inci=0; inci < 8; inci++) {
         newNeigh = (neighbor_t) [index get]; 
         // if we found an empty one, exit the loop
         if ([self getAgentAtNeighbor: newNeigh] == nil) {
            gotOne = 1;
            break;
         }
         else {
            [index next];
         }
      }
   }

Let me know if this solves the problem.

BTW, you could eliminate the passing of "index" to the
person.  That is, since ModelSwarm doesn't make use of
"index", there's no need to declare it there.  Then the
"setPerson" method becomes:

   -setPerson: (id) n  Move_list: (id) mm {
      name = n;
      moves = mm;
      index = [moves begin: [self getZone]];
      stillhere = 1;   // always here when initialized
      return self;
   }

Also, since index is an instance variable of "Person", the
"step" method shouldn't need to keep reassigning it, unless
of course the "moves" list was reassigned.  That is, in
"step", you should only need "[index setLoc: Start]" and can
eliminate "index = [moves begin: [self getZone]]".

I hope this helps.

Ken.


On Sat, 10 May 1997, Marcus Vinicius Pereira Pessoa wrote:

> Hi,
> 
> I’ve been listening to this list for a long time and now I’m trying to
> make my first simulation. I am modifying the hello-world example and
> trying to create a list of moves that will be a characteristic from each
> person. They will move trough the world during a finite time. In each
> step they will try the next possible move (choosing sequentially from
> the list).
> But I am having a problem with the code. I tried to make the list in the
> ModelSwarm and in the Person itself and none of these tries worked, in
> both of them I always receive an empty list in the Person’s step method.
> 
> ModelSwarm:
> 
>     id moves;
>     id index;
>     neighbor_t temp_move;
> 
> // build the list of moves
>     moves = [List create: [person getZone] ];
>     index = [moves begin: [person getZone]];
>     for (inck = 1; inck < 8; inck++) {
>       temp_move =  [uniformUnsRand getUnsignedWithMin: 1L withMax:
> VNSet];
>       [moves addLast: (void *) &temp_move];
>     }
> // tell the person what her comm numbers are
>     [person setPerson: name Move_list: moves index_pointer: index ];
> 
> Person:
> 
> -step {
> 
>     // look for a place to move
>     index = [moves begin: [self getZone]];
>     [index setLoc: Start];
> for (inci=0; inci < 8; inci++) {
>       newNeigh = (neighbor_t) [index get]; 
> // if we found an empty one, exit the loop
>        if ([self getAgentAtNeighbor: newNeigh] == nil) {
>       gotOne = 1;
>       break;
>       }
>         else {
>       [index next];
>       }
> }
> 
> 
> -setPerson: (id) n  
>   Move_list: (id) mm
>   index_pointer: (id) p {
>     name = n;
>     moves = mm;
>     index = p;
>     stillhere = 1;   // always here when initialized
>   return self;
> }
> 
> I would appreciate if someone could give me some advice.
> 
> Thanks in advance,
> 
> Vinicius.
> 

_________________________________________________________
Ken Cline                             address@hidden
SAIC                                 VOICE (410) 571-0413
Annapolis, MD                          FAX (301) 261-8427


                  =================================   Swarm-Support is for 
discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ================================

reply via email to

[Prev in Thread] Current Thread [Next in Thread]