• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cormas / ecec-model / 5823152171

pending completion
5823152171

push

github

olekscode
Fixed the deprecated method call

2 of 2 new or added lines in 1 file covered. (100.0%)

13 of 304 relevant lines covered (4.28%)

0.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.21
/src/ECEC-Model/ECECForager.class.st
1
Class {
2
        #name : #ECECForager,
3
        #superclass : #CMAgent,
4
        #traits : 'TCMLocated',
5
        #classTraits : 'TCMLocated classTrait',
6
        #instVars : [
7
                'energy'
8
        ],
9
        #category : #'ECEC-Model'
10
}
11

12
{ #category : #accessing }
13
ECECForager class >> catabolicRate [
×
14

×
15
        ^ 2
×
16
]
×
17

18
{ #category : #default }
19
ECECForager class >> defaultProbes [
×
20

×
21
        ^ self probes
×
22
]
×
23

24
{ #category : #accessing }
25
ECECForager class >> fertilityThreshold [
×
26

×
27
        ^ 100
×
28
]
×
29

30
{ #category : #accessing }
31
ECECForager class >> harvestRate [
32

33
        self subclassResponsibility
34
]
35

36
{ #category : #biology }
37
ECECForager >> consumeEnergy [
×
38

×
39
        self energy: self energy - self class catabolicRate
×
40
]
×
41

42
{ #category : #biology }
43
ECECForager >> eat [
×
44
        "The forager eats a quatity of biomass of its current location. The quantity depends on the harvestRate: a proportion of biomass (50% or 99% according to forager type)"
×
45
        
×
46
        | quantity |
×
47
        patch ifNil: [ ^ nil ].
×
48
        
×
49
        quantity := self patch biomass * self class harvestRate.
×
50
        
×
51
        self energy: self energy + quantity.
×
52
        self patch biomass: self patch biomass - quantity
×
53
]
×
54

55
{ #category : #accessing }
56
ECECForager >> energy [
×
57

×
58
        ^ energy
×
59
]
×
60

61
{ #category : #accessing }
62
ECECForager >> energy: anObject [
×
63

×
64
        energy := anObject
×
65
]
×
66

67
{ #category : #initialization }
68
ECECForager >> initialize [
3✔
69

3✔
70
        super initialize.
3✔
71
        energy := 50.
3✔
72
]
3✔
73

74
{ #category : #printing }
75
ECECForager >> interestingDetails [
×
76
        "Answer a Collection>of interesting receiver's attributes, from a modeler point of view, to display in a popup for example "
×
77

×
78
        ^ super interestingDetails , { 
×
79
                'Energy: ' -> (self energy asString)
×
80
                }
×
81
]
×
82

83
{ #category : #biology }
84
ECECForager >> move [
×
85
        "The Forager examines its current location and around. From thw patches that are not occupied, it chooses the one containing the most biomass. If the chosen patch has enough biomass to meet the catabolic rate, the Forager moves there. If not, it moves instead to a randomly chosen adjacent free place (not occupied by another Forager)"        
×
86

×
87
        | candidatePatches maxBiomass targetPatch |
×
88
        patch ifNil: [ ^ self ].
×
89
        
×
90
        candidatePatches := self patch neighbourhoodAndSelf select: [ :each |
×
91
                each biomass > self class catabolicRate and: [ each hasNoOccupants ] ].
×
92
        
×
93
        candidatePatches ifEmpty: [
×
94
                self randomWalkConstrainedBy: [ :c | c hasNoOccupants ].
×
95
                ^ self ].
×
96
        
×
97
        maxBiomass := (candidatePatches collect: [ :each | each biomass ]) max.
×
98
        targetPatch := candidatePatches detect: [ :each | each biomass = maxBiomass ].
×
99
        
×
100
        self moveTo: targetPatch.
×
101
]
×
102

103
{ #category : #pov }
104
ECECForager >> pov [
105

106
        self subclassResponsibility
107
]
108

109
{ #category : #biology }
110
ECECForager >> reproduce [
×
111
        "The forager reproduces asexually, creating an offspring with the same heritable traits as itself (e.g., feeding strategy). At the same time the parent's energy is reduced by the offspring's initial energy (50).  Newborn offspring occupies the nearest free place to its parent. "
×
112
        
×
113
        | newForager freePatch |
×
114
        patch ifNil: [ ^ self ].
×
115
        
×
116
        freePatch := self nearestEmptyLocationWithinRadius: 1.
×
117
        freePatch ifNil: [ ^ self ].
×
118
        
×
119
        newForager := self newEntity: self class.
×
120
        self energy: self energy - newForager energy.
×
121
        
×
122
        newForager moveTo: freePatch
×
123
]
×
124

125
{ #category : #povSize }
126
ECECForager >> sizeOfPOV [
×
127

×
128
        ^ 2 + (self energy / self class fertilityThreshold * 20)
×
129
]
×
130

131
{ #category : #stepping }
132
ECECForager >> step [
×
133

×
134
        self
×
135
                consumeEnergy;
×
136
                move;
×
137
                eat.
×
138
                
×
139
        self energy >= self class fertilityThreshold
×
140
                ifTrue: [ self reproduce ].
×
141
                
×
142
        self energy <= 0
×
143
                ifTrue: [ self die ]
×
144
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc