28 #ifndef ELEMENT_SHARK_H
29 #define ELEMENT_SHARK_H
46 typedef typename CC::ATOM_TYPE T;
47 typedef typename CC::PARAM_CONFIG P;
49 R = P::EVENT_WINDOW_RADIUS,
50 BITS = P::BITS_PER_ATOM,
55 MAX_SHARK_ENERGY = (1<<SHARK_ENERGY_LEN) - 1,
57 INITIAL_DEFAULT_BIRTH_AGE = 15,
58 DEFAULT_ENERGY_PER_FISH = 8
73 u32 GetSharkEnergy(
const T& us)
const
78 void SetSharkEnergy(T& us,
const u32 age)
const
84 static const u32 TYPE()
91 m_sharkBirthAge(
this,
"age",
"Birth Age",
92 "Number of events for a shark to mature",
93 1, INITIAL_DEFAULT_BIRTH_AGE, 100),
94 m_sharkEnergyPerFish(
this,
"energy",
"Energy Per Fish",
95 "Life events gained per fish eaten",
96 1, DEFAULT_ENERGY_PER_FISH, 50)
104 static T defaultAtom(TYPE(),0,0,0);
106 this->SetBirthAge(defaultAtom, m_sharkBirthAge.GetValue());
107 this->SetCurrentAge(defaultAtom, 0);
108 this->SetSharkEnergy(defaultAtom, m_sharkEnergyPerFish.GetValue());
126 const T& me,
const SPoint& offset)
const
142 u32 energy = GetSharkEnergy(
self);
143 bool starved = energy == 0;
152 this->SetSharkEnergy(
self, energy);
154 u32 age = this->GetCurrentAge(
self);
156 bool reproable = age >= (u32) m_sharkBirthAge.GetValue();
160 this->SetCurrentAge(
self, 1 + age);
169 energy = MIN((u32) MAX_SHARK_ENERGY, energy + m_sharkEnergyPerFish.GetValue());
176 this->SetSharkEnergy(
self, energy);
180 this->SetCurrentAge(
self,0);
189 else if (emptyCount > 0)
194 this->SetSharkEnergy(
self, energy);
195 this->SetCurrentAge(
self,0);
212 Element_Shark<CC> Element_Shark<CC>::THE_INSTANCE;
static void Write(BV &bv, u32 val)
Definition: BitField.h:84
u32 GetType() const
Definition: Element.h:290
Definition: Element_Empty.h:41
static u32 Read(const BV &bv)
Definition: BitField.h:73
virtual void Behavior(EventWindow< CC > &window) const
Definition: Element_Shark.h:131
void SetCenterAtom(const T &atom)
Definition: EventWindow.h:220
bool Equals(const Point< T > &rhs) const
Definition: Point.tcc:205
virtual u32 PercentMovable(const T &you, const T &me, const SPoint &offset) const
Definition: Element_Shark.h:125
void SetName(const char *name)
Definition: Element.h:209
void SetAtomicSymbol(const char *symbol)
Definition: Element.h:193
void FindRandomAtoms(const u32 radius, const u32 count,...) const
Definition: WindowScanner.tcc:319
Definition: Parameter.h:593
const T & GetCenterAtom() const
Definition: EventWindow.h:209
Definition: AbstractElement_WaPat.h:39
Definition: Element_Fish.h:42
Definition: ElementTable.h:43
Definition: Element_Shark.h:43
virtual u32 DefaultPhysicsColor() const
Definition: Element_Shark.h:113
const BitVector< P::BITS_PER_ATOM > & GetBits(const T &atom) const
Definition: Element.h:132
Definition: WindowScanner.h:40
virtual u32 Diffusability(EventWindow< CC > &ew, SPoint nowAt, SPoint maybeAt) const
Definition: Element_Shark.h:120
bool SetRelativeAtom(const SPoint &offset, const T &atom)
Definition: EventWindow.tcc:15
virtual const T & GetDefaultAtom() const
Definition: Element_Shark.h:102