I've been using MASON for a while - love it, thanks so much for what you're
doing. I've hit a bit of a snag with Bag, and I could use some help. 

I have agents playing a game, and I used getNeighborsMaxDistance to find
possible players. Each agent has a boolean variable played - only agents
whose played = false should be available as potential partners. 
For debugging, I created a situation with 3 agents occupying a single spot.
First, two of them should play, and then the next one should find no one to
play with. However, that last one kept returning with a partner who had
already played. Here is the method:

public  Bag findNotPlayed(Bag neighbors){
for(int k = 0; k < neighbors.numObjs; k++){
   Agent a = (Agent)neighbors.get(k);
   if(a.equals(this) || a == this){
int num = neighbors.numObjs;
for(int i=0; i < num; i++){
   Agent a = (Agent)neighbors.get(i);
return neighbors;

In the second for loop, when I used i < neighbors.numObj, the method removed
only one of the two agents who had played. When I substituted the local
variable num, I got a IndexOutOfBounds exception. 
What I really want is to make sure that the second for-loop is going through
every object in the Bag, and removing ALL the relevant objects. I've tried
both remove() and removeNondestructively - it doesn't seem to make a

Any ideas? Your help is most appreciated.