swarm-support
[Top][All Lists]
Advanced

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

Re: Help request from a SWARM newbie


From: Marshall James
Subject: Re: Help request from a SWARM newbie
Date: Wed, 27 Jan 1999 16:39:29 +0100

Hi,
is myList a List or a ListIndex? If it's a ListIndex then the line
[myList remove: enemyBug];
would cause a status access violation... instead you'd need to have the line
[[myList getCollection] remove: enemyBug];
James

A 15:52 27/01/99 +0100, vous avez écrit :
>>>>
I'd like to modify simpleSwarmBug2 in this way:

Each Bug has a certain amount of strenght (a float value initially set to 0) that increases of ,let's say, 0.1 every time it eats.
Then, when a Bug wants to move to anather location (-step) that is already occupied by another Bug, it checks if its own strenght is higher than that of its "enemy" :if it's so,
it destroys it (in my mind,that would mean to make the bugList remove the defeated Bug), otherwise goes on.
Here are the parts of source I've modified:
In "Bug.h":

added inst.variables id bugEnemy and float strenght;
added inst.var id myList; (the List whose the bug is part)
added method -getStrenght (returns Bug's strenght)
added method -setList:(id) aList (sent by bugList as a message to set itself
as the bug list)

In "Bug.m",I added the following lines to the -step method:
.....
//Check that no other bug is at the new site

if ((enemy=[world getObjectAtX: newX Y: newY])==nil)
{

[world putObject:nil atX:xPos Y:yPos];
[world putObject:self atX:newX Y: newY];
xPos=newX;
yPos=newY;

}
else if (strenght >= [enemyBug getStrenght]) //space is not free and

//you're stronger
{
[myList remove:enemyBug];
}


if ([foodSpace getValueAtX: xPos Y: yPos]==1)
{
[foodSpace putValue:0 AtX: xPos Y: yPos];
strenght+=0.1;
} .........

In "ModelSwarm.m" I added the following bold line:
.....
aBug = [Bug createBegin: self];
[aBug setWorld: world Food: food];
[aBug setList:bugList];
aBug = [aBug createEnd];
.......

The rest of code is left unchanged.
Because it's only three days since I begun to study SWARM,I couldn't pretend my varation would have worked,infact the runtime system complains:Exception:STATUS_ACCES_VIOLATION
What was my error?
Finally a question on leaving unspecified the return value of a method (making it to return the default type id) even when it hasn't to return any value:it's a matter of style or is there something behind that?

Thank you in advance for your advice.
_______________________________________________________________
Fabio Mascelloni.
Dept. of Computer Science - University of Pisa,Italy
e-mail: address@hidden
<<<<



--

James Marshall - Research Assistant - COTCOS Project
Institut de Recherche en Informatique de Toulouse
WWW: http://www.mk.dmu.ac.uk/~jmarshall
================================= 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]