[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Class
From: |
jalex |
Subject: |
Re: Class |
Date: |
17 Apr 2000 08:02:01 -0700 |
User-agent: |
Gnus/5.0803 (Gnus v5.8.3) Emacs/20.3 |
David Aliaga <address@hidden> writes:
> Hello.
> I would like to ask if it is possible in Swarm to do
> the following:
>
> if([capture isKindOf: [A_Prey Class]])
> { ........
> }
Swarm is built upon Objective C, so anything you can do in Objective C
you can do in Swarm. In particular, the isKindOf method works in just
the manner described (except the method name is "class" and not
"Class"). Here's how I use it in one of my models:
- (void) updatePopulationCount
{
int x,y;
int maxX = [data_source getSizeX];
int maxY = [data_source getSizeY];
[self resetPopulationCount];
for (x=0; x < maxX; x++) {
for (y=0; y < maxY; y++) {
// Count the number of each kind of agent we have
id agent = [data_source getObjectAtX: x Y: y];
if ( [agent isKindOf: [MimicBestNeighborAgent class]] )
class_count[MIMIC_BEST_NEIGHBOR]++;
else if ( [agent isKindOf: [MimicBestAverageStrategyAgent class]] )
class_count[MIMIC_BEST_AVERAGE_STRATEGY]++;
else if ( [agent isKindOf: [MimicWithProbAgent class]] )
class_count[MIMIC_WITH_PROB_PROP_TO_SUCCESS]++;
else if ( [agent isKindOf: [BestResponseAgent class]] )
class_count[BEST_RESPONSE_STRATEGY]++;
}
}
// Irrelevant stuff deleted
}
Cheers,
Jason
--
Jason Alexander
Logic & Philosophy of Science email: address@hidden
School of Social Sciences department: http://hypatia.ss.uci.edu/lps
University of California, Irvine phone: (949) 824-1520
==================================
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.
- Class, David Aliaga, 2000/04/17